Skip to content

Commit

Permalink
feat: add rust-analyzer.openDocs
Browse files Browse the repository at this point in the history
FYI #256
  • Loading branch information
fannheyward committed Oct 12, 2020
1 parent 4c5cc32 commit 04c51ad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ You can use these commands by `:CocCommand XYZ`.
- `rust-analyzer.expandMacro`: Expand macro recursively
- `rust-analyzer.joinLines`: Join lines
- `rust-analyzer.matchingBrace`: Find matching brace
- `rust-analyzer.openDocs`: Open docs under cursor
- `rust-analyzer.parentModule`: Locate parent module
- `rust-analyzer.reload`: Restart rust-analyzer server
- `rust-analyzer.run`: List available runnables of current file
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@
"title": "Find matching brace",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.openDocs",
"title": "Open docs under cursor",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.parentModule",
"title": "Locate parent module",
Expand Down
16 changes: 16 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,19 @@ export function resolveCodeAction(ctx: Ctx): Cmd {
await applySnippetWorkspaceEdit(edit);
};
}

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

const param: TextDocumentPositionParams = {
textDocument: { uri: document.uri },
position,
};
const doclink = await ctx.client.sendRequest(ra.openDocs, param);
if (doclink) {
await commands.executeCommand('vscode.open', Uri.parse(doclink));
}
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('expandMacro', cmds.expandMacro);
ctx.registerCommand('joinLines', cmds.joinLines);
ctx.registerCommand('matchingBrace', cmds.matchingBrace);
ctx.registerCommand('openDocs', cmds.openDocs);
ctx.registerCommand('parentModule', cmds.parentModule);
ctx.registerCommand('run', cmds.run);
ctx.registerCommand('runSingle', cmds.runSingle);
Expand Down
2 changes: 2 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ export interface CommandLinkGroup {
title?: string;
commands: CommandLink[];
}

export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>('experimental/externalDocs');

0 comments on commit 04c51ad

Please sign in to comment.