|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -import { DebugConfiguration, TestItem, TestRunRequest } from 'vscode'; |
| 4 | +import { DebugConfiguration, TestItem, TestRunRequest, Uri } from 'vscode'; |
5 | 5 | import { sendInfo } from 'vscode-extension-telemetry-wrapper'; |
6 | | -import { runTests, testController } from '../controller/testController'; |
| 6 | +import { loadChildren, runTests, testController } from '../controller/testController'; |
7 | 7 | import { loadJavaProjects } from '../controller/utils'; |
8 | 8 | import { showTestItemsInCurrentFile } from '../extension'; |
9 | 9 |
|
@@ -39,10 +39,46 @@ export async function runTestsFromTestExplorer(testItem: TestItem, launchConfigu |
39 | 39 |
|
40 | 40 | export async function refreshExplorer(): Promise<void> { |
41 | 41 | sendInfo('', { name: 'refreshTests' }); |
| 42 | + |
| 43 | + await loadJavaProjects(); |
| 44 | + |
| 45 | + // Force re-resolution of all existing project roots |
| 46 | + const loadPromises: Promise<void>[] = []; |
42 | 47 | testController?.items.forEach((root: TestItem) => { |
43 | | - testController?.items.delete(root.id); |
| 48 | + loadPromises.push(loadChildren(root)); |
44 | 49 | }); |
| 50 | + await Promise.all(loadPromises); |
45 | 51 |
|
46 | | - await loadJavaProjects(); |
| 52 | + await showTestItemsInCurrentFile(); |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Refresh only the project subtree that matches the given classpath-change URI. |
| 57 | + * Falls back to a full (incremental) refresh if no matching project is found. |
| 58 | + */ |
| 59 | +export async function refreshProject(classpathUri: Uri): Promise<void> { |
| 60 | + sendInfo('', { name: 'refreshProject' }); |
| 61 | + const uriString: string = classpathUri.toString(); |
| 62 | + |
| 63 | + // Find the project root with the longest matching URI prefix (most specific match) |
| 64 | + let matchedProject: TestItem | undefined; |
| 65 | + let matchedUriLength: number = 0; |
| 66 | + testController?.items.forEach((root: TestItem) => { |
| 67 | + if (root.uri) { |
| 68 | + const rootUriString: string = root.uri.toString(); |
| 69 | + if (uriString.startsWith(rootUriString) && rootUriString.length > matchedUriLength) { |
| 70 | + matchedProject = root; |
| 71 | + matchedUriLength = rootUriString.length; |
| 72 | + } |
| 73 | + } |
| 74 | + }); |
| 75 | + |
| 76 | + if (matchedProject) { |
| 77 | + // Re-resolve only the matched project's children |
| 78 | + await loadChildren(matchedProject); |
| 79 | + } else { |
| 80 | + // No matching project found – do incremental full refresh |
| 81 | + await loadJavaProjects(); |
| 82 | + } |
47 | 83 | await showTestItemsInCurrentFile(); |
48 | 84 | } |
0 commit comments