From 6b52079ce4e414782d27238df7f3cff3c99192fe Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 23 Mar 2020 16:00:05 +0800 Subject: [PATCH] Fix the compatability issue caused by platform specific properties in launch.json (#779) * Fix the compatability issue caused by platform specific properties in launch.json Signed-off-by: Jinbo Wang * make tslint happy Signed-off-by: Jinbo Wang --- src/configurationProvider.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index 9bd8e99..bd6aec2 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -16,6 +16,13 @@ import { logger, Type } from "./logger"; import * as utility from "./utility"; import { VariableResolver } from "./variableResolver"; +const platformNameMappings = { + win32: "windows", + linux: "linux", + darwin: "osx", +}; +const platformName = platformNameMappings[process.platform]; + export class JavaDebugConfigurationProvider implements vscode.DebugConfigurationProvider { private isUserSettingsDirty: boolean = true; private debugHistory: MostRecentlyUsedHistory = new MostRecentlyUsedHistory(); @@ -46,6 +53,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration vscode.ProviderResult { const resolveDebugConfigurationHandler = instrumentOperation("resolveDebugConfiguration", (operationId: string) => { try { + // See https://github.com/microsoft/vscode-java-debug/issues/778 + // Merge the platform specific properties to the global config to simplify the subsequent resolving logic. + this.mergePlatformProperties(folder, config); this.resolveVariables(folder, config); return this.heuristicallyResolveDebugConfiguration(folder, config); } catch (ex) { @@ -93,6 +103,19 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration }); } + private mergePlatformProperties(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration) { + if (config && platformName && config[platformName]) { + try { + for (const key of Object.keys(config[platformName])) { + config[key] = config[platformName][key]; + } + config[platformName] = undefined; + } catch { + // do nothing + } + } + } + private resolveVariables(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration): void { // all the properties whose values are string or array of string const keys = ["mainClass", "args", "vmArgs", "modulePaths", "classPaths", "projectName",