Add a debug flag to allow remote debugging (#524)

With this flag on, it is possible to remote-debug the language server in a java debugger.
This commit is contained in:
Andrew Eisenberg
2020-08-06 11:08:26 -07:00
committed by GitHub
parent 8ccb7c4fa4
commit 648bf4b629
2 changed files with 16 additions and 2 deletions

6
.vscode/launch.json vendored
View File

@@ -15,7 +15,11 @@
"outFiles": [
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
],
"preLaunchTask": "Build"
"preLaunchTask": "Build",
"env": {
// uncomment to allow debugging the language server Java process from a remote java debugger
// "DEBUG_LANGUAGE_SERVER": "true"
}
},
{
"name": "Launch Unit Tests (vscode-codeql)",

View File

@@ -11,11 +11,15 @@ import { ideServerLogger } from './logging';
/** Starts a new CodeQL language server process, sending progress messages to the status bar. */
export async function spawnIdeServer(config: QueryServerConfig): Promise<StreamInfo> {
return window.withProgress({ title: 'CodeQL language server', location: ProgressLocation.Window }, async (progressReporter, _) => {
const args = ['--check-errors', 'ON_CHANGE'];
if (shouldDebug()) {
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=n,quiet=y');
}
const child = cli.spawnServer(
config.codeQlPath,
'CodeQL language server',
['execute', 'language-server'],
['--check-errors', 'ON_CHANGE'],
args,
ideServerLogger,
data => ideServerLogger.log(data.toString(), { trailingNewline: false }),
data => ideServerLogger.log(data.toString(), { trailingNewline: false }),
@@ -24,3 +28,9 @@ export async function spawnIdeServer(config: QueryServerConfig): Promise<StreamI
return { writer: child.stdin!, reader: child.stdout! };
});
}
function shouldDebug() {
return 'DEBUG_LANGUAGE_SERVER' in process.env
&& process.env.DEBUG_LANGUAGE_SERVER !== '0'
&& process.env.DEBUG_LANGUAGE_SERVER?.toLocaleLowerCase() !== 'false';
}