Accept both string and string array in args and vmArgs. (#414)
* Accept both string and string array in args and vmArgs.
This commit is contained in:
parent
a69d509ad3
commit
140474e956
|
@ -49,12 +49,12 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
|
|||
### Launch
|
||||
|
||||
- `mainClass` (required) - The main class of the program (fully qualified name, e.g. [mymodule/]com.xyz.MainClass).
|
||||
- `args` - The command line arguments passed to the program. Use `"${command:SpecifyProgramArgs}"` to prompt for program arguments.
|
||||
- `args` - The command line arguments passed to the program. Use `"${command:SpecifyProgramArgs}"` to prompt for program arguments. It accepts a string or an array of string.
|
||||
- `sourcePaths` - The extra source directories of the program. The debugger looks for source code from project settings by default. This option allows the debugger to look for source code in extra directories.
|
||||
- `modulePaths` - The modulepaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
|
||||
- `classPaths` - The classpaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
|
||||
- `encoding` - The `file.encoding` setting for the JVM. If not specified, 'UTF-8' will be used. Possible values can be found in http://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html.
|
||||
- `vmArgs` - The extra options and system properties for the JVM (e.g. -Xms\<size\> -Xmx\<size\> -D\<name\>=\<value\>).
|
||||
- `vmArgs` - The extra options and system properties for the JVM (e.g. -Xms\<size\> -Xmx\<size\> -D\<name\>=\<value\>), it accepts a string or an array of string.
|
||||
- `projectName` - The preferred project in which the debugger searches for classes. There could be duplicated class names in different projects. This setting also works when the debugger looks for the specified main class when launching a program. It is required when the workspace has multiple java projects, otherwise the expression evaluation and conditional breakpoint may not work.
|
||||
- `cwd` - The working directory of the program.
|
||||
- `env` - The extra environment variables for the program.
|
||||
|
|
10
package.json
10
package.json
|
@ -72,12 +72,18 @@
|
|||
"default": ""
|
||||
},
|
||||
"args": {
|
||||
"type": "string",
|
||||
"type": [
|
||||
"array",
|
||||
"string"
|
||||
],
|
||||
"description": "The command line arguments passed to the program.",
|
||||
"default": ""
|
||||
},
|
||||
"vmArgs": {
|
||||
"type": "string",
|
||||
"type": [
|
||||
"array",
|
||||
"string"
|
||||
],
|
||||
"description": "The extra options and system properties for the JVM (e.g. -Xms<size> -Xmx<size> -D<name>=<value>).",
|
||||
"default": ""
|
||||
},
|
||||
|
|
|
@ -164,6 +164,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
|||
anchor: anchor.REQUEST_TYPE_NOT_SUPPORTED,
|
||||
});
|
||||
}
|
||||
|
||||
if (Array.isArray(config.args)) {
|
||||
config.args = this.concatArgs(config.args);
|
||||
}
|
||||
|
||||
if (Array.isArray(config.vmArgs)) {
|
||||
config.vmArgs = this.concatArgs(config.vmArgs);
|
||||
}
|
||||
|
||||
const debugServerPort = await startDebugSession();
|
||||
if (debugServerPort) {
|
||||
config.debugServer = debugServerPort;
|
||||
|
@ -202,6 +211,22 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of arguments to a string as the args and vmArgs.
|
||||
*/
|
||||
private concatArgs(args: any[]): string {
|
||||
return _.join(_.map(args, (arg: any): string => {
|
||||
const str = String(arg);
|
||||
// if it has quotes or spaces, use double quotes to wrap it
|
||||
if (/['"\s]/.test(str)) {
|
||||
return "\"" + str.replace(/(['"\\])/g, "\\$1") + "\"";
|
||||
}
|
||||
return str;
|
||||
|
||||
// if it has only single quotes
|
||||
}), " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* When VS Code cannot find any available DebugConfiguration, it passes a { noDebug?: boolean } to resolve.
|
||||
* This function judges whether a DebugConfiguration is empty by filtering out the field "noDebug".
|
||||
|
|
Loading…
Reference in New Issue