From a85a2c4d151d9d2e8fb016d76aad99a6ca88bc75 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 11 May 2021 16:15:31 +0200 Subject: Allow viewing the crate graph in a webview --- editors/code/package.json | 5 +++++ editors/code/src/commands.ts | 8 ++++++++ editors/code/src/lsp_ext.ts | 2 ++ editors/code/src/main.ts | 1 + 4 files changed, 16 insertions(+) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index f35d30898..0f38a1673 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -109,6 +109,11 @@ "title": "View Hir", "category": "Rust Analyzer" }, + { + "command": "rust-analyzer.viewCrateGraph", + "title": "View Crate Graph", + "category": "Rust Analyzer" + }, { "command": "rust-analyzer.expandMacro", "title": "Expand macro recursively", diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 4092435db..8ab259af2 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -429,6 +429,14 @@ export function viewHir(ctx: Ctx): Cmd { }; } +export function viewCrateGraph(ctx: Ctx): Cmd { + return async () => { + const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two); + const svg = await ctx.client.sendRequest(ra.viewCrateGraph); + panel.webview.html = svg; + }; +} + // Opens the virtual file that will show the syntax tree // // The contents of the file come from the `TextDocumentContentProvider` diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index f78de894b..aa745a65c 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -27,6 +27,8 @@ export const syntaxTree = new lc.RequestType("ru export const viewHir = new lc.RequestType("rust-analyzer/viewHir"); +export const viewCrateGraph = new lc.RequestType0("rust-analyzer/viewCrateGraph"); + export interface ExpandMacroParams { textDocument: lc.TextDocumentIdentifier; position: lc.Position; diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 643fb643f..516322d03 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -106,6 +106,7 @@ async function tryActivate(context: vscode.ExtensionContext) { ctx.registerCommand('parentModule', commands.parentModule); ctx.registerCommand('syntaxTree', commands.syntaxTree); ctx.registerCommand('viewHir', commands.viewHir); + ctx.registerCommand('viewCrateGraph', commands.viewCrateGraph); ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine); -- cgit v1.2.3