From fb8dee16d6a93a2d2b78062693be95caae2db65a Mon Sep 17 00:00:00 2001 From: wenyutang-ms Date: Wed, 3 Jun 2026 16:14:05 +0800 Subject: [PATCH] fix: refresh Test Explorer after first-time enable tests When the Test Explorer has no resolved projects yet and a `classpathUpdated` notification arrives (the exact scenario after "Java: Enable Tests" downloads a JUnit jar onto an unmanaged folder), `refreshProject` would iterate over zero items, match nothing and silently return, leaving the user to manually refresh. Root cause traced end-to-end via JDT-LS `.metadata/.log` and the LSP wire trace (`java.trace.server: verbose`): 1. jar lands in `lib/` 2. JDT-LS file watcher -> `UpdateClasspathJob` -> classpath delta (`>> Updating classpath` / `>> Adding `, both fire ~10x) 3. `ClasspathUpdateHandler` sends `language/eventNotification { eventType: 100, data: }` 4. vscode-java fires `onDidClasspathUpdate(uri)` 5. vscode-java-test calls `refreshProject(uri)` 6. BUG: `testController.items.size === 0` -> no match -> silent return Fix the bootstrap case by falling back to a full `refreshExplorer()` when there are no roots to match against, while keeping the existing "skip unrelated classpath updates" behaviour intact for the common case where there ARE roots but the URI matches none of them (e.g. sibling non-test projects like Gradle's `buildSrc`). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/commands/testExplorerCommands.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/testExplorerCommands.ts b/src/commands/testExplorerCommands.ts index f106d83c..ecd47c47 100644 --- a/src/commands/testExplorerCommands.ts +++ b/src/commands/testExplorerCommands.ts @@ -101,7 +101,10 @@ export async function refreshProject(classpathUri: Uri): Promise { }); await Promise.all(loadPromises); } else { - // URI doesn't match any known test project – skip to avoid unnecessary full refresh + // Bootstrap: first-time enable tests on an empty Test Explorer. + if (testController?.items.size === 0) { + await refreshExplorer(); + } return; } await showTestItemsInCurrentFile();