Skip to content

Commit 6b52079

Browse files
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 <[email protected]> * make tslint happy Signed-off-by: Jinbo Wang <[email protected]>
1 parent 6cf236d commit 6b52079

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/configurationProvider.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import { logger, Type } from "./logger";
1616
import * as utility from "./utility";
1717
import { VariableResolver } from "./variableResolver";
1818

19+
const platformNameMappings = {
20+
win32: "windows",
21+
linux: "linux",
22+
darwin: "osx",
23+
};
24+
const platformName = platformNameMappings[process.platform];
25+
1926
export class JavaDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
2027
private isUserSettingsDirty: boolean = true;
2128
private debugHistory: MostRecentlyUsedHistory = new MostRecentlyUsedHistory();
@@ -46,6 +53,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
4653
vscode.ProviderResult<vscode.DebugConfiguration> {
4754
const resolveDebugConfigurationHandler = instrumentOperation("resolveDebugConfiguration", (operationId: string) => {
4855
try {
56+
// See https://github.com/microsoft/vscode-java-debug/issues/778
57+
// Merge the platform specific properties to the global config to simplify the subsequent resolving logic.
58+
this.mergePlatformProperties(folder, config);
4959
this.resolveVariables(folder, config);
5060
return this.heuristicallyResolveDebugConfiguration(folder, config);
5161
} catch (ex) {
@@ -93,6 +103,19 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
93103
});
94104
}
95105

106+
private mergePlatformProperties(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration) {
107+
if (config && platformName && config[platformName]) {
108+
try {
109+
for (const key of Object.keys(config[platformName])) {
110+
config[key] = config[platformName][key];
111+
}
112+
config[platformName] = undefined;
113+
} catch {
114+
// do nothing
115+
}
116+
}
117+
}
118+
96119
private resolveVariables(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration): void {
97120
// all the properties whose values are string or array of string
98121
const keys = ["mainClass", "args", "vmArgs", "modulePaths", "classPaths", "projectName",

0 commit comments

Comments
 (0)