Skip to content

Commit ce36fc5

Browse files
committed
added parsing of vmArgs
1 parent bf2421e commit ce36fc5

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

vscode/src/debugger/debugger.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { l10n } from '../localiser';
2424
import { StreamDebugAdapter } from './streamDebugAdapter';
2525
import { extCommands, nbCommands } from '../commands/commands';
2626
import { argumentsNode, environmentVariablesNode, vmOptionsNode, workingDirectoryNode } from '../views/runConfiguration';
27-
import { initializeRunConfiguration } from '../utils';
27+
import { initializeRunConfiguration, parseArguments } from '../utils';
2828
import { globalState } from '../globalState';
2929

3030
export function registerDebugger(context: ExtensionContext): void {
@@ -239,7 +239,9 @@ class RunConfigurationProvider implements vscode.DebugConfigurationProvider {
239239
config.vmArgs = vmArgs;
240240
} else if (Array.isArray(config.vmArgs)) {
241241
let cfg: string[] = config.vmArgs;
242-
cfg.push(vmArgs);
242+
243+
const result = parseArguments(vmArgs);
244+
cfg.push(...result);
243245
} else {
244246
// assume the config is a string
245247
config.vmArgs = `${config.vmArgs} ${vmArgs}`;
@@ -270,4 +272,4 @@ class RunConfigurationProvider implements vscode.DebugConfigurationProvider {
270272
});
271273
}
272274

273-
}
275+
}

vscode/src/utils.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,42 @@ export async function initializeRunConfiguration(): Promise<boolean> {
301301
}
302302
}
303303
return false;
304-
}
304+
}
305+
306+
const isQuotes = (c: string): boolean => {
307+
return c === "'" || c === '"';
308+
}
309+
310+
export const parseArguments = (input: string): string[] => {
311+
const result: string[] = [];
312+
let current = "";
313+
if (input.search(/['"]/) < 0) return input.split(/\s+/);
314+
for (let i = 0; i < input.length; i++) {
315+
const char = input[i];
316+
if (char === " ") {
317+
result.push(current);
318+
current = "";
319+
} else if (isQuotes(char)) {
320+
const quoteType = char;
321+
current += char;
322+
i++;
323+
let f = true;
324+
while (i < input.length && f) {
325+
current += input[i];
326+
const isEscapingSomethingElse = (i > 1 && input[i - 1] == "\\" && input[i - 2] == "\\");
327+
if (input[i] === quoteType && input[i - 1] != "\\" && !isEscapingSomethingElse)
328+
f = false;
329+
else
330+
i++;
331+
}
332+
} else {
333+
current += char;
334+
}
335+
}
336+
if (current) {
337+
result.push(current);
338+
}
339+
340+
return result;
341+
}
342+

0 commit comments

Comments
 (0)