Delay registering codelens provider until java extension is activated (#632)

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
This commit is contained in:
Jinbo Wang 2019-08-16 11:14:08 +08:00 committed by GitHub
parent 0b1e326a38
commit 7bc4c86a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w
import { JAVA_LANGID } from "./constants";
import { IMainMethod, resolveMainMethod } from "./languageServerPlugin";
import { getJavaExtensionAPI, isJavaExtEnabled } from "./utility";
const JAVA_RUN_CODELENS_COMMAND = "java.debug.runCodeLens";
const JAVA_DEBUG_CODELENS_COMMAND = "java.debug.debugCodeLens";
@ -14,7 +15,22 @@ const JAVA_DEBUG_CONFIGURATION = "java.debug.settings";
const ENABLE_CODE_LENS_VARIABLE = "enableRunDebugCodeLens";
export function initializeCodeLensProvider(context: vscode.ExtensionContext): void {
context.subscriptions.push(new DebugCodeLensContainer());
// delay registering codelens provider until the Java extension is activated.
if (isActivatedByJavaFile() && isJavaExtEnabled()) {
getJavaExtensionAPI().then(() => {
context.subscriptions.push(new DebugCodeLensContainer());
});
} else {
context.subscriptions.push(new DebugCodeLensContainer());
}
}
function isActivatedByJavaFile(): boolean {
if (vscode.window.activeTextEditor) {
return vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.languageId === "java";
}
return false;
}
class DebugCodeLensContainer implements vscode.Disposable {