Skip to content

Commit

Permalink
feat: add rust-analyzer.viewHir
Browse files Browse the repository at this point in the history
FYI #256
  • Loading branch information
fannheyward committed Jan 6, 2021
1 parent c1db73f commit f5720cc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ You can use these commands by `:CocCommand XYZ`.
- `rust-analyzer.serverVersion`: Show current Rust Analyzer server version
- `rust-analyzer.toggleInlayHints`: Toggle inlay hints on/off
- `rust-analyzer.explainError`: Explain the currently hovered error message
- `rust-analyzer.viewHir`: View Hir
- `rust-analyzer.upgrade`: Download latest `rust-analyzer` from [GitHub release](https://github.com/rust-analyzer/rust-analyzer/releases)

## Highlight Group
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
"title": "Expand macro recursively",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.viewHir",
"title": "View Hir",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.explainError",
"title": "Explain the currently hovered diagnostic",
Expand Down
17 changes: 17 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,20 @@ export function openCargoToml(ctx: Ctx): Cmd {
await workspace.jumpTo(location.uri);
};
}

export function viewHir(ctx: Ctx): Cmd {
return async () => {
const { document, position } = await workspace.getCurrentState();
if (!isRustDocument(document)) return;

const param: TextDocumentPositionParams = {
textDocument: { uri: document.uri },
position,
};
const ret = await ctx.client.sendRequest(ra.viewHir, param);
await workspace.nvim.command('tabnew').then(async () => {
const buf = await workspace.nvim.buffer;
buf.setLines(ret.split('\n'), { start: 0, end: -1 });
});
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('explainError', cmds.explainError);
ctx.registerCommand('upgrade', cmds.upgrade);
ctx.registerCommand('ssr', cmds.ssr);
ctx.registerCommand('viewHir', cmds.viewHir);
ctx.registerCommand('serverVersion', cmds.serverVersion);
ctx.registerCommand('toggleInlayHints', cmds.toggleInlayHints);
ctx.registerCommand('reload', (ctx) => {
Expand Down
2 changes: 2 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface SyntaxTreeParams {
}
export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>('rust-analyzer/syntaxTree');

export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>('rust-analyzer/viewHir');

export interface ExpandMacroParams {
textDocument: lc.TextDocumentIdentifier;
position: lc.Position;
Expand Down

0 comments on commit f5720cc

Please sign in to comment.