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') 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 From a14194b428efdb09cc45f9862ec34bef0038cd35 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Tue, 1 Sep 2020 11:38:32 +1200 Subject: Changes from review --- editors/code/src/lsp_ext.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'editors') diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 569e747bd..562804715 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -119,13 +119,4 @@ export interface CommandLinkGroup { 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'); +export const openDocs = new lc.RequestType('experimental/externalDocs'); -- cgit v1.2.3 From 974518fde7975b839ed4ccd4c5ce1d48cd6db3c7 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Tue, 1 Sep 2020 20:26:10 +1200 Subject: Code reorganisation and field support --- editors/code/src/commands.ts | 6 +++--- editors/code/src/lsp_ext.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'editors') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index b22cd450b..24c2e196d 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -421,12 +421,10 @@ 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 }; @@ -435,7 +433,9 @@ export function openDocs(ctx: Ctx): Cmd { const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); - vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink.remote)); + if (doclink != null) { + vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)); + } }; } diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 562804715..fc8e120b3 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -119,4 +119,4 @@ export interface CommandLinkGroup { commands: CommandLink[]; } -export const openDocs = new lc.RequestType('experimental/externalDocs'); +export const openDocs = new lc.RequestType('experimental/externalDocs'); -- cgit v1.2.3 From c648884397bfdb779c447fa31964dc1fce94bd95 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Thu, 3 Sep 2020 19:55:24 +1200 Subject: Differentiate method/tymethod by determining 'defaultness' Currently a method only has defaultness if it is a provided trait method, but this will change when specialisation is available and may need to become a concept known to hir. I opted to go for a 'fewest changes' approach given specialisation is still under development. --- editors/code/src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 24c2e196d..1445e41d3 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -425,7 +425,7 @@ export function openDocs(ctx: Ctx): Cmd { const client = ctx.client; const editor = vscode.window.activeTextEditor; if (!editor || !client) { - return + return; }; const position = editor.selection.active; -- cgit v1.2.3