Skip to content

Commit

Permalink
feat: add rust-analyzer.viewMir
Browse files Browse the repository at this point in the history
related #256
  • Loading branch information
fannheyward committed May 6, 2023
1 parent bd049c9 commit 4254c94
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ You can use these commands by `:CocCommand XYZ`.
| rust-analyzer.testCurrent | Test Current |
| rust-analyzer.upgrade | Download latest `rust-analyzer` from [GitHub release](https://github.com/rust-lang/rust-analyzer/releases) |
| rust-analyzer.viewHir | View Hir |
| rust-analyzer.viewMir | View Mir |
| rust-analyzer.viewFileText | View File Text |
| rust-analyzer.viewCrateGraph | View Crate Graph |
| rust-analyzer.viewFullCrateGraph | View Crate Graph (Full) |
Expand Down
61 changes: 33 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1143,137 +1143,142 @@
{
"command": "rust-analyzer.analyzerStatus",
"title": "Status",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.memoryUsage",
"title": "Memory Usage (Clears Database)",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.reloadWorkspace",
"title": "Reload workspace",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.joinLines",
"title": "Join lines",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.matchingBrace",
"title": "Find matching brace",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.openDocs",
"title": "Open docs under cursor",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.openCargoToml",
"title": "Open Cargo.toml",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.parentModule",
"title": "Locate parent module",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.reload",
"title": "Restart server",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.run",
"title": "Run",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.debug",
"title": "Debug",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.ssr",
"title": "Structural Search Replace",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.serverVersion",
"title": "Show current Rust Analyzer server version",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.syntaxTree",
"title": "Show Syntax Tree",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.testCurrent",
"title": "Test Current",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.upgrade",
"title": "Upgrade Rust Analyzer from GitHub release",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.expandMacro",
"title": "Expand macro recursively",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewHir",
"title": "View Hir",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewMir",
"title": "View Mir",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewFileText",
"title": "View File Text (as seen by the server)",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewItemTree",
"title": "Debug ItemTree",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewCrateGraph",
"title": "View Crate Graph",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.shuffleCrateGraph",
"title": "Shuffle Crate Graph",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.viewFullCrateGraph",
"title": "View Crate Graph (Full)",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.echoRunCommandLine",
"title": "Echo Run Command Line",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.peekTests",
"title": "Peek related tests",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.moveItemUp",
"title": "Move item up",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.moveItemDown",
"title": "Move item down",
"category": "Rust Analyzer"
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.runFlycheck",
Expand All @@ -1298,7 +1303,7 @@
{
"command": "rust-analyzer.explainError",
"title": "Explain the currently hovered diagnostic",
"category": "Rust Analyzer"
"category": "rust-analyzer"
}
]
}
Expand Down
15 changes: 12 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export function openCargoToml(ctx: Ctx): Cmd {
};
}

export function viewHir(ctx: Ctx): Cmd {
function viewXir(ctx: Ctx, xir: 'HIR' | 'MIR'): Cmd {
return async () => {
const { document, position } = await workspace.getCurrentState();
if (!isRustDocument(document)) return;
Expand All @@ -701,18 +701,27 @@ export function viewHir(ctx: Ctx): Cmd {
textDocument: { uri: document.uri },
position,
};
const ret = await ctx.client.sendRequest(ra.viewHir, param);
const req = xir === 'HIR' ? ra.viewHir : ra.viewMir;
const ret = await ctx.client.sendRequest(req, param);
if (!ret) return;
const nvim = workspace.nvim;
nvim.pauseNotification();
nvim.command(`edit +setl\\ buftype=nofile [HIR]`, true);
nvim.command(`edit +setl\\ buftype=nofile [${xir}]`, true);
nvim.command('setl nobuflisted bufhidden=wipe', true);
nvim.call('append', [0, ret.split('\n')], true);
nvim.command(`exe 1`, true);
await nvim.resumeNotification(true);
};
}

export function viewHir(ctx: Ctx): Cmd {
return viewXir(ctx, 'HIR');
}

export function viewMir(ctx: Ctx): Cmd {
return viewXir(ctx, 'MIR');
}

export function viewFileText(ctx: Ctx): Cmd {
return async () => {
const { document } = await workspace.getCurrentState();
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('reload', cmds.reload);
ctx.registerCommand('upgrade', cmds.upgrade);
ctx.registerCommand('viewHir', cmds.viewHir);
ctx.registerCommand('viewMir', cmds.viewMir);
ctx.registerCommand('openDocs', cmds.openDocs);
ctx.registerCommand('joinLines', cmds.joinLines);
ctx.registerCommand('peekTests', cmds.peekTests);
Expand Down
6 changes: 6 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ 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 interpretFunction = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
'rust-analyzer/interpretFunction'
);
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
'rust-analyzer/viewItemTree'
);
Expand Down

0 comments on commit 4254c94

Please sign in to comment.