@@ -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