Skip to content

Commit 7bc4c86

Browse files
Delay registering codelens provider until java extension is activated (#632)
Signed-off-by: Jinbo Wang <[email protected]>
1 parent 0b1e326 commit 7bc4c86

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/debugCodeLensProvider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,30 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w
77

88
import { JAVA_LANGID } from "./constants";
99
import { IMainMethod, resolveMainMethod } from "./languageServerPlugin";
10+
import { getJavaExtensionAPI, isJavaExtEnabled } from "./utility";
1011

1112
const JAVA_RUN_CODELENS_COMMAND = "java.debug.runCodeLens";
1213
const JAVA_DEBUG_CODELENS_COMMAND = "java.debug.debugCodeLens";
1314
const JAVA_DEBUG_CONFIGURATION = "java.debug.settings";
1415
const ENABLE_CODE_LENS_VARIABLE = "enableRunDebugCodeLens";
1516

1617
export function initializeCodeLensProvider(context: vscode.ExtensionContext): void {
17-
context.subscriptions.push(new DebugCodeLensContainer());
18+
// delay registering codelens provider until the Java extension is activated.
19+
if (isActivatedByJavaFile() && isJavaExtEnabled()) {
20+
getJavaExtensionAPI().then(() => {
21+
context.subscriptions.push(new DebugCodeLensContainer());
22+
});
23+
} else {
24+
context.subscriptions.push(new DebugCodeLensContainer());
25+
}
26+
}
27+
28+
function isActivatedByJavaFile(): boolean {
29+
if (vscode.window.activeTextEditor) {
30+
return vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.languageId === "java";
31+
}
32+
33+
return false;
1834
}
1935

2036
class DebugCodeLensContainer implements vscode.Disposable {

0 commit comments

Comments
 (0)