Skip to content

Commit

Permalink
fix - Cannot see Delegate Test to Gradle option in VS Code (#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Nov 11, 2024
1 parent 4104198 commit 96b5c94
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,7 @@ export class Extension {
}

private async activate(): Promise<void> {
const testExtension = vscode.extensions.getExtension("vscjava.vscode-java-test");
if (testExtension) {
testExtension.activate().then((api: any) => {
if (api) {
const testRunner: GradleTestRunner = this.buildServerController.getGradleTestRunner(api);
api.registerTestProfile("Delegate Test to Gradle", vscode.TestRunProfileKind.Run, testRunner);
api.registerTestProfile(
"Delegate Test to Gradle (Debug)",
vscode.TestRunProfileKind.Debug,
testRunner
);
}
});
}
this.registerGradleTestRunner();
const activated = !!(await this.rootProjectsStore.getProjectRoots()).length;
if (!this.server.isReady()) {
await this.server.start();
Expand Down Expand Up @@ -399,4 +386,35 @@ export class Extension {
public getApi(): Api {
return this.api;
}

private async registerGradleTestRunner(): Promise<void> {
// To register the Gradle test runner, we need to wait for the Test Runner extension to be activated.
// The Test Runner extension depends on the Java extension, VS Code has an issue that it doesn't
// activate the Java extension before the Test Runner extension if we call activate() for the test extension.
// Thus here we need to activate the Java extension first.
const javaLsExtension = vscode.extensions.getExtension("redhat.java");
if (!javaLsExtension) {
return;
}

const javaLsApi = await javaLsExtension.activate();
if (!javaLsApi.serverReady) {
return;
}

await javaLsApi.serverReady();
const testExtension = vscode.extensions.getExtension("vscjava.vscode-java-test");
if (testExtension) {
const testRunnerApi = await testExtension.activate();
if (testRunnerApi) {
const testRunner: GradleTestRunner = this.buildServerController.getGradleTestRunner(testRunnerApi);
testRunnerApi.registerTestProfile("Delegate Test to Gradle", vscode.TestRunProfileKind.Run, testRunner);
testRunnerApi.registerTestProfile(
"Delegate Test to Gradle (Debug)",
vscode.TestRunProfileKind.Debug,
testRunner
);
}
}
}
}

0 comments on commit 96b5c94

Please sign in to comment.