Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - Cannot see Delegate Test to Gradle option in VS Code #1622

Merged
merged 2 commits into from
Nov 11, 2024
Merged
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
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
);
}
}
}
}
Loading