diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts index d9b95e3983a2..665770b7a378 100644 --- a/java/java.lsp.server/vscode/src/extension.ts +++ b/java/java.lsp.server/vscode/src/extension.ts @@ -830,10 +830,12 @@ export function activate(context: ExtensionContext): VSNetBeansAPI { } }; + context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel', async (projects?) => { + testAdapter?.runTestsWithParallelParallel(projects); + })); + context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel.createProfile', async (projects?) => { - if (projects) { - testAdapter?.registerRunInParallelProfile(projects); - } + testAdapter?.registerRunInParallelProfile(projects); })); context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test', async (uri, methodName?, launchConfiguration?, testInParallel?, projects?) => { diff --git a/java/java.lsp.server/vscode/src/testAdapter.ts b/java/java.lsp.server/vscode/src/testAdapter.ts index faf6e8c9618c..66e74784b104 100644 --- a/java/java.lsp.server/vscode/src/testAdapter.ts +++ b/java/java.lsp.server/vscode/src/testAdapter.ts @@ -18,7 +18,7 @@ */ 'use strict'; -import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile } from "vscode"; +import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile, CancellationTokenSource } from "vscode"; import * as path from 'path'; import { asRange, TestCase, TestSuite } from "./protocol"; import { COMMAND_PREFIX, listeners, TEST_PROGRESS_EVENT } from "./extension"; @@ -33,6 +33,7 @@ export class NbTestAdapter { private itemsToRun: Set | undefined; private started: boolean = false; private suiteStates: Map; + private parallelRunProfile: TestRunProfile | undefined; constructor() { this.testController = tests.createTestController('apacheNetBeansController', 'Apache NetBeans'); @@ -46,7 +47,15 @@ export class NbTestAdapter { public registerRunInParallelProfile(projects: string[]) { const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects); - this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true); + this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true); + this.testController.items.replace([]); + this.load(); + } + + public runTestsWithParallelParallel(projects?: string[]) { + if (this.parallelRunProfile) { + this.run(new TestRunRequest(undefined, undefined, this.parallelRunProfile), new CancellationTokenSource().token, true, projects); + } } async load(): Promise { @@ -198,7 +207,7 @@ export class NbTestAdapter { } testProgress(suite: TestSuite): void { - const currentModule = this.testController.items.get(this.getModuleName(suite)); + const currentModule = this.testController.items.get(suite.moduleName || ""); const currentSuite = currentModule?.children.get(suite.name); switch (suite.state) { @@ -287,10 +296,11 @@ export class NbTestAdapter { } updateTests(suite: TestSuite, testExecution?: boolean): void { - const moduleName = this.getModuleName(suite); + const moduleName = suite.moduleName || ""; let currentModule = this.testController.items.get(moduleName); if (!currentModule) { - currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(moduleName, 'module'), this.getModulePath(suite)); + const parsedName = this.parseModuleName(moduleName); + currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(parsedName, 'module'), this.getModulePath(suite)); this.testController.items.add(currentModule); } @@ -360,11 +370,19 @@ export class NbTestAdapter { currentModule.children.replace(suiteChildren); } } - - getModuleName(suite: TestSuite): string { - return suite.moduleName?.replace(":", "-") || ""; + + parseModuleName(moduleName: string): string { + if (!this.parallelRunProfile) { + return moduleName.replace(":", "-"); + } + const index = moduleName.indexOf(":"); + if (index !== -1) { + return moduleName.slice(index + 1); + } + const parts = moduleName.split("-"); + return parts[parts.length - 1]; } - + getModulePath(suite: TestSuite): Uri { return Uri.parse(suite.modulePath || ""); }