Skip to content

Commit 58cd13b

Browse files
author
Benjamin Pasero
committed
Extension host debugging: change to a model where VS Code triggers reattach (instead of polling)
1 parent 5e7472b commit 58cd13b

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { IPluginService, IPluginDescription } from 'vs/platform/plugins/common/p
4444
import { IOutputService } from 'vs/workbench/parts/output/common/output';
4545
import { IKeybindingService, IKeybindingContextKey } from 'vs/platform/keybinding/common/keybindingService';
4646
import { IWindowService, IBroadcast } from 'vs/workbench/services/window/electron-browser/windowService';
47-
import { ILogEntry, PLUGIN_LOG_BROADCAST_CHANNEL } from 'vs/workbench/services/thread/electron-browser/threadService';
47+
import { ILogEntry, PLUGIN_LOG_BROADCAST_CHANNEL, PLUGIN_ATTACH_BROADCAST_CHANNEL } from 'vs/workbench/services/thread/electron-browser/threadService';
4848

4949
var DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';
5050
var DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated';
@@ -132,6 +132,15 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
132132
}
133133

134134
private onBroadcast(broadcast: IBroadcast): void {
135+
136+
// Attach: PH is ready to be attached to
137+
if (broadcast.channel === PLUGIN_ATTACH_BROADCAST_CHANNEL) {
138+
this.rawAttach('extensionHost', broadcast.payload.port);
139+
140+
return;
141+
}
142+
143+
// From this point on we require an active session
135144
let session = this.getActiveSession();
136145
if (!session || session.getType() !== 'extensionHost') {
137146
return; // we are only intersted if we have an active debug session for extensionHost

src/vs/workbench/services/thread/electron-browser/threadService.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import cp = require('child_process');
2727
import ipc = require('ipc');
2828

2929
export const PLUGIN_LOG_BROADCAST_CHANNEL = 'vscode:pluginLog';
30+
export const PLUGIN_ATTACH_BROADCAST_CHANNEL = 'vscode:pluginAttach';
3031

3132
// Enable to see detailed message communication between window and plugin host
3233
const logPluginHostCommunication = false;
@@ -126,14 +127,24 @@ class PluginHostProcessManager {
126127
this.initializePluginHostProcess = new TPromise<cp.ChildProcess>((c, e) => {
127128

128129
// Resolve additional execution args (e.g. debug)
129-
return this.resolveExecArgv(config, (execArgv) => {
130-
if (execArgv) {
131-
opts.execArgv = execArgv;
130+
return this.resolveDebugPort(config, (port) => {
131+
if (port) {
132+
opts.execArgv = ['--nolazy', (config.env.debugBrkPluginHost ? '--debug-brk=' : '--debug=') + port];
132133
}
133134

134135
// Run Plugin Host as fork of current process
135136
this.pluginHostProcessHandle = cp.fork(uri.parse(require.toUrl('bootstrap')).fsPath, ['--type=pluginHost'], opts);
136137

138+
// Notify debugger that we are ready to attach to the process if we run a development plugin
139+
if (config.env.pluginDevelopmentPath && port) {
140+
this.windowService.broadcast({
141+
channel: PLUGIN_ATTACH_BROADCAST_CHANNEL,
142+
payload: {
143+
port: port
144+
}
145+
});
146+
}
147+
137148
// Messages from Plugin host
138149
this.pluginHostProcessHandle.on('message', (msg) => {
139150

@@ -251,7 +262,7 @@ class PluginHostProcessManager {
251262
}, () => this.terminate());
252263
}
253264

254-
private resolveExecArgv(config: IConfiguration, clb: (execArgv: any) => void): void {
265+
private resolveDebugPort(config: IConfiguration, clb: (port: number) => void): void {
255266

256267
// Check for a free debugging port
257268
if (typeof config.env.debugPluginHostPort === 'number') {
@@ -272,7 +283,7 @@ class PluginHostProcessManager {
272283
console.info('%c[Plugin Host] %cdebugger listening on port ' + port, 'color: blue', 'color: black');
273284
}
274285

275-
return clb(['--nolazy', (config.env.debugBrkPluginHost ? '--debug-brk=' : '--debug=') + port]);
286+
return clb(port);
276287
});
277288
}
278289

0 commit comments

Comments
 (0)