about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorAnatol Liu <axlui@anatols-mbp.lan>2020-11-12 17:48:07 -0800
committerAnatol Liu <axlui@anatols-mbp.lan>2020-11-12 17:48:07 -0800
commitb1b7727e046b4b25dcca034ee767a7fc3238409d (patch)
treec1942b7af1e73b139d2c62d1d81e8d6749dc8cd2 /editors/code/src
parent111cc34c8f181315f4dcfa85c616d54d47eff0b9 (diff)
downloadrust-b1b7727e046b4b25dcca034ee767a7fc3238409d.tar.gz
rust-b1b7727e046b4b25dcca034ee767a7fc3238409d.zip
add open Cargo.toml action
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands.ts21
-rw-r--r--editors/code/src/lsp_ext.ts6
-rw-r--r--editors/code/src/main.ts1
3 files changed, 28 insertions, 0 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index cf34622c341..92bc4d7f723 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 d320c3cd718..5e877ce6511 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<lc.TextDocumentPositionParams, string | void, void>('experimental/externalDocs');
+
+export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>("experimental/openCargoToml");
+
+export interface OpenCargoTomlParams {
+    textDocument: lc.TextDocumentIdentifier;
+}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 09543e348a8..2f3dde8acd6 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);