From 5eb21eaa8a7b77a24c8b36dc6afc8b2a90bdea4a Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Thu, 6 Jul 2017 00:26:17 +0200 Subject: [PATCH] Debug API for tracking current debug session; fixes #30157 --- src/vs/vscode.proposed.d.ts | 18 +++++++++++++++++ .../mainThreadDebugService.ts | 8 ++++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 9 ++++++++- src/vs/workbench/api/node/extHost.protocol.ts | 1 + .../workbench/api/node/extHostDebugService.ts | 20 +++++++++++++++++++ src/vs/workbench/parts/debug/common/debug.ts | 1 + .../parts/debug/common/debugViewModel.ts | 11 +++++++++- 7 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 6b3227a6cff..8430b05ab96 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 dc3186f738d..a4677049542 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 56c79673a9b..2155bc87c32 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 31a81ca1809..99db9aa1563 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 3b1a496cd6f..5a16373fe23 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 ebba65013cb..182aa4a25fc 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 1db0ec4bead..fa0a2ac2afa 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; } -- GitLab