From b1b7727e046b4b25dcca034ee767a7fc3238409d Mon Sep 17 00:00:00 2001 From: Anatol Liu Date: Thu, 12 Nov 2020 17:48:07 -0800 Subject: add open Cargo.toml action --- editors/code/package.json | 9 +++++++++ editors/code/src/commands.ts | 21 +++++++++++++++++++++ editors/code/src/lsp_ext.ts | 6 ++++++ editors/code/src/main.ts | 1 + 4 files changed, 37 insertions(+) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index eccafccdd..b02c80773 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -187,6 +187,11 @@ "command": "rust-analyzer.openDocs", "title": "Open docs under cursor", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.openCargoToml", + "title": "Open Cargo.toml", + "category": "Rust Analyzer" } ], "keybindings": [ @@ -1057,6 +1062,10 @@ { "command": "rust-analyzer.openDocs", "when": "inRustProject" + }, + { + "command": "rust-analyzer.openCargoToml", + "when": "inRustProject" } ] } diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index cf34622c3..92bc4d7f7 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -188,6 +188,27 @@ export function parentModule(ctx: Ctx): Cmd { }; } +export function openCargoToml(ctx: Ctx): Cmd { + return async () => { + const editor = ctx.activeRustEditor; + const client = ctx.client; + if (!editor || !client) return; + + const response = await client.sendRequest(ra.openCargoToml, { + textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), + }); + if (!response) return; + + const uri = client.protocol2CodeConverter.asUri(response.uri); + const range = client.protocol2CodeConverter.asRange(response.range); + + const doc = await vscode.workspace.openTextDocument(uri); + const e = await vscode.window.showTextDocument(doc); + e.selection = new vscode.Selection(range.start, range.start); + e.revealRange(range, vscode.TextEditorRevealType.InCenter); + }; +} + export function ssr(ctx: Ctx): Cmd { return async () => { const editor = vscode.window.activeTextEditor; diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index d320c3cd7..5e877ce65 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -114,3 +114,9 @@ export interface CommandLinkGroup { } export const openDocs = new lc.RequestType('experimental/externalDocs'); + +export const openCargoToml = new lc.RequestType("experimental/openCargoToml"); + +export interface OpenCargoTomlParams { + textDocument: lc.TextDocumentIdentifier; +} diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 09543e348..2f3dde8ac 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -111,6 +111,7 @@ async function tryActivate(context: vscode.ExtensionContext) { ctx.registerCommand('debug', commands.debug); ctx.registerCommand('newDebugConfig', commands.newDebugConfig); ctx.registerCommand('openDocs', commands.openDocs); + ctx.registerCommand('openCargoToml', commands.openCargoToml); defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); -- cgit v1.2.3