feat(vscode): inject workspace context into chat, add latex math rend… · modelscript/modelscript@20ab6ad · GitHub
Skip to content

Commit 20ab6ad

Browse files
committed
feat(vscode): inject workspace context into chat, add latex math rendering, listClasses lsp endpoint
1 parent e5ae5e8 commit 20ab6ad

3 files changed

Lines changed: 195 additions & 30 deletions

File tree

‎packages/lsp/src/browserServerMain.ts‎

Lines changed: 27 additions & 0 deletions

‎packages/vscode/src/chatPanel.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,25 @@ export class ChatPanel {
4949
case "getActiveFileContext":
5050
this.sendActiveFileContext();
5151
break;
52+
case "listClasses":
53+
await this.handleListClasses(msg);
54+
break;
5255
}
5356
},
5457
null,
5558
this.disposables,
5659
);
5760

61+
// Auto-send active file context when panel opens
62+
this.sendActiveFileContext();
63+
64+
// Re-send active file context when user switches editors
65+
this.disposables.push(
66+
vscode.window.onDidChangeActiveTextEditor(() => {
67+
this.sendActiveFileContext();
68+
}),
69+
);
70+
5871
this.panel.onDidDispose(() => this.dispose(), null, this.disposables);
5972
}
6073

@@ -87,8 +100,28 @@ export class ChatPanel {
87100
}
88101
}
89102

103+
private async handleListClasses(msg: { id: string }) {
104+
try {
105+
const result = (await this.client.sendRequest("modelscript/listClasses")) as {
106+
classes: { name: string; kind: string; uri: string }[];
107+
};
108+
this.panel.webview.postMessage({ type: "classListResult", id: msg.id, result });
109+
} catch (e) {
110+
this.panel.webview.postMessage({
111+
type: "classListResult",
112+
id: msg.id,
113+
result: { classes: [], error: e instanceof Error ? e.message : String(e) },
114+
});
115+
}
116+
}
117+
90118
private sendActiveFileContext() {
91-
const editor = vscode.window.activeTextEditor;
119+
// activeTextEditor is undefined when the webview panel has focus,
120+
// so fall back to visibleTextEditors to find any open Modelica file.
121+
let editor = vscode.window.activeTextEditor;
122+
if (!editor || editor.document.languageId !== "modelica") {
123+
editor = vscode.window.visibleTextEditors.find((e) => e.document.languageId === "modelica");
124+
}
92125
if (editor && editor.document.languageId === "modelica") {
93126
this.panel.webview.postMessage({
94127
type: "activeFileContext",
@@ -251,6 +284,25 @@ export class ChatPanel {
251284
40% { opacity: 1; }
252285
}
253286
287+
/* Math rendering */
288+
.math-inline {
289+
font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', serif;
290+
font-style: italic;
291+
padding: 0 2px;
292+
color: var(--vscode-editor-foreground, #d4d4d4);
293+
}
294+
.math-block {
295+
font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', serif;
296+
font-style: italic;
297+
display: block;
298+
text-align: center;
299+
padding: 6px 8px;
300+
margin: 4px 0;
301+
background: var(--vscode-textCodeBlock-background, #1a1a1a);
302+
border-radius: 4px;
303+
color: var(--vscode-editor-foreground, #d4d4d4);
304+
}
305+
254306
/* Input area */
255307
#input-area {
256308
display: flex;

‎packages/vscode/src/webview/chatWebview.ts‎

Lines changed: 115 additions & 29 deletions

0 commit comments

Comments
 (0)