Skip to content

Commit

Permalink
feat: rust-analyzer.viewItemTree
Browse files Browse the repository at this point in the history
related #256
  • Loading branch information
fannheyward committed May 24, 2021
1 parent 3e13fb6 commit 8b49b7d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@
"title": "View Hir",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.viewItemTree",
"title": "Debug ItemTree",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.viewCrateGraph",
"title": "View Crate Graph",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.echoRunCommandLine",
"title": "Echo Run Command Line",
Expand Down
20 changes: 20 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,3 +661,23 @@ export function viewCrateGraph(ctx: Ctx): Cmd {
window.echoLines([svg]);
};
}

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

const param: ra.ViewItemTreeParams = {
textDocument: { uri: document.uri },
};
const ret = await ctx.client.sendRequest(ra.viewItemTree, param);
if (!ret) return;
const nvim = workspace.nvim;
nvim.pauseNotification();
nvim.command(`edit +setl\\ buftype=nofile [ItemTree]`, true);
nvim.command('setl nobuflisted bufhidden=wipe', true);
nvim.call('append', [0, ret.split('\n')], true);
nvim.command(`exe 1`, true);
await nvim.resumeNotification();
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('expandMacro', cmds.expandMacro);
ctx.registerCommand('moveItemUp', cmds.moveItemUp);
ctx.registerCommand('moveItemDown', cmds.moveItemDown);
ctx.registerCommand('viewItemTree', cmds.viewItemTree);
ctx.registerCommand('explainError', cmds.explainError);
ctx.registerCommand('parentModule', cmds.parentModule);
ctx.registerCommand('matchingBrace', cmds.matchingBrace);
Expand Down
6 changes: 6 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>('ru

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

export interface ViewItemTreeParams {
textDocument: lc.TextDocumentIdentifier;
}

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

export const viewCrateGraph = new lc.RequestType0<string, void>('rust-analyzer/viewCrateGraph');

export interface ExpandMacroParams {
Expand Down

0 comments on commit 8b49b7d

Please sign in to comment.