@@ -21,7 +21,7 @@ import type { LanguageClient } from "vscode-languageclient/node";
21
21
import { LINKED_COMMANDS } from "./client" ;
22
22
import type { DependencyId } from "./dependencies_provider" ;
23
23
import { unwrapUndefinable } from "./undefinable" ;
24
- import { getWebViewModulePath } from "./uri" ;
24
+ import { getNodeModulePath , getWebViewModulePath } from "./uri" ;
25
25
26
26
export * from "./ast_inspector" ;
27
27
export * from "./run" ;
@@ -737,7 +737,8 @@ export function viewItemTree(ctx: CtxInit): Cmd {
737
737
738
738
function crateGraph ( ctx : CtxInit , full : boolean ) : Cmd {
739
739
return async ( ) => {
740
- const nodeModulesPath = vscode . Uri . file ( path . join ( ctx . extensionPath , "node_modules" ) ) ;
740
+ const nodeModulesPath = getNodeModulePath ( ctx ) ;
741
+ const webviewModulePath = getWebViewModulePath ( ctx ) ;
741
742
742
743
const panel = vscode . window . createWebviewPanel (
743
744
"rust-analyzer.crate-graph" ,
@@ -746,55 +747,33 @@ function crateGraph(ctx: CtxInit, full: boolean): Cmd {
746
747
{
747
748
enableScripts : true ,
748
749
retainContextWhenHidden : true ,
749
- localResourceRoots : [ nodeModulesPath ] ,
750
+ localResourceRoots : [ nodeModulesPath , webviewModulePath ] ,
750
751
} ,
751
752
) ;
752
753
const params = {
753
754
full : full ,
754
755
} ;
755
756
const client = ctx . client ;
756
757
const dot = await client . sendRequest ( ra . viewCrateGraph , params ) ;
757
- const uri = panel . webview . asWebviewUri ( nodeModulesPath ) ;
758
+
759
+ const nodeModuleUri = panel . webview . asWebviewUri ( nodeModulesPath ) ;
760
+ const webviewModuleUri = panel . webview . asWebviewUri ( webviewModulePath ) ;
758
761
759
762
const html = `
760
763
<!DOCTYPE html>
761
764
<meta charset="utf-8">
762
765
<head>
763
- <style>
764
- /* Fill the entire view */
765
- html, body { margin:0; padding:0; overflow:hidden }
766
- svg { position:fixed; top:0; left:0; height:100%; width:100% }
767
-
768
- /* Disable the graphviz background and fill the polygons */
769
- .graph > polygon { display:none; }
770
- :is(.node,.edge) polygon { fill: white; }
771
-
772
- /* Invert the line colours for dark themes */
773
- body:not(.vscode-light) .edge path { stroke: white; }
774
- </style>
766
+ <link href="${ webviewModuleUri } /show_crate_graph.css" rel="stylesheet" media="screen"/>
775
767
</head>
776
768
<body>
777
- <script type="text/javascript" src="${ uri } /d3/dist/d3.min.js"></script>
778
- <script type="text/javascript" src="${ uri } /@hpcc-js/wasm/dist/graphviz.umd.js"></script>
779
- <script type="text/javascript" src="${ uri } /d3-graphviz/build/d3-graphviz.min.js"></script>
769
+ <script type="text/javascript" src="${ nodeModuleUri } /d3/dist/d3.min.js"></script>
770
+ <script type="text/javascript" src="${ nodeModuleUri } /@hpcc-js/wasm/dist/graphviz.umd.js"></script>
771
+ <script type="text/javascript" src="${ nodeModuleUri } /d3-graphviz/build/d3-graphviz.min.js"></script>
780
772
<div id="graph"></div>
781
- <script>
782
- let dot = \`${ dot } \`;
783
- let graph = d3.select("#graph")
784
- .graphviz({ useWorker: false, useSharedWorker: false })
785
- .fit(true)
786
- .zoomScaleExtent([0.1, Infinity])
787
- .renderDot(dot);
788
-
789
- d3.select(window).on("click", (event) => {
790
- if (event.ctrlKey) {
791
- graph.resetZoom(d3.transition().duration(100));
792
- }
793
- });
794
- d3.select(window).on("copy", (event) => {
795
- event.clipboardData.setData("text/plain", dot);
796
- event.preventDefault();
797
- });
773
+ <script type="module">
774
+ import { showCrateDependencyGraph } from '${ webviewModuleUri } /show_crate_graph.js';
775
+ const dot = ${ JSON . stringify ( dot ) } ;
776
+ showCrateDependencyGraph(dot);
798
777
</script>
799
778
</body>
800
779
` ;
0 commit comments