Skip to content

Commit

Permalink
feat: rust-analyzer.interpretFunction
Browse files Browse the repository at this point in the history
related #256
  • Loading branch information
fannheyward committed May 6, 2023
1 parent 4254c94 commit 90eb4b7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ You can use these commands by `:CocCommand XYZ`.
| rust-analyzer.cancelFlycheck | Cancel running flychecks |
| rust-analyzer.clearFlycheck | Clear flycheck diagnostics |
| rust-analyzer.rebuildProcMacros | Rebuild proc macros and build scripts |
| rust-analyzer.interpretFunction | Interpret Function |

## License

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,11 @@
"title": "Rebuild proc macros and build scripts",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.interpretFunction",
"title": "Interpret Function",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.explainError",
"title": "Explain the currently hovered diagnostic",
Expand Down
21 changes: 21 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,27 @@ export function viewMir(ctx: Ctx): Cmd {
return viewXir(ctx, 'MIR');
}

export function interpretFunction(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.interpretFunction, param);
if (!ret) return;
const nvim = workspace.nvim;
nvim.pauseNotification();
nvim.command(`edit +setl\\ buftype=nofile [interpretFunction]`, 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 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 @@ -74,6 +74,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('clearFlycheck', cmds.clearFlycheck);
ctx.registerCommand('analyzerStatus', cmds.analyzerStatus);
ctx.registerCommand('viewCrateGraph', cmds.viewCrateGraph);
ctx.registerCommand('interpretFunction', cmds.interpretFunction);
ctx.registerCommand('rebuildProcMacros', cmds.rebuildProcMacros);
ctx.registerCommand('shuffleCrateGraph', cmds.shuffleCrateGraph);
ctx.registerCommand('viewFullCrateGraph', cmds.viewFullCrateGraph);
Expand Down

0 comments on commit 90eb4b7

Please sign in to comment.