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 <jinbwan@microsoft.com>

* make tslint happy

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
This commit is contained in:
Jinbo Wang 2020-03-23 16:00:05 +08:00 committed by GitHub
parent 6cf236d694
commit 6b52079ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -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<vscode.DebugConfiguration> {
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",