Add support for running DebugConfigurations with serverReadyAction (#197597)

* Add support for running DebugConfigurations with serverReadyAction

This PR adds 'config' as an option for serverReadyAction. It runs
similar to 'name', but if a configuration is generated on the fly, its
easier to inject the debug configurations with the serverReadyAction.

* Merge into startDebugSession method

---------

Co-authored-by: Rob Lourens <roblourens@gmail.com>
This commit is contained in:
Andrew Wang 2023-11-22 11:41:19 -08:00 committed by GitHub
parent 567021733a
commit 452b754c5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 4 deletions

View file

@ -158,6 +158,50 @@
"default": false
}
}
},
{
"type": "object",
"additionalProperties": false,
"markdownDescription": "%debug.server.ready.serverReadyAction.description%",
"default": {
"action": "startDebugging",
"config": {
"type": "node",
"request": "launch"
},
"killOnServerStop": false
},
"required": [
"config"
],
"properties": {
"action": {
"type": "string",
"enum": [
"startDebugging"
],
"enumDescriptions": [
"%debug.server.ready.action.startDebugging.description%"
],
"markdownDescription": "%debug.server.ready.action.description%",
"default": "startDebugging"
},
"pattern": {
"type": "string",
"markdownDescription": "%debug.server.ready.pattern.description%",
"default": "listening on port ([0-9]+)"
},
"config": {
"type": "object",
"markdownDescription": "%debug.server.ready.debugConfig.description%",
"default": {}
},
"killOnServerStop": {
"type": "boolean",
"markdownDescription": "%debug.server.ready.killOnServerStop.description%",
"default": false
}
}
}
]
}

View file

@ -8,6 +8,7 @@
"debug.server.ready.action.debugWithChrome.description": "Start debugging with the 'Debugger for Chrome'.",
"debug.server.ready.action.startDebugging.description": "Run another launch configuration.",
"debug.server.ready.pattern.description": "Server is ready if this pattern appears on the debug console. The first capture group must include a URI or a port number.",
"debug.server.ready.debugConfig.description": "The debug configuration to run.",
"debug.server.ready.uriFormat.description": "A format string used when constructing the URI from a port number. The first '%s' is substituted with the port number.",
"debug.server.ready.webRoot.description": "Value passed to the debug configuration for the 'Debugger for Chrome'.",
"debug.server.ready.killOnServerStop.description": "Stop the child session when the parent session stopped.",

View file

@ -18,6 +18,7 @@ interface ServerReadyAction {
uriFormat?: string;
webRoot?: string;
name?: string;
config?: vscode.DebugConfiguration;
killOnServerStop?: boolean;
}
@ -194,7 +195,11 @@ class ServerReadyDetector extends vscode.Disposable {
break;
case 'startDebugging':
await this.startNamedDebugSession(session, args.name || 'unspecified');
if (args.config) {
await this.startDebugSession(session, args.config.name, args.config);
} else {
await this.startDebugSession(session, args.name || 'unspecified');
}
break;
default:
@ -246,17 +251,24 @@ class ServerReadyDetector extends vscode.Disposable {
});
}
private async startNamedDebugSession(session: vscode.DebugSession, name: string) {
/**
* Starts a debug session given a debug configuration name (saved in launch.json) or a debug configuration object.
*
* @param session The parent debugSession
* @param name The name of the configuration to launch. If config it set, it assumes it is the same as config.name.
* @param config [Optional] Instead of starting a debug session by debug configuration name, use a debug configuration object instead.
*/
private async startDebugSession(session: vscode.DebugSession, name: string, config?: vscode.DebugConfiguration) {
const args = session.configuration.serverReadyAction as ServerReadyAction;
if (!args.killOnServerStop) {
await vscode.debug.startDebugging(session.workspaceFolder, name);
await vscode.debug.startDebugging(session.workspaceFolder, config ?? name);
return;
}
const cts = new vscode.CancellationTokenSource();
const newSessionPromise = this.catchStartedDebugSession(x => x.name === name, cts.token);
if (!await vscode.debug.startDebugging(session.workspaceFolder, name)) {
if (!await vscode.debug.startDebugging(session.workspaceFolder, config ?? name)) {
cts.cancel();
cts.dispose();
return;