Skip to content

Commit e3f41f6

Browse files
rentziassCopilot
andauthored
Patch stack frames with source for VS Code auto-focus
VS Code auto-selects the top stack frame after a 'stopped' event only if the frame has a 'source' reference — without one, VS Code shows the frame in the Call Stack panel but never selects it, so scopes/variables are never requested. The runner doesn't set source on stack frames yet (the ADR plans to add the workflow file as source later). Until then, inject a minimal synthetic source with sourceReference pointing back to the frame ID and presentationHint 'deemphasize' so VS Code auto-focuses the frame without trying to render a fake file prominently. This doesn't affect nvim-dap or other DAP clients that auto-select frames regardless of source. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9be2c73 commit e3f41f6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/debugger/webSocketDapAdapter.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ export class WebSocketDapAdapter implements vscode.DebugAdapter {
152152
return;
153153
}
154154

155+
// VS Code auto-focuses the top stack frame only if it has a source
156+
// reference. The runner doesn't set one yet (the ADR calls for adding
157+
// the workflow file later). Patch frames so VS Code auto-selects them.
158+
if (m.type === "response" && m.command === "stackTrace") {
159+
patchStackFrameSources(message);
160+
}
161+
155162
this._onDidSendMessage.fire(message);
156163

157164
// When the configurationDone response arrives from the runner,
@@ -220,3 +227,39 @@ function describeDapMessage(msg: vscode.DebugProtocolMessage): string {
220227
const detail = (m.command as string) ?? (m.event as string) ?? "";
221228
return detail ? `${type}:${detail}` : type;
222229
}
230+
231+
interface DapStackFrame {
232+
id: number;
233+
name: string;
234+
source?: {name?: string; path?: string; sourceReference?: number; presentationHint?: string};
235+
line: number;
236+
column: number;
237+
presentationHint?: string;
238+
}
239+
240+
/**
241+
* VS Code auto-focuses the top stack frame after a `stopped` event only when
242+
* that frame carries a `source` reference. The runner doesn't set one yet (the
243+
* ADR plans to add the workflow file as source later). Until then, we inject a
244+
* minimal synthetic source so VS Code's auto-focus works.
245+
*/
246+
function patchStackFrameSources(message: vscode.DebugProtocolMessage): void {
247+
const m = message as Record<string, unknown>;
248+
const body = m.body as {stackFrames?: DapStackFrame[]} | undefined;
249+
if (!body?.stackFrames) {
250+
return;
251+
}
252+
253+
for (const frame of body.stackFrames) {
254+
if (!frame.source) {
255+
frame.source = {
256+
name: frame.name,
257+
// A positive sourceReference tells VS Code to use the DAP `source`
258+
// request to fetch content. We reuse the frame id; the runner will
259+
// respond (or fail gracefully) when VS Code asks for it.
260+
sourceReference: frame.id,
261+
presentationHint: "deemphasize"
262+
};
263+
}
264+
}
265+
}

0 commit comments

Comments
 (0)