|
1 | 1 | import * as vscode from 'vscode';
|
2 | 2 | import * as lc from 'vscode-languageclient';
|
3 | 3 | import * as ra from './lsp_ext';
|
| 4 | +import * as path from 'path'; |
4 | 5 |
|
5 | 6 | import { Ctx, Cmd } from './ctx';
|
6 | 7 | import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
@@ -474,28 +475,47 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd {
|
474 | 475 | return async () => {
|
475 | 476 | const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two, {
|
476 | 477 | enableScripts: true,
|
477 |
| - retainContextWhenHidden: true |
478 |
| - }); |
| 478 | + retainContextWhenHidden: true, |
| 479 | + localResourceRoots: [vscode.Uri.joinPath(vscode.Uri.parse(ctx.extensionPath), "node_modules")] |
| 480 | + }); |
479 | 481 | const params = {
|
480 | 482 | full: full,
|
481 | 483 | };
|
482 | 484 | const dot = await ctx.client.sendRequest(ra.viewCrateGraph, params);
|
483 | 485 |
|
484 | 486 | console.log(dot);
|
485 | 487 |
|
| 488 | + let script_d3 = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', 'd3', 'dist', 'd3.min.js')); |
| 489 | + let script_d3_gv = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', 'd3-graphviz', 'build', 'd3-graphviz.min.js')); |
| 490 | + let script_wasm = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', '@hpcc-js', 'wasm', 'dist', 'index.min.js')); |
| 491 | + |
| 492 | + console.log(script_d3, script_d3_gv, script_wasm); |
| 493 | + |
486 | 494 | const html = `
|
487 | 495 | <!DOCTYPE html>
|
488 | 496 | <meta charset="utf-8">
|
489 |
| -
|
| 497 | + <head> |
| 498 | + <style> |
| 499 | + body { |
| 500 | + padding: 0px |
| 501 | + } |
| 502 | + ::-webkit-scrollbar { |
| 503 | + display: none; |
| 504 | + } |
| 505 | + </style> |
| 506 | + </head> |
490 | 507 | <body>
|
491 |
| - <script src="https://d3js.org/d3.v5.min.js"></script> |
492 |
| - <script src="https://unpkg.com/@hpcc-js/[email protected]/dist/index.min.js"></script> |
493 |
| - <script src="https://unpkg.com/[email protected]/build/d3-graphviz.js"></script> |
494 |
| - <div id="graph" style="text-align: center;"></div> |
| 508 | + <script src="${panel.webview.asWebviewUri(script_d3)}"></script> |
| 509 | + <script src="${panel.webview.asWebviewUri(script_wasm)}"></script> |
| 510 | + <script src="${panel.webview.asWebviewUri(script_d3_gv)}"></script> |
| 511 | + <div id="graph"></div> |
495 | 512 | <script>
|
496 |
| - let margin = 0; |
497 |
| - d3.select("#graph").graphviz().fit(true).width(window.innerWidth - margin).height(window.innerHeight - margin) |
498 |
| - .renderDot(\`${dot}\`); |
| 513 | + d3.select("#graph") |
| 514 | + .graphviz() |
| 515 | + .fit(true) |
| 516 | + .width(window.innerWidth) |
| 517 | + .height(window.innerHeight) |
| 518 | + .renderDot(\`${dot}\`); |
499 | 519 | </script>
|
500 | 520 | </body>
|
501 | 521 | `;
|
|
0 commit comments