diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index d3396b60bde..7f3e0c1f03e 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -5483,6 +5483,11 @@ declare module 'vscode' { */ export const onDidChangeActiveDebugSession: Event; + /** + * An [event](#Event) which fires when a new debug session has been started. + */ + export const onDidStartDebugSession: Event; + /** * An [event](#Event) which fires when a custom DAP event is received from the debug session. */ diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index 0f3e4050c5d..8f85bd5312c 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -23,6 +23,7 @@ export class MainThreadDebugService extends MainThreadDebugServiceShape { this._proxy = threadService.get(ExtHostContext.ExtHostDebugService); this._toDispose = []; + this._toDispose.push(debugService.onDidNewProcess(proc => this._proxy.$acceptDebugSessionStarted(proc.getId(), proc.configuration.type, proc.name))); this._toDispose.push(debugService.onDidEndProcess(proc => this._proxy.$acceptDebugSessionTerminated(proc.getId(), proc.configuration.type, proc.name))); this._toDispose.push(debugService.getViewModel().onDidFocusProcess(proc => { if (proc) { diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 1c08f1cf6be..5882e710102 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -470,6 +470,9 @@ export function createApiFactory( startDebugSession(config: vscode.DebugConfiguration) { return extHostDebugService.startDebugSession(config); }, + onDidStartDebugSession(listener, thisArg?, disposables?) { + return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables); + }, onDidTerminateDebugSession(listener, thisArg?, disposables?) { return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables); }, diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index f724fae276a..8425a69ad20 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -499,6 +499,7 @@ export abstract class ExtHostTaskShape { } export abstract class ExtHostDebugServiceShape { + $acceptDebugSessionStarted(id: DebugSessionUUID, type: string, name: string): void { throw ni(); } $acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { throw ni(); } $acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { throw ni(); } $acceptDebugSessionCustomEvent(id: DebugSessionUUID, type: string, name: string, event: any): void { throw ni(); } diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 0e591c82529..8ff6c387d7c 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -18,6 +18,9 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape { private _debugServiceProxy: MainThreadDebugServiceShape; private _debugSessions: Map = new Map(); + private _onDidStartDebugSession: Emitter; + get onDidStartDebugSession(): Event { return this._onDidStartDebugSession.event; } + private _onDidTerminateDebugSession: Emitter; get onDidTerminateDebugSession(): Event { return this._onDidTerminateDebugSession.event; } @@ -34,6 +37,7 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape { constructor(threadService: IThreadService) { super(); + this._onDidStartDebugSession = new Emitter(); this._onDidTerminateDebugSession = new Emitter(); this._onDidChangeActiveDebugSession = new Emitter(); this._onDidReceiveDebugSessionCustomEvent = new Emitter(); @@ -50,6 +54,16 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape { }); } + public $acceptDebugSessionStarted(id: DebugSessionUUID, type: string, name: string): void { + + let debugSession = this._debugSessions.get(id); + if (!debugSession) { + debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name); + this._debugSessions.set(id, debugSession); + } + this._onDidStartDebugSession.fire(debugSession); + } + public $acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { let debugSession = this._debugSessions.get(id); diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index d7dffcdb029..940d0a6cf95 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -440,6 +440,11 @@ export interface IDebugService { */ onDidChangeState: Event; + /** + * Allows to register on new process events. + */ + onDidNewProcess: Event; + /** * Allows to register on end process events. */ diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 8712ddf7458..bbc9faab89e 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -68,6 +68,7 @@ export class DebugService implements debug.IDebugService { private sessionStates: Map; private _onDidChangeState: Emitter; + private _onDidNewProcess: Emitter; private _onDidEndProcess: Emitter; private _onDidCustomEvent: Emitter; private model: Model; @@ -110,6 +111,7 @@ export class DebugService implements debug.IDebugService { this.toDisposeOnSessionEnd = new Map(); this.breakpointsToSendOnResourceSaved = new Set(); this._onDidChangeState = new Emitter(); + this._onDidNewProcess = new Emitter(); this._onDidEndProcess = new Emitter(); this._onDidCustomEvent = new Emitter(); this.sessionStates = new Map(); @@ -291,7 +293,9 @@ export class DebugService implements debug.IDebugService { } private registerSessionListeners(process: Process, session: RawDebugSession): void { + this.toDisposeOnSessionEnd.get(session.getId()).push(session); + this.toDisposeOnSessionEnd.get(session.getId()).push(session.onDidInitialize(event => { aria.status(nls.localize('debuggingStarted', "Debugging started.")); const sendConfigurationDone = () => { @@ -503,6 +507,10 @@ export class DebugService implements debug.IDebugService { return this._onDidChangeState.event; } + public get onDidNewProcess(): Event { + return this._onDidNewProcess.event; + } + public get onDidEndProcess(): Event { return this._onDidEndProcess.event; } @@ -842,6 +850,7 @@ export class DebugService implements debug.IDebugService { this.viewModel.setMultiProcessView(true); } this.updateStateAndEmit(session.getId(), debug.State.Running); + this._onDidNewProcess.fire(process); return this.telemetryService.publicLog('debugSessionStart', { type: configuration.type, diff --git a/src/vs/workbench/parts/debug/test/common/mockDebug.ts b/src/vs/workbench/parts/debug/test/common/mockDebug.ts index afcc057d1e1..e8d09bf95a0 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebug.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebug.ts @@ -19,6 +19,10 @@ export class MockDebugService implements debug.IDebugService { return null; } + public get onDidNewProcess(): Event { + return null; + } + public get onDidEndProcess(): Event { return null; }