use auto attach children instead of multiple launch configs

This is a new (with js-debug) option that makes debugging child processes much easier. Use it for the LSP subprocesses.

Supplants https://github.com/microsoft/vscode-extension-samples/pull/704
This commit is contained in:
Connor Peet
2022-12-06 15:31:35 -08:00
parent 7e2f7f11d0
commit dbee9a0daf
13 changed files with 11 additions and 123 deletions

View File

@ -9,19 +9,12 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"autoAttachChildProcesses": true,
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
@ -34,11 +27,5 @@
],
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": ["Launch Client", "Attach to Server"]
}
]
}

View File

@ -20,10 +20,6 @@ export function activate(context: ExtensionContext) {
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
@ -31,7 +27,6 @@ export function activate(context: ExtensionContext) {
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

View File

@ -9,19 +9,12 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"autoAttachChildProcesses": true,
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
@ -34,11 +27,5 @@
],
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": ["Launch Client", "Attach to Server"]
}
]
}

View File

@ -16,9 +16,6 @@ const htmlLanguageService = getLanguageService();
export function activate(context: ExtensionContext) {
// The server is implemented in node
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
@ -27,7 +24,6 @@ export function activate(context: ExtensionContext) {
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

View File

@ -8,21 +8,11 @@
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"autoAttachChildProcesses": true,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"preLaunchTask": "npm: watch:client"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"address": "localhost",
"protocol": "inspector",
"port": 6009,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
@ -33,15 +23,8 @@
"--extensionTestsPath=${workspaceRoot}/client/out/test",
"${workspaceRoot}/client/testFixture"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": ["Launch Client", "Attach to Server"]
}
]
}

View File

@ -29,9 +29,6 @@ export function activate(context: ExtensionContext) {
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
@ -40,7 +37,6 @@ export function activate(context: ExtensionContext) {
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

View File

@ -8,30 +8,10 @@
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"autoAttachChildProcesses": true,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server 6011",
"address": "localhost",
"protocol": "inspector",
"port": 6011,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server 6012",
"address": "localhost",
"protocol": "inspector",
"port": 6012,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
}
]
}

View File

@ -61,10 +61,9 @@ export function activate(context: ExtensionContext) {
const uri = document.uri;
// Untitled files go to a default client.
if (uri.scheme === 'untitled' && !defaultClient) {
const debugOptions = { execArgv: ["--nolazy", "--inspect=6010"] };
const serverOptions = {
run: { module, transport: TransportKind.ipc },
debug: { module, transport: TransportKind.ipc, options: debugOptions}
debug: { module, transport: TransportKind.ipc }
};
const clientOptions: LanguageClientOptions = {
documentSelector: [
@ -87,10 +86,9 @@ export function activate(context: ExtensionContext) {
folder = getOuterMostWorkspaceFolder(folder);
if (!clients.has(folder.uri.toString())) {
const debugOptions = { execArgv: ["--nolazy", `--inspect=${6011 + clients.size}`] };
const serverOptions = {
run: { module, transport: TransportKind.ipc },
debug: { module, transport: TransportKind.ipc, options: debugOptions}
debug: { module, transport: TransportKind.ipc }
};
const clientOptions: LanguageClientOptions = {
documentSelector: [
@ -128,4 +126,4 @@ export function deactivate(): Thenable<void> {
promises.push(client.stop());
}
return Promise.all(promises).then(() => undefined);
}
}

View File

@ -9,19 +9,12 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"autoAttachChildProcesses": true,
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
@ -34,11 +27,5 @@
],
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": ["Launch Client", "Attach to Server"]
}
]
}

View File

@ -32,7 +32,6 @@ It also includes an End-to-End test.
- Switch to the Run and Debug View in the Sidebar (Ctrl+Shift+D).
- Select `Launch Client` from the drop down (if it is not already).
- Press ▷ to run the launch config (F5).
- If you want to debug the server as well, use the launch configuration `Attach to Server`
- In the [Extension Development Host](https://code.visualstudio.com/api/get-started/your-first-extension#:~:text=Then%2C%20inside%20the%20editor%2C%20press%20F5.%20This%20will%20compile%20and%20run%20the%20extension%20in%20a%20new%20Extension%20Development%20Host%20window.) instance of VSCode, open a document in 'plain text' language mode.
- Type `j` or `t` to see `Javascript` and `TypeScript` completion.
- Enter text content such as `AAA aaa BBB`. The extension will emit diagnostics for all words in all-uppercase.

View File

@ -20,9 +20,6 @@ export function activate(context: ExtensionContext) {
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
@ -31,7 +28,6 @@ export function activate(context: ExtensionContext) {
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

View File

@ -8,26 +8,10 @@
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}" ],
"stopOnEntry": false,
"autoAttachChildProcesses": true,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/client/out/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"address": "localhost",
"protocol": "inspector",
"port": 6011,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/server/out/**/*.js"]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": ["Launch Client", "Attach to Server"]
}
]
}

View File

@ -12,7 +12,7 @@ export function activate(context: ExtensionContext): void {
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'sampleServer.js'));
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } },
debug: { module: serverModule, transport: TransportKind.ipc, options: { execArgv: ['--nolazy', '--inspect=6011'], cwd: process.cwd() } }
debug: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } }
};
let clientOptions: LanguageClientOptions = {
@ -48,4 +48,4 @@ export function activate(context: ExtensionContext): void {
}
export function deactivate() {
}
}