diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index fefdacf..eb30434 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -95,6 +95,12 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration mainClass: "${file}", }; try { + const isOnStandardMode = await utility.waitForStandardMode(); + if (!isOnStandardMode) { + resolve([defaultLaunchConfig]); + return ; + } + const mainClasses = await lsPlugin.resolveMainClass(folder ? folder.uri : undefined); let cache; cache = {}; @@ -148,6 +154,11 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration private async resolveAndValidateDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration) { try { + const isOnStandardMode = await utility.waitForStandardMode(); + if (!isOnStandardMode) { + return undefined; + } + if (this.isUserSettingsDirty) { this.isUserSettingsDirty = false; await updateDebugSettings(); diff --git a/src/debugCodeLensProvider.ts b/src/debugCodeLensProvider.ts index e3b36d0..e6b3bca 100644 --- a/src/debugCodeLensProvider.ts +++ b/src/debugCodeLensProvider.ts @@ -9,7 +9,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w import { JAVA_LANGID } from "./constants"; import { initializeHoverProvider } from "./hoverProvider"; import { IMainMethod, isOnClasspath, resolveMainMethod } from "./languageServerPlugin"; -import { getJavaExtensionAPI, isJavaExtEnabled } from "./utility"; +import { getJavaExtensionAPI, isJavaExtEnabled, ServerMode } from "./utility"; const JAVA_RUN_CODELENS_COMMAND = "java.debug.runCodeLens"; const JAVA_DEBUG_CODELENS_COMMAND = "java.debug.debugCodeLens"; @@ -19,8 +19,16 @@ const ENABLE_CODE_LENS_VARIABLE = "enableRunDebugCodeLens"; export function initializeCodeLensProvider(context: vscode.ExtensionContext): void { // delay registering codelens provider until the Java extension is activated. if (isActivatedByJavaFile() && isJavaExtEnabled()) { - getJavaExtensionAPI().then(() => { - context.subscriptions.push(new DebugCodeLensContainer()); + getJavaExtensionAPI().then((api) => { + if (api && (api.serverMode === ServerMode.LIGHTWEIGHT || api.serverMode === ServerMode.HYBRID)) { + api.onDidServerModeChange((mode: string) => { + if (mode === ServerMode.STANDARD) { + context.subscriptions.push(new DebugCodeLensContainer()); + } + }); + } else { + context.subscriptions.push(new DebugCodeLensContainer()); + } }); } else { context.subscriptions.push(new DebugCodeLensContainer()); diff --git a/src/extension.ts b/src/extension.ts index 0821d25..ec067be 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -204,8 +204,11 @@ async function applyHCR(hcrStatusBar: NotificationBar) { async function runJavaFile(uri: vscode.Uri, noDebug: boolean) { const alreadyActivated: boolean = utility.isJavaExtActivated(); try { - // Wait for Java Language Support extension being activated. - await utility.getJavaExtensionAPI(); + // Wait for Java Language Support extension being on Standard mode. + const isOnStandardMode = await utility.waitForStandardMode(); + if (!isOnStandardMode) { + return; + } } catch (ex) { if (ex instanceof utility.JavaExtensionNotEnabledError) { utility.guideToInstallJavaExtension(); diff --git a/src/utility.ts b/src/utility.ts index 7d563d0..5afbe33 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -178,3 +178,51 @@ export function getLauncherScriptPath() { const ext = vscode.extensions.getExtension(DEBUGGER_EXTENSION_ID); return path.join(ext.extensionPath, "scripts", "launcher.bat"); } + +export enum ServerMode { + STANDARD = "Standard", + LIGHTWEIGHT = "LightWeight", + HYBRID = "Hybrid", +} + +/** + * Wait for Java Language Support extension being on Standard mode, + * and return true if the final status is on Standard mode. + */ +export async function waitForStandardMode(): Promise { + const api = await getJavaExtensionAPI(); + if (api && api.serverMode === ServerMode.LIGHTWEIGHT) { + const answer = await vscode.window.showInformationMessage("Run/Debug feature requires Java language server to run in Standard mode. " + + "Do you want to switch it to Standard mode now?", "Yes", "Cancel"); + if (answer === "Yes") { + return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (progress) => { + if (api.serverMode === ServerMode.STANDARD) { + return true; + } + + progress.report({ message: "Switching to Standard mode..." }); + return new Promise((resolve) => { + api.onDidServerModeChange((mode: string) => { + if (mode === ServerMode.STANDARD) { + resolve(true); + } + }); + + vscode.commands.executeCommand("java.server.mode.switch", ServerMode.STANDARD, true); + }); + }); + } + + return false; + } else if (api && api.serverMode === ServerMode.HYBRID) { + return new Promise((resolve) => { + api.onDidServerModeChange((mode: string) => { + if (mode === ServerMode.STANDARD) { + resolve(true); + } + }); + }); + } + + return true; +}