Skip to content

Commit

Permalink
Extension host debugging: change to a model where VS Code triggers re…
Browse files Browse the repository at this point in the history
…attach (instead of polling)
  • Loading branch information
bpasero committed Dec 2, 2015
1 parent 5e7472b commit 58cd13b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { IPluginService, IPluginDescription } from 'vs/platform/plugins/common/p
import { IOutputService } from 'vs/workbench/parts/output/common/output';
import { IKeybindingService, IKeybindingContextKey } from 'vs/platform/keybinding/common/keybindingService';
import { IWindowService, IBroadcast } from 'vs/workbench/services/window/electron-browser/windowService';
import { ILogEntry, PLUGIN_LOG_BROADCAST_CHANNEL } from 'vs/workbench/services/thread/electron-browser/threadService';
import { ILogEntry, PLUGIN_LOG_BROADCAST_CHANNEL, PLUGIN_ATTACH_BROADCAST_CHANNEL } from 'vs/workbench/services/thread/electron-browser/threadService';

var DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';
var DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated';
Expand Down Expand Up @@ -132,6 +132,15 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}

private onBroadcast(broadcast: IBroadcast): void {

// Attach: PH is ready to be attached to
if (broadcast.channel === PLUGIN_ATTACH_BROADCAST_CHANNEL) {
this.rawAttach('extensionHost', broadcast.payload.port);

return;
}

// From this point on we require an active session
let session = this.getActiveSession();
if (!session || session.getType() !== 'extensionHost') {
return; // we are only intersted if we have an active debug session for extensionHost
Expand Down
21 changes: 16 additions & 5 deletions src/vs/workbench/services/thread/electron-browser/threadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import cp = require('child_process');
import ipc = require('ipc');

export const PLUGIN_LOG_BROADCAST_CHANNEL = 'vscode:pluginLog';
export const PLUGIN_ATTACH_BROADCAST_CHANNEL = 'vscode:pluginAttach';

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

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

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

// Notify debugger that we are ready to attach to the process if we run a development plugin
if (config.env.pluginDevelopmentPath && port) {
this.windowService.broadcast({
channel: PLUGIN_ATTACH_BROADCAST_CHANNEL,
payload: {
port: port
}
});
}

// Messages from Plugin host
this.pluginHostProcessHandle.on('message', (msg) => {

Expand Down Expand Up @@ -251,7 +262,7 @@ class PluginHostProcessManager {
}, () => this.terminate());
}

private resolveExecArgv(config: IConfiguration, clb: (execArgv: any) => void): void {
private resolveDebugPort(config: IConfiguration, clb: (port: number) => void): void {

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

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

Expand Down

0 comments on commit 58cd13b

Please sign in to comment.