Skip to content

Commit a7bf5e6

Browse files
committed
Add debug flag for query server
And separate flag for IDE server. Setting these flags to `true` will start the respective Java processes in debug mode so that they can be attached to a debugger.
1 parent e0cd041 commit a7bf5e6

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

.vscode/launch.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
1717
],
1818
"env": {
19-
// uncomment to allow debugging the language server Java process from a remote java debugger
20-
// "DEBUG_LANGUAGE_SERVER": "true"
19+
// change to 'true' debug the IDE or Query servers
20+
"IDE_SERVER_JAVA_DEBUG": "false",
21+
"QUERY_SERVER_JAVA_DEBUG": "false",
2122
}
2223
},
2324
{

extensions/ql-vscode/src/cli.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,3 +907,16 @@ async function logStream(stream: Readable, logger: Logger): Promise<void> {
907907
logger.log(line);
908908
}
909909
}
910+
911+
912+
export function shouldDebugIdeServer() {
913+
return 'IDE_SERVER_JAVA_DEBUG' in process.env
914+
&& process.env.IDE_SERVER_JAVA_DEBUG !== '0'
915+
&& process.env.IDE_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
916+
}
917+
918+
export function shouldDebugQueryServer() {
919+
return 'QUERY_SERVER_JAVA_DEBUG' in process.env
920+
&& process.env.QUERY_SERVER_JAVA_DEBUG !== '0'
921+
&& process.env.QUERY_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
922+
}

extensions/ql-vscode/src/ide-server.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ideServerLogger } from './logging';
1212
export async function spawnIdeServer(config: QueryServerConfig): Promise<StreamInfo> {
1313
return window.withProgress({ title: 'CodeQL language server', location: ProgressLocation.Window }, async (progressReporter, _) => {
1414
const args = ['--check-errors', 'ON_CHANGE'];
15-
if (shouldDebug()) {
15+
if (cli.shouldDebugIdeServer()) {
1616
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=n,quiet=y');
1717
}
1818
const child = cli.spawnServer(
@@ -28,9 +28,3 @@ export async function spawnIdeServer(config: QueryServerConfig): Promise<StreamI
2828
return { writer: child.stdin!, reader: child.stdout! };
2929
});
3030
}
31-
32-
function shouldDebug() {
33-
return 'DEBUG_LANGUAGE_SERVER' in process.env
34-
&& process.env.DEBUG_LANGUAGE_SERVER !== '0'
35-
&& process.env.DEBUG_LANGUAGE_SERVER?.toLocaleLowerCase() !== 'false';
36-
}

extensions/ql-vscode/src/queryserver-client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ export class QueryServerClient extends DisposableObject {
107107
if (this.config.debug) {
108108
args.push('--debug', '--tuple-counting');
109109
}
110+
111+
if (cli.shouldDebugQueryServer()) {
112+
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9010,server=y,suspend=n,quiet=y');
113+
}
114+
110115
const child = cli.spawnServer(
111116
this.config.codeQlPath,
112117
'CodeQL query server',

0 commit comments

Comments
 (0)