Skip to content

Commit

Permalink
feat(commands): add rust-analyzer.viewFileText
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Apr 19, 2022
1 parent 19cff5b commit 3a69d37
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ You can use these commands by `:CocCommand XYZ`.
| rust-analyzer.toggleInlayHints | Toggle inlay hints on/off |
| rust-analyzer.upgrade | Download latest `rust-analyzer` from [GitHub release](https://github.com/rust-analyzer/rust-analyzer/releases) |
| rust-analyzer.viewHir | View Hir |
| rust-analyzer.viewFileText | View File Text |
| rust-analyzer.viewCrateGraph | View Crate Graph |
| rust-analyzer.viewFullCrateGraph | View Crate Graph (Full) |
| rust-analyzer.shuffleCrateGraph | Shuffle Crate Graph |
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@
"title": "View Hir",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.viewFileText",
"title": "View File Text (as seen by the server)",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.viewItemTree",
"title": "Debug ItemTree",
Expand Down
18 changes: 18 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,24 @@ export function viewHir(ctx: Ctx): Cmd {
};
}

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

const ret = await ctx.client.sendRequest(ra.viewFileText, { uri: document.uri });
if (!ret) return;

const nvim = workspace.nvim;
nvim.pauseNotification();
nvim.command(`edit +setl\\ buftype=nofile [TEXT]`, 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 echoRunCommandLine(ctx: Ctx) {
return async () => {
const runnable = await fetchRunnable(ctx);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('ssr', cmds.ssr);
ctx.registerCommand('upgrade', cmds.upgrade);
ctx.registerCommand('viewHir', cmds.viewHir);
ctx.registerCommand('viewFileText', cmds.viewFileText);
ctx.registerCommand('openDocs', cmds.openDocs);
ctx.registerCommand('joinLines', cmds.joinLines);
ctx.registerCommand('peekTests', cmds.peekTests);
Expand Down
2 changes: 2 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>('ru

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

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

export interface ViewItemTreeParams {
textDocument: lc.TextDocumentIdentifier;
}
Expand Down

0 comments on commit 3a69d37

Please sign in to comment.