From bfda0d25834250a3adbcd0d26953a1cdc6662e7f Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Sun, 30 Aug 2020 20:02:29 +1200 Subject: WIP: Command to open docs under cursor --- editors/code/package.json | 9 +++++++++ editors/code/src/commands.ts | 25 +++++++++++++++++++++++-- editors/code/src/lsp_ext.ts | 11 +++++++++++ editors/code/src/main.ts | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index 6a712a8a8..4bd3117fc 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -182,6 +182,11 @@ "command": "rust-analyzer.toggleInlayHints", "title": "Toggle inlay hints", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.openDocs", + "title": "Open docs under cursor", + "category": "Rust Analyzer" } ], "keybindings": [ @@ -1044,6 +1049,10 @@ { "command": "rust-analyzer.toggleInlayHints", "when": "inRustProject" + }, + { + "command": "rust-analyzer.openDocs", + "when": "inRustProject" } ] } diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 1a90f1b7d..b22cd450b 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -419,10 +419,31 @@ export function gotoLocation(ctx: Ctx): Cmd { }; } +export function openDocs(ctx: Ctx): Cmd { + return async () => { + console.log("running openDocs"); + + const client = ctx.client; + const editor = vscode.window.activeTextEditor; + if (!editor || !client) { + console.log("not yet ready"); + return + }; + + const position = editor.selection.active; + const textDocument = { uri: editor.document.uri.toString() }; + + const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); + + vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink.remote)); + }; + +} + export function resolveCodeAction(ctx: Ctx): Cmd { const client = ctx.client; - return async (params: ra.ResolveCodeActionParams) => { - const item: lc.WorkspaceEdit = await client.sendRequest(ra.resolveCodeAction, params); + return async () => { + const item: lc.WorkspaceEdit = await client.sendRequest(ra.resolveCodeAction, null); if (!item) { return; } diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index f286b68a6..569e747bd 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -118,3 +118,14 @@ export interface CommandLinkGroup { title?: string; commands: CommandLink[]; } + +export interface DocumentationLink { + remote: string; +} + +export interface OpenDocsParams { + textDocument: lc.TextDocumentIdentifier; + position: lc.Position; +} + +export const openDocs = new lc.RequestType('rust-analyzer/openDocs'); diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 2896d90ac..09543e348 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -110,6 +110,7 @@ async function tryActivate(context: vscode.ExtensionContext) { ctx.registerCommand('run', commands.run); ctx.registerCommand('debug', commands.debug); ctx.registerCommand('newDebugConfig', commands.newDebugConfig); + ctx.registerCommand('openDocs', commands.openDocs); defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); -- cgit v1.2.3