Skip to content

Commit e01d3e0

Browse files
committed
Fix debug mode detection
It was no longer possible to start a remote Java debugger on lemminx, because the debug flags used to start the hosted vscode extension have changed. Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 4971d5b commit e01d3e0

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/javaServerStarter.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,34 @@ function prepareParams(requirements: RequirementsData, xmlJavaExtensions: string
7777
}
7878

7979
function startedInDebugMode(): boolean {
80-
let args = (process as any).execArgv;
80+
const args = (process as any).execArgv as string[];
81+
return hasDebugFlag(args);
82+
}
83+
84+
function hasDebugFlag(args: string[]): boolean {
8185
if (args) {
82-
return args.some((arg) => /^--debug=?/.test(arg) || /^--debug-brk=?/.test(arg) || /^--inspect-brk=?/.test(arg));
83-
};
86+
// See https://nodejs.org/en/docs/guides/debugging-getting-started/
87+
return args.some( arg => /^--inspect/.test(arg) || /^--debug/.test(arg));
88+
}
8489
return false;
8590
}
8691

8792
//exported for tests
8893
export function parseVMargs(params: any[], vmargsLine: string) {
89-
if (!vmargsLine) {
90-
return;
91-
}
92-
let vmargs = vmargsLine.match(/(?:[^\s"]+|"[^"]*")+/g);
93-
if (vmargs === null) {
94-
return;
95-
}
96-
vmargs.forEach(arg => {
97-
//remove all standalone double quotes
98-
arg = arg.replace(/(\\)?"/g, function ($0, $1) { return ($1 ? $0 : ''); });
99-
//unescape all escaped double quotes
100-
arg = arg.replace(/(\\)"/g, '"');
101-
if (params.indexOf(arg) < 0) {
102-
params.push(arg);
103-
}
104-
});
94+
if (!vmargsLine) {
95+
return;
96+
}
97+
let vmargs = vmargsLine.match(/(?:[^\s"]+|"[^"]*")+/g);
98+
if (vmargs === null) {
99+
return;
100+
}
101+
vmargs.forEach(arg => {
102+
//remove all standalone double quotes
103+
arg = arg.replace(/(\\)?"/g, function ($0, $1) { return ($1 ? $0 : ''); });
104+
//unescape all escaped double quotes
105+
arg = arg.replace(/(\\)"/g, '"');
106+
if (params.indexOf(arg) < 0) {
107+
params.push(arg);
108+
}
109+
});
105110
}

0 commit comments

Comments
 (0)