Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export let client: Promise<NbLanguageClient>;
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;
Expand Down Expand Up @@ -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);
Expand Down
61 changes: 50 additions & 11 deletions java/java.lsp.server/vscode/src/testAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will be the behaviour of the rest of the code on testEvents with undefined name and id ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't happen. But I added explicit check for that case

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 => {
Expand Down
Loading