diff options
| author | hkalbasi <hamidrezakalbasi@protonmail.com> | 2023-02-26 16:04:41 +0330 |
|---|---|---|
| committer | hkalbasi <hamidrezakalbasi@protonmail.com> | 2023-03-06 21:09:09 +0330 |
| commit | ac04bfd7a7223cc7077f6745c35f8b655ea13c73 (patch) | |
| tree | fb993abefdda7f7673b7b715199119335eea4e1e /editors/code | |
| parent | a25710b0c01cc523b0f3732ca68321ac107a0ebe (diff) | |
| download | rust-ac04bfd7a7223cc7077f6745c35f8b655ea13c73.tar.gz rust-ac04bfd7a7223cc7077f6745c35f8b655ea13c73.zip | |
Add `View Mir` command and fix some bugs
Diffstat (limited to 'editors/code')
| -rw-r--r-- | editors/code/package.json | 5 | ||||
| -rw-r--r-- | editors/code/src/commands.ts | 27 | ||||
| -rw-r--r-- | editors/code/src/lsp_ext.ts | 3 | ||||
| -rw-r--r-- | editors/code/src/main.ts | 1 |
4 files changed, 29 insertions, 7 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index effe4e279c7..90f7b9074c8 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -115,6 +115,11 @@ "category": "rust-analyzer (debug command)" }, { + "command": "rust-analyzer.viewMir", + "title": "View Mir", + "category": "rust-analyzer (debug command)" + }, + { "command": "rust-analyzer.viewFileText", "title": "View File Text (as seen by the server)", "category": "rust-analyzer (debug command)" 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<vscode.Uri>(); 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<vscode.Uri> { @@ -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<lc.TextDocumentIdentifier, string export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>( "rust-analyzer/viewHir" ); +export const viewMir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>( + "rust-analyzer/viewMir" +); export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>( "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<string, CommandFactory> { 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 }, |
