Skip to content

Commit 5bbf0f6

Browse files
Further simplification and dead code removal
1 parent c467fb5 commit 5bbf0f6

5 files changed

Lines changed: 13 additions & 37 deletions

File tree

src/programflow-visualization/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The self-contained UI component that the user interacts with:
1313

1414
### **Panel (frontend/)**
1515
The VS Code extension-side host that owns the webview:
16-
- **visualization_panel.ts**: Creates and manages the webview panel lifecycle. Receives `reset` and `append` messages from the trace backend, posts them to the webview. Handles `highlight` and `select` messages from the webview to update editor line highlighting.
16+
- **visualization_panel.ts**: Creates and manages the webview panel lifecycle. Receives `reset` and `append` messages from the trace backend, posts them to the webview. Handles `highlight` messages from the webview to update editor line highlighting.
1717

1818
## Message Flow
1919

@@ -40,7 +40,7 @@ graph TB
4040
panel -->|postMessage reset/append| webview
4141
4242
webview -->|custom events| adapter["vscode-host-adapter.ts"]
43-
adapter -->|postMessage highlight/select| panel
43+
adapter -->|postMessage highlight| panel
4444
panel -->|updateLineHighlight| editor
4545
4646
ui -->|local navigation| gen

src/programflow-visualization/frontend/visualization_panel.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class VisualizationPanel {
1717
private readonly _context: vscode.ExtensionContext;
1818
private readonly _outChannel: vscode.OutputChannel;
1919

20-
private readonly _filePath: string;
2120
private readonly _fileHash: string;
2221

2322
private readonly _tracePort: MessagePort | null;
@@ -39,7 +38,6 @@ export class VisualizationPanel {
3938
) {
4039
this._context = context;
4140
this._outChannel = outChannel;
42-
this._filePath = filePath;
4341
this._fileHash = fileHash;
4442
this._tracePort = tracePort;
4543

@@ -88,18 +86,9 @@ export class VisualizationPanel {
8886

8987
this._panel.webview.onDidReceiveMessage(
9088
async (msg) => {
91-
switch (msg?.command) {
92-
case "highlight":
93-
if (typeof msg.filePath === "string" && typeof msg.line === "number") {
94-
await this.updateLineHighlight(false, msg.filePath, msg.line);
95-
}
96-
break;
97-
case "select":
98-
if (typeof msg.filePath === "string" && typeof msg.line === "number") {
99-
await this.updateLineHighlight(false, msg.filePath, msg.line);
100-
}
101-
break;
102-
}
89+
if (msg?.command !== "highlight") {return;}
90+
if (typeof msg.filePath !== "string" || typeof msg.line !== "number") {return;}
91+
await this.updateLineHighlight(false, msg.filePath, msg.line);
10392
},
10493
undefined,
10594
context.subscriptions
@@ -189,7 +178,6 @@ export class VisualizationPanel {
189178
command: "append",
190179
elem,
191180
complete: this._backendTrace.complete,
192-
len: this._backendTrace.trace.length,
193181
});
194182
}
195183

src/programflow-visualization/web/html-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ export class HTMLGenerator {
185185

186186
private frameItem(index: number, stackElem: StackElem): string {
187187
return `
188-
<div class="column frame-item" id="frameItem?">
189-
<div class="row subtitle" id="frameItemTitle">
188+
<div class="column frame-item">
189+
<div class="row subtitle">
190190
${stackElem.frameName === '<module>' ? 'Global' : escapeHTML(stackElem.frameName)}
191191
</div>
192-
<div class="column ${index === 0 ? 'current-frame' : 'frame'}" id="frameItemSubItems">
192+
<div class="column ${index === 0 ? 'current-frame' : 'frame'}">
193193
${stackElem.locals.map(namedValue => this.frameSubItem(stackElem.frameName, namedValue)).join('')}
194194
</div>
195195
</div>

src/programflow-visualization/web/vscode-host-adapter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Bridge messages between the VS Code host API and webview custom events
22
declare const acquireVsCodeApi: undefined | (() => { postMessage: (msg: any) => void });
33

4+
type HighlightMsg = { command: "highlight"; filePath: string; line: number };
5+
46
const vscode = typeof acquireVsCodeApi === "function"
57
? acquireVsCodeApi()
68
: { postMessage: (_: any) => {} };
@@ -19,12 +21,8 @@ window.addEventListener("message", (event: MessageEvent) => {
1921
}
2022
});
2123

22-
window.addEventListener("programflow:select", (e: Event) => {
23-
const ce = e as CustomEvent<any>;
24-
vscode.postMessage({ command: "select", ...ce.detail });
25-
});
26-
2724
window.addEventListener("programflow:highlight", (e: Event) => {
2825
const ce = e as CustomEvent<{ filePath: string; line: number }>;
29-
vscode.postMessage({ command: "highlight", ...ce.detail });
26+
const msg: HighlightMsg = { command: "highlight", ...ce.detail };
27+
vscode.postMessage(msg);
3028
});

src/programflow-visualization/web/webview.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ import { HTMLGenerator } from "./html-generator";
33
import LinkerLine from "linkerline";
44
import type { BackendTraceElem, FrontendTraceElem } from "../types";
55

6-
// only used to add seperate Browser navigation if not in vscode
7-
const isVscode = typeof (window as any).acquireVsCodeApi === "function";
8-
96
type ResetMsg = {
107
command: "reset";
118
trace: BackendTraceElem[];
129
complete: boolean;
13-
index?: number;
1410
};
1511

1612
type AppendMsg = {
1713
command: "append";
1814
elem: BackendTraceElem;
1915
complete: boolean;
20-
index?: number;
21-
len?: number;
2216
};
2317

2418
// Optional example trace format (designer mode)
@@ -83,7 +77,7 @@ function renderCurrent() {
8377
}
8478

8579
function postCurrentHighlight() {
86-
if (!isVscode || trace.length === 0) {
80+
if (trace.length === 0) {
8781
return;
8882
}
8983
window.dispatchEvent(new CustomEvent("programflow:highlight", {
@@ -245,15 +239,13 @@ window.addEventListener("programflow:reset", (e: Event) => {
245239
const msg = (e as CustomEvent<ResetMsg>).detail;
246240
trace = msg.trace ?? [];
247241
traceComplete = !!msg.complete;
248-
traceIndex = Number(msg.index ?? traceIndex);
249242
renderCurrent();
250243
});
251244

252245
window.addEventListener("programflow:append", (e: Event) => {
253246
const msg = (e as CustomEvent<AppendMsg>).detail;
254247
trace.push(msg.elem);
255248
traceComplete = !!msg.complete;
256-
traceIndex = Number(msg.index ?? traceIndex);
257249
renderCurrent();
258250
});
259251

@@ -288,8 +280,6 @@ function setupUi() {
288280
// Optional: example trace mode
289281
const anyWin = window as any;
290282
const staticTrace: StaticTrace | undefined = anyWin.__PROGRAMFLOW_TRACE__;
291-
292-
console.log("static trace mode:", !!staticTrace?.trace, staticTrace?.trace?.length);
293283

294284
if (staticTrace?.trace) {
295285
trace = staticTrace.trace;

0 commit comments

Comments
 (0)