From 8a563e4a46a699aa0e77ed38f925b61d843a9d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Oliveira?= Date: Tue, 10 Aug 2021 13:35:37 +0000 Subject: [PATCH] Use local node_modules to allow the graph to load offline - Fix some warnings --- crates/rust-analyzer/src/handlers.rs | 4 +-- editors/code/src/commands.ts | 40 +++++++++++++++++++++------- editors/code/src/ctx.ts | 4 +++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index fd0e51ca7c7..e61572eb2b6 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -3,8 +3,8 @@ //! `ide` crate. use std::{ - io::{Read, Write as _}, - process::{self, Command, Stdio}, + io::{Write as _}, + process::{self, Stdio}, }; use ide::{ diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 6b69e5229b4..fd8fc32db48 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import * as ra from './lsp_ext'; +import * as path from 'path'; import { Ctx, Cmd } from './ctx'; import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; @@ -474,8 +475,9 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd { return async () => { const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two, { enableScripts: true, - retainContextWhenHidden: true - }); + retainContextWhenHidden: true, + localResourceRoots: [vscode.Uri.joinPath(vscode.Uri.parse(ctx.extensionPath), "node_modules")] + }); const params = { full: full, }; @@ -483,19 +485,37 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd { 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 = ` - + + + - - - -
+ + + +
`; diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 2ffd3be6f5c..666a4b6972b 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -68,6 +68,10 @@ export class Ctx { this.pushCleanup(d); } + get extensionPath(): string { + return this.extCtx.extensionPath; + } + get globalState(): vscode.Memento { return this.extCtx.globalState; }