提交 5eb21eaa 编写于 作者: A Andre Weinand

Debug API for tracking current debug session; fixes #30157

上级 78b912ee
......@@ -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<DebugSession | undefined>;
}
}
......@@ -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(<DebugSessionUUID>proc.getId(), proc.configuration.type, proc.name)));
this._toDispose.push(debugService.getViewModel().onDidFocusProcess(proc => {
if (proc) {
this._proxy.$acceptDebugSessionActiveChanged(<DebugSessionUUID>proc.getId(), proc.configuration.type, proc.name);
} else {
this._proxy.$acceptDebugSessionActiveChanged(undefined);
}
}));
}
public dispose(): void {
......
......@@ -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);
})
};
......
......@@ -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
......
......@@ -21,11 +21,18 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
private _onDidTerminateDebugSession: Emitter<vscode.DebugSession>;
get onDidTerminateDebugSession(): Event<vscode.DebugSession> { return this._onDidTerminateDebugSession.event; }
private _onDidChangeActiveDebugSession: Emitter<vscode.DebugSession | undefined>;
get onDidChangeActiveDebugSession(): Event<vscode.DebugSession | undefined> { 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<vscode.DebugSession>();
this._onDidChangeActiveDebugSession = new Emitter<vscode.DebugSession>();
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 {
......
......@@ -273,6 +273,7 @@ export interface IViewModel extends ITreeElement {
isMultiProcessView(): boolean;
onDidFocusProcess: Event<IProcess | undefined>;
onDidFocusStackFrame: Event<IStackFrame>;
onDidSelectExpression: Event<IExpression>;
onDidSelectFunctionBreakpoint: Event<IFunctionBreakpoint>;
......
......@@ -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<debug.IProcess | undefined>;
private _onDidFocusStackFrame: Emitter<debug.IStackFrame>;
private _onDidSelectExpression: Emitter<debug.IExpression>;
private _onDidSelectFunctionBreakpoint: Emitter<debug.IFunctionBreakpoint>;
......@@ -20,6 +21,7 @@ export class ViewModel implements debug.IViewModel {
public changedWorkbenchViewState: boolean;
constructor(private _selectedConfigurationName: string) {
this._onDidFocusProcess = new Emitter<debug.IProcess | undefined>();
this._onDidFocusStackFrame = new Emitter<debug.IStackFrame>();
this._onDidSelectExpression = new Emitter<debug.IExpression>();
this._onDidSelectFunctionBreakpoint = new Emitter<debug.IFunctionBreakpoint>();
......@@ -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<debug.IProcess> {
return this._onDidFocusProcess.event;
}
public get onDidFocusStackFrame(): Event<debug.IStackFrame> {
return this._onDidFocusStackFrame.event;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册