From ac04bfd7a7223cc7077f6745c35f8b655ea13c73 Mon Sep 17 00:00:00 2001 From: hkalbasi Date: Sun, 26 Feb 2023 16:04:41 +0330 Subject: Add `View Mir` command and fix some bugs --- editors/code/src/commands.ts | 27 ++++++++++++++++++++------- editors/code/src/lsp_ext.ts | 3 +++ editors/code/src/main.ts | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 49a8ca4edba..70b91fe7dc8 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -405,12 +405,11 @@ export function syntaxTree(ctx: CtxInit): Cmd { }; } -// Opens the virtual file that will show the HIR of the function containing the cursor position -// -// The contents of the file come from the `TextDocumentContentProvider` -export function viewHir(ctx: CtxInit): Cmd { +function viewHirOrMir(ctx: CtxInit, xir: "hir" | "mir"): Cmd { + const viewXir = xir === "hir" ? "viewHir" : "viewMir"; + const requestType = xir === "hir" ? ra.viewHir : ra.viewMir; const tdcp = new (class implements vscode.TextDocumentContentProvider { - readonly uri = vscode.Uri.parse("rust-analyzer-hir://viewHir/hir.rs"); + readonly uri = vscode.Uri.parse(`rust-analyzer-${xir}://${viewXir}/${xir}.rs`); readonly eventEmitter = new vscode.EventEmitter(); constructor() { vscode.workspace.onDidChangeTextDocument( @@ -452,7 +451,7 @@ export function viewHir(ctx: CtxInit): Cmd { ), position: client.code2ProtocolConverter.asPosition(rustEditor.selection.active), }; - return client.sendRequest(ra.viewHir, params, ct); + return client.sendRequest(requestType, params, ct); } get onDidChange(): vscode.Event { @@ -461,7 +460,7 @@ export function viewHir(ctx: CtxInit): Cmd { })(); ctx.pushExtCleanup( - vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-hir", tdcp) + vscode.workspace.registerTextDocumentContentProvider(`rust-analyzer-${xir}`, tdcp) ); return async () => { @@ -474,6 +473,20 @@ export function viewHir(ctx: CtxInit): Cmd { }; } +// Opens the virtual file that will show the HIR of the function containing the cursor position +// +// The contents of the file come from the `TextDocumentContentProvider` +export function viewHir(ctx: CtxInit): Cmd { + return viewHirOrMir(ctx, "hir"); +} + +// Opens the virtual file that will show the MIR of the function containing the cursor position +// +// The contents of the file come from the `TextDocumentContentProvider` +export function viewMir(ctx: CtxInit): Cmd { + return viewHirOrMir(ctx, "mir"); +} + export function viewFileText(ctx: CtxInit): Cmd { const tdcp = new (class implements vscode.TextDocumentContentProvider { readonly uri = vscode.Uri.parse("rust-analyzer-file-text://viewFileText/file.rs"); diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index f6f5124dc41..400cd207d41 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -59,6 +59,9 @@ export const viewFileText = new lc.RequestType( "rust-analyzer/viewHir" ); +export const viewMir = new lc.RequestType( + "rust-analyzer/viewMir" +); export const viewItemTree = new lc.RequestType( "rust-analyzer/viewItemTree" ); diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5987368e6e0..1eb01f30c1e 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -158,6 +158,7 @@ function createCommands(): Record { parentModule: { enabled: commands.parentModule }, syntaxTree: { enabled: commands.syntaxTree }, viewHir: { enabled: commands.viewHir }, + viewMir: { enabled: commands.viewMir }, viewFileText: { enabled: commands.viewFileText }, viewItemTree: { enabled: commands.viewItemTree }, viewCrateGraph: { enabled: commands.viewCrateGraph }, -- cgit 1.4.1-3-g733a5