mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-20 03:49:51 +00:00
Use local node_modules to allow the graph to load offline
- Fix some warnings
This commit is contained in:
parent
f4f68e62c2
commit
8a563e4a46
3 changed files with 36 additions and 12 deletions
|
|
@ -3,8 +3,8 @@
|
||||||
//! `ide` crate.
|
//! `ide` crate.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{Read, Write as _},
|
io::{Write as _},
|
||||||
process::{self, Command, Stdio},
|
process::{self, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ide::{
|
use ide::{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
import * as ra from './lsp_ext';
|
import * as ra from './lsp_ext';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
import { Ctx, Cmd } from './ctx';
|
import { Ctx, Cmd } from './ctx';
|
||||||
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
||||||
|
|
@ -474,8 +475,9 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd {
|
||||||
return async () => {
|
return async () => {
|
||||||
const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two, {
|
const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two, {
|
||||||
enableScripts: true,
|
enableScripts: true,
|
||||||
retainContextWhenHidden: true
|
retainContextWhenHidden: true,
|
||||||
});
|
localResourceRoots: [vscode.Uri.joinPath(vscode.Uri.parse(ctx.extensionPath), "node_modules")]
|
||||||
|
});
|
||||||
const params = {
|
const params = {
|
||||||
full: full,
|
full: full,
|
||||||
};
|
};
|
||||||
|
|
@ -483,19 +485,37 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd {
|
||||||
|
|
||||||
console.log(dot);
|
console.log(dot);
|
||||||
|
|
||||||
|
let script_d3 = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', 'd3', 'dist', 'd3.min.js'));
|
||||||
|
let script_d3_gv = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', 'd3-graphviz', 'build', 'd3-graphviz.min.js'));
|
||||||
|
let script_wasm = vscode.Uri.file(path.join(ctx.extensionPath, 'node_modules', '@hpcc-js', 'wasm', 'dist', 'index.min.js'));
|
||||||
|
|
||||||
|
console.log(script_d3, script_d3_gv, script_wasm);
|
||||||
|
|
||||||
const html = `
|
const html = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
padding: 0px
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="https://d3js.org/d3.v5.min.js"></script>
|
<script src="${panel.webview.asWebviewUri(script_d3)}"></script>
|
||||||
<script src="https://unpkg.com/@hpcc-js/wasm@0.3.11/dist/index.min.js"></script>
|
<script src="${panel.webview.asWebviewUri(script_wasm)}"></script>
|
||||||
<script src="https://unpkg.com/d3-graphviz@3.0.5/build/d3-graphviz.js"></script>
|
<script src="${panel.webview.asWebviewUri(script_d3_gv)}"></script>
|
||||||
<div id="graph" style="text-align: center;"></div>
|
<div id="graph"></div>
|
||||||
<script>
|
<script>
|
||||||
let margin = 0;
|
d3.select("#graph")
|
||||||
d3.select("#graph").graphviz().fit(true).width(window.innerWidth - margin).height(window.innerHeight - margin)
|
.graphviz()
|
||||||
.renderDot(\`${dot}\`);
|
.fit(true)
|
||||||
|
.width(window.innerWidth)
|
||||||
|
.height(window.innerHeight)
|
||||||
|
.renderDot(\`${dot}\`);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
`;
|
`;
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,10 @@ export class Ctx {
|
||||||
this.pushCleanup(d);
|
this.pushCleanup(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get extensionPath(): string {
|
||||||
|
return this.extCtx.extensionPath;
|
||||||
|
}
|
||||||
|
|
||||||
get globalState(): vscode.Memento {
|
get globalState(): vscode.Memento {
|
||||||
return this.extCtx.globalState;
|
return this.extCtx.globalState;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue