Skip to content

Commit 140474e

Browse files
authored
Accept both string and string array in args and vmArgs. (#414)
* Accept both string and string array in args and vmArgs.
1 parent a69d509 commit 140474e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
4949
### Launch
5050

5151
- `mainClass` (required) - The main class of the program (fully qualified name, e.g. [mymodule/]com.xyz.MainClass).
52-
- `args` - The command line arguments passed to the program. Use `"${command:SpecifyProgramArgs}"` to prompt for program arguments.
52+
- `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.
5353
- `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.
5454
- `modulePaths` - The modulepaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
5555
- `classPaths` - The classpaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
5656
- `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.
57-
- `vmArgs` - The extra options and system properties for the JVM (e.g. -Xms\<size\> -Xmx\<size\> -D\<name\>=\<value\>).
57+
- `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.
5858
- `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.
5959
- `cwd` - The working directory of the program.
6060
- `env` - The extra environment variables for the program.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@
7272
"default": ""
7373
},
7474
"args": {
75-
"type": "string",
75+
"type": [
76+
"array",
77+
"string"
78+
],
7679
"description": "The command line arguments passed to the program.",
7780
"default": ""
7881
},
7982
"vmArgs": {
80-
"type": "string",
83+
"type": [
84+
"array",
85+
"string"
86+
],
8187
"description": "The extra options and system properties for the JVM (e.g. -Xms<size> -Xmx<size> -D<name>=<value>).",
8288
"default": ""
8389
},

src/configurationProvider.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
164164
anchor: anchor.REQUEST_TYPE_NOT_SUPPORTED,
165165
});
166166
}
167+
168+
if (Array.isArray(config.args)) {
169+
config.args = this.concatArgs(config.args);
170+
}
171+
172+
if (Array.isArray(config.vmArgs)) {
173+
config.vmArgs = this.concatArgs(config.vmArgs);
174+
}
175+
167176
const debugServerPort = await startDebugSession();
168177
if (debugServerPort) {
169178
config.debugServer = debugServerPort;
@@ -202,6 +211,22 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
202211
}
203212
}
204213

214+
/**
215+
* Converts an array of arguments to a string as the args and vmArgs.
216+
*/
217+
private concatArgs(args: any[]): string {
218+
return _.join(_.map(args, (arg: any): string => {
219+
const str = String(arg);
220+
// if it has quotes or spaces, use double quotes to wrap it
221+
if (/['"\s]/.test(str)) {
222+
return "\"" + str.replace(/(['"\\])/g, "\\$1") + "\"";
223+
}
224+
return str;
225+
226+
// if it has only single quotes
227+
}), " ");
228+
}
229+
205230
/**
206231
* When VS Code cannot find any available DebugConfiguration, it passes a { noDebug?: boolean } to resolve.
207232
* This function judges whether a DebugConfiguration is empty by filtering out the field "noDebug".

0 commit comments

Comments
 (0)