Skip to content

Commit 0b6d6ac

Browse files
committed
Dispatch additional test events
1 parent e60cf75 commit 0b6d6ac

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

java/java.lsp.server/vscode/src/extension.ts

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export let client: Promise<NbLanguageClient>;
7575
export let clientRuntimeJDK : string | null = null;
7676
export const MINIMAL_JDK_VERSION = 17;
7777
export const TEST_PROGRESS_EVENT: string = "testProgress";
78+
const TEST_ADAPTER_CREATED_EVENT: string = "testAdapterCreated";
7879
let testAdapter: NbTestAdapter | undefined;
7980
let nbProcess : ChildProcess | null = null;
8081
let debugPort: number = -1;
@@ -1534,6 +1535,10 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
15341535
c.start().then(() => {
15351536
if (isJavaSupportEnabled()) {
15361537
testAdapter = new NbTestAdapter();
1538+
const testAdapterCreatedListeners = listeners.get(TEST_ADAPTER_CREATED_EVENT);
1539+
testAdapterCreatedListeners?.forEach(listener => {
1540+
commands.executeCommand(listener);
1541+
})
15371542
}
15381543
c.onNotification(StatusMessageRequest.type, showStatusBarMessage);
15391544
c.onRequest(HtmlPageRequest.type, showHtmlPage);

java/java.lsp.server/vscode/src/testAdapter.ts

+44-11
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ export class NbTestAdapter {
4646
}
4747

4848
public registerRunInParallelProfile(projects: string[]) {
49-
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
50-
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
49+
if (!this.parallelRunProfile) {
50+
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
51+
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
52+
}
5153
this.testController.items.replace([]);
5254
this.load();
5355
}
@@ -165,20 +167,33 @@ export class NbTestAdapter {
165167

166168
dispatchTestEvent(state: SuiteState, testItem: TestItem): void {
167169
if (testItem.parent && testItem.children.size > 0) {
168-
this.dispatchEvent({
169-
name: testItem.id,
170-
moduleName: testItem.parent.id,
171-
modulePath: testItem.parent.uri?.path,
172-
state,
173-
});
170+
if (testItem.id.includes(":") && testItem.parent.parent) {
171+
// special case when parameterized test
172+
this.dispatchEvent(this.getParametrizedTestEvent(state, testItem));
173+
} else {
174+
this.dispatchEvent({
175+
name: testItem.id,
176+
moduleName: testItem.parent.id,
177+
modulePath: testItem.parent.uri?.path,
178+
state,
179+
});
180+
}
174181
} else if (testItem.children.size === 0) {
175182
const testSuite = testItem.parent;
183+
const parentState = testSuite && this.suiteStates.get(testSuite) ? this.suiteStates.get(testSuite) : state;
176184
if (testSuite) {
185+
let moduleName = testSuite.parent?.id;
186+
let modulePath = testSuite.parent?.uri?.path;
187+
if (testSuite.id.includes(":") && testSuite.parent?.parent) {
188+
// special case when parameterized test
189+
moduleName = testSuite.parent.parent.id;
190+
modulePath = testSuite.parent.parent.uri?.path;
191+
}
177192
const testSuiteEvent: any = {
178193
name: testSuite.id,
179-
moduleName: testSuite.parent?.id,
180-
modulePath: testSuite.parent?.uri?.path,
181-
state,
194+
moduleName,
195+
modulePath,
196+
state: parentState,
182197
tests: []
183198
}
184199
testSuite?.children.forEach(suite => {
@@ -199,6 +214,24 @@ export class NbTestAdapter {
199214
}
200215
}
201216

217+
getParametrizedTestEvent(state: SuiteState, testItem: TestItem): any {
218+
let name = testItem.parent?.id;
219+
const idx = name?.indexOf(':') || 0;
220+
return {
221+
name,
222+
moduleName: testItem.parent?.parent?.id,
223+
modulePath: testItem.parent?.parent?.uri?.path,
224+
state,
225+
tests: [
226+
{
227+
id: name,
228+
name: name?.slice(idx + 1),
229+
state
230+
}
231+
]
232+
}
233+
}
234+
202235
dispatchEvent(event: any): void {
203236
const testProgressListeners = listeners.get(TEST_PROGRESS_EVENT);
204237
testProgressListeners?.forEach(listener => {

0 commit comments

Comments
 (0)