diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts index dbd6de6b40e1..d43b8dcd16c0 100644 --- a/java/java.lsp.server/vscode/src/extension.ts +++ b/java/java.lsp.server/vscode/src/extension.ts @@ -75,6 +75,7 @@ export let client: Promise; export let clientRuntimeJDK : string | null = null; export const MINIMAL_JDK_VERSION = 17; export const TEST_PROGRESS_EVENT: string = "testProgress"; +const TEST_ADAPTER_CREATED_EVENT: string = "testAdapterCreated"; let testAdapter: NbTestAdapter | undefined; let nbProcess : ChildProcess | null = null; let debugPort: number = -1; @@ -1534,6 +1535,10 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex c.start().then(() => { if (isJavaSupportEnabled()) { testAdapter = new NbTestAdapter(); + const testAdapterCreatedListeners = listeners.get(TEST_ADAPTER_CREATED_EVENT); + testAdapterCreatedListeners?.forEach(listener => { + commands.executeCommand(listener); + }) } c.onNotification(StatusMessageRequest.type, showStatusBarMessage); c.onRequest(HtmlPageRequest.type, showHtmlPage); diff --git a/java/java.lsp.server/vscode/src/testAdapter.ts b/java/java.lsp.server/vscode/src/testAdapter.ts index 976de6647226..e4d9f3feb34b 100644 --- a/java/java.lsp.server/vscode/src/testAdapter.ts +++ b/java/java.lsp.server/vscode/src/testAdapter.ts @@ -46,8 +46,10 @@ export class NbTestAdapter { } public registerRunInParallelProfile(projects: string[]) { - const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects); - this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true); + if (!this.parallelRunProfile) { + const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects); + this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true); + } this.testController.items.replace([]); this.load(); } @@ -165,20 +167,36 @@ export class NbTestAdapter { dispatchTestEvent(state: SuiteState, testItem: TestItem): void { if (testItem.parent && testItem.children.size > 0) { - this.dispatchEvent({ - name: testItem.id, - moduleName: testItem.parent.id, - modulePath: testItem.parent.uri?.path, - state, - }); + if (testItem.id.includes(":") && testItem.parent.parent) { + // special case when parameterized test + const testEvent = this.getParametrizedTestEvent(state, testItem); + if (!testEvent) return; + + this.dispatchEvent(testEvent); + } else { + this.dispatchEvent({ + name: testItem.id, + moduleName: testItem.parent.id, + modulePath: testItem.parent.uri?.path, + state, + }); + } } else if (testItem.children.size === 0) { const testSuite = testItem.parent; + const parentState = testSuite && this.suiteStates.get(testSuite) ? this.suiteStates.get(testSuite) : state; if (testSuite) { + let moduleName = testSuite.parent?.id; + let modulePath = testSuite.parent?.uri?.path; + if (testSuite.id.includes(":") && testSuite.parent?.parent) { + // special case when parameterized test + moduleName = testSuite.parent.parent.id; + modulePath = testSuite.parent.parent.uri?.path; + } const testSuiteEvent: any = { name: testSuite.id, - moduleName: testSuite.parent?.id, - modulePath: testSuite.parent?.uri?.path, - state, + moduleName, + modulePath, + state: parentState, tests: [] } testSuite?.children.forEach(suite => { @@ -199,6 +217,27 @@ export class NbTestAdapter { } } + getParametrizedTestEvent(state: SuiteState, testItem: TestItem): any { + if (!testItem.parent || !testItem.parent.parent) { + return undefined; + } + let name = testItem.parent.id; + const idx = name.indexOf(':'); + return { + name, + moduleName: testItem.parent.parent.id, + modulePath: testItem.parent.parent.uri?.path, + state, + tests: [ + { + id: name, + name: name.slice(idx + 1), + state + } + ] + } + } + dispatchEvent(event: any): void { const testProgressListeners = listeners.get(TEST_PROGRESS_EVENT); testProgressListeners?.forEach(listener => {