Skip to content

Commit 5cbe2b9

Browse files
authored
debug: tighten down debugFocus API proposal (#207006)
* debug: tighten down debugFocus API proposal Some bug fixes and reworking to align better with our APIs * fix getter error
1 parent 25f1b18 commit 5cbe2b9

6 files changed

+72
-81
lines changed

src/vs/workbench/api/browser/mainThreadDebugService.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { convertToVSCPaths, convertToDAPaths, isSessionAttach } from 'vs/workben
1818
import { ErrorNoTelemetry } from 'vs/base/common/errors';
1919
import { IDebugVisualizerService } from 'vs/workbench/contrib/debug/common/debugVisualizers';
2020
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
21+
import { Event } from 'vs/base/common/event';
2122

2223
@extHostNamedCustomer(MainContext.MainThreadDebugService)
2324
export class MainThreadDebugService implements MainThreadDebugServiceShape, IDebugAdapterFactory {
@@ -88,28 +89,28 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
8889
this._debugAdapterDescriptorFactories = new Map();
8990
this._extHostKnownSessions = new Set();
9091

91-
this._toDispose.add(this.debugService.getViewModel().onDidFocusThread(({ thread, explicit, session }) => {
92-
if (session) {
93-
const dto: IThreadFocusDto = {
92+
const viewModel = this.debugService.getViewModel();
93+
this._toDispose.add(Event.any(viewModel.onDidFocusStackFrame, viewModel.onDidFocusThread)(() => {
94+
const stackFrame = viewModel.focusedStackFrame;
95+
const thread = viewModel.focusedThread;
96+
if (stackFrame) {
97+
this._proxy.$acceptStackFrameFocus({
98+
kind: 'stackFrame',
99+
threadId: stackFrame.thread.threadId,
100+
frameId: stackFrame.frameId,
101+
sessionId: stackFrame.thread.session.getId(),
102+
} satisfies IStackFrameFocusDto);
103+
} else if (thread) {
104+
this._proxy.$acceptStackFrameFocus({
94105
kind: 'thread',
95-
threadId: thread?.threadId,
96-
sessionId: session.getId(),
97-
};
98-
this._proxy.$acceptStackFrameFocus(dto);
106+
threadId: thread.threadId,
107+
sessionId: thread.session.getId(),
108+
} satisfies IThreadFocusDto);
109+
} else {
110+
this._proxy.$acceptStackFrameFocus(undefined);
99111
}
100112
}));
101113

102-
this._toDispose.add(this.debugService.getViewModel().onDidFocusStackFrame(({ stackFrame, explicit, session }) => {
103-
if (session) {
104-
const dto: IStackFrameFocusDto = {
105-
kind: 'stackFrame',
106-
threadId: stackFrame?.thread.threadId,
107-
frameId: stackFrame?.frameId,
108-
sessionId: session.getId(),
109-
};
110-
this._proxy.$acceptStackFrameFocus(dto);
111-
}
112-
}));
113114
this.sendBreakpointsAndListen();
114115
}
115116

src/vs/workbench/api/common/extHost.api.impl.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,11 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
12411241
get breakpoints() {
12421242
return extHostDebugService.breakpoints;
12431243
},
1244-
get stackFrameFocus() {
1245-
return extHostDebugService.stackFrameFocus;
1244+
get activeStackItem() {
1245+
if (!isProposedApiEnabled(extension, 'debugFocus')) {
1246+
return undefined;
1247+
}
1248+
return extHostDebugService.activeStackItem;
12461249
},
12471250
registerDebugVisualizationProvider(id, provider) {
12481251
checkProposedApiEnabled(extension, 'debugVisualization');
@@ -1267,9 +1270,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
12671270
onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
12681271
return _asExtensionEvent(extHostDebugService.onDidChangeBreakpoints)(listener, thisArgs, disposables);
12691272
},
1270-
onDidChangeStackFrameFocus(listener, thisArg?, disposables?) {
1273+
onDidChangeActiveStackItem(listener, thisArg?, disposables?) {
12711274
checkProposedApiEnabled(extension, 'debugFocus');
1272-
return _asExtensionEvent(extHostDebugService.onDidChangeStackFrameFocus)(listener, thisArg, disposables);
1275+
return _asExtensionEvent(extHostDebugService.onDidChangeActiveStackItem)(listener, thisArg, disposables);
12731276
},
12741277
registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider, triggerKind?: vscode.DebugConfigurationProviderTriggerKind) {
12751278
return extHostDebugService.registerDebugConfigurationProvider(debugType, provider, triggerKind || DebugConfigurationProviderTriggerKind.Initial);
@@ -1673,8 +1676,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
16731676
InteractiveSessionVoteDirection: extHostTypes.InteractiveSessionVoteDirection,
16741677
ChatCopyKind: extHostTypes.ChatCopyKind,
16751678
InteractiveEditorResponseFeedbackKind: extHostTypes.InteractiveEditorResponseFeedbackKind,
1676-
StackFrameFocus: extHostTypes.StackFrameFocus,
1677-
ThreadFocus: extHostTypes.ThreadFocus,
1679+
StackFrame: extHostTypes.StackFrame,
1680+
Thread: extHostTypes.Thread,
16781681
RelatedInformationType: extHostTypes.RelatedInformationType,
16791682
SpeechToTextStatus: extHostTypes.SpeechToTextStatus,
16801683
PartialAcceptTriggerKind: extHostTypes.PartialAcceptTriggerKind,

src/vs/workbench/api/common/extHost.protocol.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2342,14 +2342,14 @@ export type IDebugSessionDto = IDebugSessionFullDto | DebugSessionUUID;
23422342
export interface IThreadFocusDto {
23432343
kind: 'thread';
23442344
sessionId: string;
2345-
threadId: number | undefined;
2345+
threadId: number;
23462346
}
23472347

23482348
export interface IStackFrameFocusDto {
23492349
kind: 'stackFrame';
23502350
sessionId: string;
2351-
threadId: number | undefined;
2352-
frameId: number | undefined;
2351+
threadId: number;
2352+
frameId: number;
23532353
}
23542354

23552355

src/vs/workbench/api/common/extHostDebugService.ts

+21-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DebugSessionUUID, ExtHostDebugServiceShape, IBreakpointsDeltaDto, IThre
1515
import { IExtHostEditorTabs } from 'vs/workbench/api/common/extHostEditorTabs';
1616
import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
1717
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
18-
import { Breakpoint, DataBreakpoint, DebugAdapterExecutable, DebugAdapterInlineImplementation, DebugAdapterNamedPipeServer, DebugAdapterServer, DebugConsoleMode, Disposable, FunctionBreakpoint, Location, Position, setBreakpointId, SourceBreakpoint, ThreadFocus, StackFrameFocus, ThemeIcon } from 'vs/workbench/api/common/extHostTypes';
18+
import { Breakpoint, DataBreakpoint, DebugAdapterExecutable, DebugAdapterInlineImplementation, DebugAdapterNamedPipeServer, DebugAdapterServer, DebugConsoleMode, Disposable, FunctionBreakpoint, Location, Position, setBreakpointId, SourceBreakpoint, Thread, StackFrame, ThemeIcon } from 'vs/workbench/api/common/extHostTypes';
1919
import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
2020
import { AbstractDebugAdapter } from 'vs/workbench/contrib/debug/common/abstractDebugAdapter';
2121
import { MainThreadDebugVisualization, IAdapterDescriptor, IConfig, IDebugAdapter, IDebugAdapterExecutable, IDebugAdapterNamedPipeServer, IDebugAdapterServer, IDebugVisualization, IDebugVisualizationContext, IDebuggerContribution, DebugVisualizationType, IDebugVisualizationTreeItem } from 'vs/workbench/contrib/debug/common/debug';
@@ -44,8 +44,8 @@ export interface IExtHostDebugService extends ExtHostDebugServiceShape {
4444
onDidReceiveDebugSessionCustomEvent: Event<vscode.DebugSessionCustomEvent>;
4545
onDidChangeBreakpoints: Event<vscode.BreakpointsChangeEvent>;
4646
breakpoints: vscode.Breakpoint[];
47-
onDidChangeStackFrameFocus: Event<vscode.ThreadFocus | vscode.StackFrameFocus | undefined>;
48-
stackFrameFocus: vscode.ThreadFocus | vscode.StackFrameFocus | undefined;
47+
onDidChangeActiveStackItem: Event<vscode.Thread | vscode.StackFrame | undefined>;
48+
activeStackItem: vscode.Thread | vscode.StackFrame | undefined;
4949

5050
addBreakpoints(breakpoints0: readonly vscode.Breakpoint[]): Promise<void>;
5151
removeBreakpoints(breakpoints0: readonly vscode.Breakpoint[]): Promise<void>;
@@ -97,8 +97,8 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
9797

9898
private readonly _onDidChangeBreakpoints: Emitter<vscode.BreakpointsChangeEvent>;
9999

100-
private _stackFrameFocus: vscode.ThreadFocus | vscode.StackFrameFocus | undefined;
101-
private readonly _onDidChangeStackFrameFocus: Emitter<vscode.ThreadFocus | vscode.StackFrameFocus | undefined>;
100+
private _activeStackItem: vscode.Thread | vscode.StackFrame | undefined;
101+
private readonly _onDidChangeActiveStackItem: Emitter<vscode.Thread | vscode.StackFrame | undefined>;
102102

103103
private _debugAdapters: Map<number, IDebugAdapter>;
104104
private _debugAdaptersTrackers: Map<number, vscode.DebugAdapterTracker>;
@@ -144,7 +144,7 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
144144

145145
this._onDidChangeBreakpoints = new Emitter<vscode.BreakpointsChangeEvent>();
146146

147-
this._onDidChangeStackFrameFocus = new Emitter<vscode.ThreadFocus | vscode.StackFrameFocus | undefined>();
147+
this._onDidChangeActiveStackItem = new Emitter<vscode.Thread | vscode.StackFrame | undefined>();
148148

149149
this._activeDebugConsole = new ExtHostDebugConsole(this._debugServiceProxy);
150150

@@ -278,12 +278,12 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
278278
// extension debug API
279279

280280

281-
get stackFrameFocus(): vscode.ThreadFocus | vscode.StackFrameFocus | undefined {
282-
return this._stackFrameFocus;
281+
get activeStackItem(): vscode.Thread | vscode.StackFrame | undefined {
282+
return this._activeStackItem;
283283
}
284284

285-
get onDidChangeStackFrameFocus(): Event<vscode.ThreadFocus | vscode.StackFrameFocus | undefined> {
286-
return this._onDidChangeStackFrameFocus.event;
285+
get onDidChangeActiveStackItem(): Event<vscode.Thread | vscode.StackFrame | undefined> {
286+
return this._onDidChangeActiveStackItem.event;
287287
}
288288

289289
get onDidChangeBreakpoints(): Event<vscode.BreakpointsChangeEvent> {
@@ -768,21 +768,19 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
768768
this.fireBreakpointChanges(a, r, c);
769769
}
770770

771-
public async $acceptStackFrameFocus(focusDto: IThreadFocusDto | IStackFrameFocusDto): Promise<void> {
772-
let focus: ThreadFocus | StackFrameFocus;
773-
const session = focusDto.sessionId ? await this.getSession(focusDto.sessionId) : undefined;
774-
if (!session) {
775-
throw new Error('no DebugSession found for debug focus context');
776-
}
777-
778-
if (focusDto.kind === 'thread') {
779-
focus = new ThreadFocus(session.api, focusDto.threadId);
780-
} else {
781-
focus = new StackFrameFocus(session.api, focusDto.threadId, focusDto.frameId);
771+
public async $acceptStackFrameFocus(focusDto: IThreadFocusDto | IStackFrameFocusDto | undefined): Promise<void> {
772+
let focus: vscode.Thread | vscode.StackFrame | undefined;
773+
if (focusDto) {
774+
const session = await this.getSession(focusDto.sessionId);
775+
if (focusDto.kind === 'thread') {
776+
focus = new Thread(session.api, focusDto.threadId);
777+
} else {
778+
focus = new StackFrame(session.api, focusDto.threadId, focusDto.frameId);
779+
}
782780
}
783781

784-
this._stackFrameFocus = <vscode.ThreadFocus | vscode.StackFrameFocus>focus;
785-
this._onDidChangeStackFrameFocus.fire(this._stackFrameFocus);
782+
this._activeStackItem = focus;
783+
this._onDidChangeActiveStackItem.fire(this._activeStackItem);
786784
}
787785

788786
public $provideDebugConfigurations(configProviderHandle: number, folderUri: UriComponents | undefined, token: CancellationToken): Promise<vscode.DebugConfiguration[]> {

src/vs/workbench/api/common/extHostTypes.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -3035,23 +3035,20 @@ export class DebugAdapterInlineImplementation implements vscode.DebugAdapterInli
30353035
}
30363036

30373037

3038-
@es5ClassCompat
3039-
export class StackFrameFocus {
3038+
export class StackFrame implements vscode.StackFrame {
30403039
constructor(
30413040
public readonly session: vscode.DebugSession,
3042-
readonly threadId?: number,
3043-
readonly frameId?: number) { }
3041+
readonly threadId: number,
3042+
readonly frameId: number) { }
30443043
}
30453044

3046-
@es5ClassCompat
3047-
export class ThreadFocus {
3045+
export class Thread implements vscode.Thread {
30483046
constructor(
30493047
public readonly session: vscode.DebugSession,
3050-
readonly threadId?: number) { }
3048+
readonly threadId: number) { }
30513049
}
30523050

30533051

3054-
30553052
@es5ClassCompat
30563053
export class EvaluatableExpression implements vscode.EvaluatableExpression {
30573054
readonly range: vscode.Range;

src/vscode-dts/vscode.proposed.debugFocus.d.ts

+15-23
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,60 @@ declare module 'vscode' {
77

88
// See https://github.com/microsoft/vscode/issues/63943
99

10-
export class ThreadFocus {
10+
export class Thread {
1111
/**
1212
* Create a ThreadFocus
1313
* @param session
1414
* @param threadId
15-
* @param frameId
1615
*/
17-
constructor(
18-
session: DebugSession,
19-
threadId?: number);
20-
16+
constructor(session: DebugSession, threadId: number);
2117

2218
/**
2319
* Debug session for thread.
2420
*/
2521
readonly session: DebugSession;
2622

2723
/**
28-
* Id of the associated thread (DAP id). May be undefined if thread has become unselected.
24+
* ID of the associated thread in the debug protocol.
2925
*/
30-
readonly threadId: number | undefined;
26+
readonly threadId: number;
3127
}
3228

33-
export class StackFrameFocus {
29+
export class StackFrame {
3430
/**
3531
* Create a StackFrameFocus
3632
* @param session
3733
* @param threadId
3834
* @param frameId
3935
*/
40-
constructor(
41-
session: DebugSession,
42-
threadId?: number,
43-
frameId?: number);
44-
36+
constructor(session: DebugSession, threadId?: number, frameId?: number);
4537

4638
/**
4739
* Debug session for thread.
4840
*/
4941
readonly session: DebugSession;
5042

5143
/**
52-
* Id of the associated thread (DAP id). May be undefined if a frame is unselected.
44+
* Id of the associated thread in the debug protocol.
5345
*/
54-
readonly threadId: number | undefined;
46+
readonly threadId: number;
5547
/**
56-
* Id of the stack frame (DAP id). May be undefined if a frame is unselected.
48+
* Id of the stack frame in the debug protocol.
5749
*/
58-
readonly frameId: number | undefined;
50+
readonly frameId: number;
5951
}
6052

6153

6254
export namespace debug {
6355
/**
64-
* The currently focused thread or stack frame id, or `undefined` if this has not been set. (e.g. not in debug mode).
56+
* The currently focused thread or stack frame, or `undefined` if no
57+
* thread or stack is focused.
6558
*/
66-
export let stackFrameFocus: ThreadFocus | StackFrameFocus | undefined;
59+
export const activeStackItem: Thread | StackFrame | undefined;
6760

6861
/**
69-
* An {@link Event} which fires when the {@link debug.stackFrameFocus} changes. Provides a sessionId. threadId is not undefined
70-
* when a thread of frame has gained focus. frameId is defined when a stackFrame has gained focus.
62+
* An event which fires when the {@link debug.activeStackItem} has changed.
7163
*/
72-
export const onDidChangeStackFrameFocus: Event<ThreadFocus | StackFrameFocus | undefined>;
64+
export const onDidChangeActiveStackItem: Event<Thread | StackFrame | undefined>;
7365
}
7466
}

0 commit comments

Comments
 (0)