diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 6b3227a6cff087d1f1468b908811f8903649b40a..8430b05ab96ef088546259f21367a111a42e4b24 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -189,4 +189,22 @@ declare module 'vscode' { */ onData(callback: (data: string) => any): void; } + + export namespace debug { + + /** + * The currently active debug session or `undefined`. The active debug session is the one + * represented by the debug action floating window or the one currently shown in the drop down menu of the debug action floating window. + * If no debug session is active, the value is `undefined`. + */ + export const activeDebugSession: DebugSession | undefined; + + /** + * An [event](#Event) which fires when the [active debug session](#debug.activeDebugSession) + * has changed. *Note* that the event also fires when the active debug session changes + * to `undefined`. + */ + export const onDidChangeActiveDebugSession: Event; + } + } diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index dc3186f738d2f8876f7811056f5009a7b418b97e..a467704954235c2db764edcadb733f2c7de4b483 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -20,9 +20,17 @@ export class MainThreadDebugService extends MainThreadDebugServiceShape { @IDebugService private debugService: IDebugService ) { super(); + this._proxy = threadService.get(ExtHostContext.ExtHostDebugService); this._toDispose = []; 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) { + this._proxy.$acceptDebugSessionActiveChanged(proc.getId(), proc.configuration.type, proc.name); + } else { + this._proxy.$acceptDebugSessionActiveChanged(undefined); + } + })); } public dispose(): void { diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 56c79673a9b5fdd6fffc5de0b5def7447415d649..2155bc87c32304da01214874403f4728d25b9de7 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -463,12 +463,19 @@ export function createApiFactory( // namespace: debug const debug: typeof vscode.debug = { + get activeDebugSession() { + assertProposedApi(extension); + return extHostDebugService.activeDebugSession; + }, createDebugSession(config: vscode.DebugConfiguration) { return extHostDebugService.createDebugSession(config); }, onDidTerminateDebugSession(listener, thisArg?, disposables?) { return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables); - } + }, + onDidChangeActiveDebugSession: proposedApiFunction(extension, (listener, thisArg?, disposables?) => { + return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables); + }) }; diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 31a81ca180995cb16199fb1b334202e042302b50..99db9aa1563151f3659c6c190b00a7028999d1b7 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -501,6 +501,7 @@ export abstract class ExtHostTaskShape { export abstract class ExtHostDebugServiceShape { $acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { throw ni(); } + $acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { throw ni(); } } // --- proxy identifiers diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 3b1a496cd6fafcfcc5d90b563288d301381cb4a0..5a16373fe232d9261d5d3f92305728e2cd7cf128 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -21,11 +21,18 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape { private _onDidTerminateDebugSession: Emitter; get onDidTerminateDebugSession(): Event { return this._onDidTerminateDebugSession.event; } + private _onDidChangeActiveDebugSession: Emitter; + get onDidChangeActiveDebugSession(): Event { return this._onDidChangeActiveDebugSession.event; } + + private _activeDebugSession: vscode.DebugSession | undefined; + get activeDebugSession(): vscode.DebugSession | undefined { return this._activeDebugSession; } constructor(threadService: IThreadService) { super(); this._onDidTerminateDebugSession = new Emitter(); + this._onDidChangeActiveDebugSession = new Emitter(); + this._debugServiceProxy = threadService.get(MainContext.MainThreadDebugService); } @@ -47,6 +54,19 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape { this._onDidTerminateDebugSession.fire(debugSession); this._debugSessions.delete(id); } + + public $acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { + + if (id) { + this._activeDebugSession = this._debugSessions.get(id); + if (!this._activeDebugSession) { + this._activeDebugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name); + } + } else { + this._activeDebugSession = undefined; + } + this._onDidChangeActiveDebugSession.fire(this._activeDebugSession); + } } export class ExtHostDebugSession implements vscode.DebugSession { diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index ebba65013cb3a91ba013baca8d01075fba7f281d..182aa4a25fcb9777e29d7f94618a9fdb0986f844 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -273,6 +273,7 @@ export interface IViewModel extends ITreeElement { isMultiProcessView(): boolean; + onDidFocusProcess: Event; onDidFocusStackFrame: Event; onDidSelectExpression: Event; onDidSelectFunctionBreakpoint: Event; diff --git a/src/vs/workbench/parts/debug/common/debugViewModel.ts b/src/vs/workbench/parts/debug/common/debugViewModel.ts index 1db0ec4beadc02d0a01ee790b8bef06de98a4a8c..fa0a2ac2afaa1016323d35d1702ebd51b4043fb6 100644 --- a/src/vs/workbench/parts/debug/common/debugViewModel.ts +++ b/src/vs/workbench/parts/debug/common/debugViewModel.ts @@ -12,6 +12,7 @@ export class ViewModel implements debug.IViewModel { private _focusedProcess: debug.IProcess; private selectedExpression: debug.IExpression; private selectedFunctionBreakpoint: debug.IFunctionBreakpoint; + private _onDidFocusProcess: Emitter; private _onDidFocusStackFrame: Emitter; private _onDidSelectExpression: Emitter; private _onDidSelectFunctionBreakpoint: Emitter; @@ -20,6 +21,7 @@ export class ViewModel implements debug.IViewModel { public changedWorkbenchViewState: boolean; constructor(private _selectedConfigurationName: string) { + this._onDidFocusProcess = new Emitter(); this._onDidFocusStackFrame = new Emitter(); this._onDidSelectExpression = new Emitter(); this._onDidSelectFunctionBreakpoint = new Emitter(); @@ -46,10 +48,17 @@ export class ViewModel implements debug.IViewModel { public setFocusedStackFrame(stackFrame: debug.IStackFrame, process: debug.IProcess): void { this._focusedStackFrame = stackFrame; - this._focusedProcess = process; + if (process !== this._focusedProcess) { + this._focusedProcess = process; + this._onDidFocusProcess.fire(process); + } this._onDidFocusStackFrame.fire(stackFrame); } + public get onDidFocusProcess(): Event { + return this._onDidFocusProcess.event; + } + public get onDidFocusStackFrame(): Event { return this._onDidFocusStackFrame.event; }