diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index f54eed8474eb7fc7e8fe185b976dabe1058272bf..e11ea49ac335edc1eaa3fe453341ff856f79724c 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -6,7 +6,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import uri from 'vs/base/common/uri'; -import { IDebugService, IConfig, IDebugConfigurationProvider, IBreakpoint, IFunctionBreakpoint, IBreakpointData, IAdapterExecutable, ITerminalSettings, IDebugAdapter, IDebugAdapterProvider } from 'vs/workbench/parts/debug/common/debug'; +import { IDebugService, IConfig, IDebugConfigurationProvider, IBreakpoint, IFunctionBreakpoint, IBreakpointData, IAdapterExecutable, ITerminalSettings, IDebugAdapter, IDebugAdapterProvider, ISession } from 'vs/workbench/parts/debug/common/debug'; import { TPromise } from 'vs/base/common/winjs.base'; import { ExtHostContext, ExtHostDebugServiceShape, MainThreadDebugServiceShape, DebugSessionUUID, MainContext, @@ -28,6 +28,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb private _breakpointEventsActive: boolean; private _debugAdapters: Map; private _debugAdaptersHandleCounter = 1; + private _sessions: Map; constructor( extHostContext: IExtHostContext, @@ -38,7 +39,9 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb this._toDispose.push(debugService.onDidNewSession(session => { this._proxy.$acceptDebugSessionStarted(session.getId(), session.configuration.type, session.getName(false)); })); + this._sessions = new Map(); this._toDispose.push(debugService.onWillNewSession(session => { + this._sessions.set(session.getId(), session); // Need to start listening early to new session events because a custom event can come while a session is initialising this._toDispose.push(session.onDidCustomEvent(event => { if (event && event.sessionId) { @@ -46,7 +49,10 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb } })); })); - this._toDispose.push(debugService.onDidEndSession(proc => this._proxy.$acceptDebugSessionTerminated(proc.getId(), proc.configuration.type, proc.getName(false)))); + this._toDispose.push(debugService.onDidEndSession(session => { + this._proxy.$acceptDebugSessionTerminated(session.getId(), session.configuration.type, session.getName(false)); + this._sessions.delete(session.getId()); + })); this._toDispose.push(debugService.getViewModel().onDidFocusSession(proc => { if (proc) { this._proxy.$acceptDebugSessionActiveChanged(proc.getId(), proc.configuration.type, proc.getName(false)); @@ -220,9 +226,9 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb } public $customDebugAdapterRequest(sessionId: DebugSessionUUID, request: string, args: any): TPromise { - const process = this.debugService.getModel().getSessions().filter(p => p.getId() === sessionId).pop(); - if (process) { - return process.raw.custom(request, args).then(response => { + const session = this._sessions.get(sessionId); + if (session) { + return session.raw.custom(request, args).then(response => { if (response && response.success) { return response.body; } else {