Respond LightWeight server mode properly (#838)

* Respond LightWeight server mode properly

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* make tslint happy

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* Refine server mode waiting logic

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* Check server status before switching

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
This commit is contained in:
Jinbo Wang 2020-07-09 15:46:33 +08:00 committed by GitHub
parent cc4039929b
commit 20cd68cbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 5 deletions

View File

@ -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();

View File

@ -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());

View File

@ -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();

View File

@ -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<boolean> {
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<boolean>({ location: vscode.ProgressLocation.Window }, async (progress) => {
if (api.serverMode === ServerMode.STANDARD) {
return true;
}
progress.report({ message: "Switching to Standard mode..." });
return new Promise<boolean>((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<boolean>((resolve) => {
api.onDidServerModeChange((mode: string) => {
if (mode === ServerMode.STANDARD) {
resolve(true);
}
});
});
}
return true;
}