Skip to content

Commit f1f18a3

Browse files
authored
Merge pull request #208 from tmr232/visual-studio
Visual studio support
2 parents ca900e2 + e119dd1 commit f1f18a3

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ Additionally, the view will automatically pan to the highlighted node when it ch
6868
- [Python](https://tmr232.github.io/function-graph-overview/?language=python)
6969
- [TypesScript](https://tmr232.github.io/function-graph-overview/?language=typescript) & [TSX]((https://tmr232.github.io/function-graph-overview/?language=tsx))
7070
- [JavaScript](https://tmr232.github.io/function-graph-overview/?language=typescript) & [JSX]((https://tmr232.github.io/function-graph-overview/?language=tsx))
71+
- [C#](https://tmr232.github.io/function-graph-overview/?language=csharp)
72+
- [Java](https://tmr232.github.io/function-graph-overview/?language=java)

src/webview/src/App.svelte

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ declare global {
2727
setHighlight: (highlight: boolean) => void;
2828
};
2929
};
30+
VisualStudio?: {
31+
/**
32+
* Functions the VS extension can use to call into the WebView
33+
*/
34+
ToWebview?: {
35+
setColors: (
36+
colors: string,
37+
isDark: boolean,
38+
backgroundColor: string,
39+
foregroundColor: string,
40+
) => void;
41+
setCode: (code: string, offset: number, language: string) => void;
42+
setSimplify: (simplify: boolean) => void;
43+
setFlatSwitch: (flatSwitch: boolean) => void;
44+
setHighlight: (highlight: boolean) => void;
45+
};
46+
};
47+
chrome?: {
48+
webview?: {
49+
postMessage: (message: string) => void;
50+
};
51+
};
3052
}
3153
}
3254
</script>
@@ -195,9 +217,46 @@ declare global {
195217
});
196218
}
197219
220+
function initVisualStudio(stateHandler: StateHandler): void {
221+
function setColors(colors: string, isDark:boolean, backgroundColor:string, foregroundColor:string) {
222+
try {
223+
colorList = deserializeColorList(colors);
224+
document.body.style.backgroundColor = colorList.find(
225+
({ name }) => name === "graph.background",
226+
).hex;
227+
228+
document.documentElement.style.setProperty("--jetbrains-editor-background", backgroundColor);
229+
document.documentElement.style.setProperty("--jetbrains-editor-foreground", foregroundColor);
230+
document.documentElement.style.setProperty("--jetbrains-color-scheme", isDark?"dark":"light");
231+
} catch (error) {
232+
console.trace(error);
233+
return;
234+
}
235+
}
236+
237+
window.VisualStudio ??= {};
238+
window.VisualStudio.ToWebview = {
239+
setSimplify: (flag: boolean) =>
240+
stateHandler.update({ config: { simplify: flag } }),
241+
setFlatSwitch: (flag: boolean) =>
242+
stateHandler.update({ config: { flatSwitch: flag } }),
243+
setHighlight: (flag: boolean) =>
244+
stateHandler.update({ config: { highlight: flag } }),
245+
setCode,
246+
setColors,
247+
};
248+
249+
stateHandler.onNavigateTo((offset: number) => {
250+
window.chrome?.webview?.postMessage(
251+
JSON.stringify({ tag: "navigateTo", offset }),
252+
);
253+
});
254+
}
255+
198256
const stateHandler = new StateHandler();
199257
initVSCode(stateHandler);
200258
initJetBrains(stateHandler);
259+
initVisualStudio(stateHandler);
201260
202261
function navigateTo(
203262
e: CustomEvent<{ node: string; offset: number | null }>,

0 commit comments

Comments
 (0)