about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorvsrs <vit@conrlab.com>2020-06-10 23:01:19 +0300
committervsrs <vit@conrlab.com>2020-06-18 10:15:43 +0300
commit7e986d1504e6fd6dc1fc9b64f5fb9eac2bef952a (patch)
tree2b2cd6da18a1b4a95b1953a3fcbb2519fae44a22 /editors/code
parentd4e75312ba64c2541e0d97b9ad8d6e2a735882a4 (diff)
downloadrust-7e986d1504e6fd6dc1fc9b64f5fb9eac2bef952a.tar.gz
rust-7e986d1504e6fd6dc1fc9b64f5fb9eac2bef952a.zip
Add `rust-analyzer.gotoLocation` command
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands.ts14
-rw-r--r--editors/code/src/config.ts3
-rw-r--r--editors/code/src/main.ts1
4 files changed, 23 insertions, 0 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 3acc375f672..e6ceb235fcf 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -510,6 +510,11 @@
                     "type": "boolean",
                     "default": true
                 },
+                "rust-analyzer.hoverActions.gotoTypeDef": {
+                    "markdownDescription": "Whether to show `Go to Type Definition` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set.",
+                    "type": "boolean",
+                    "default": true
+                },
                 "rust-analyzer.linkedProjects": {
                     "markdownDescription": "Disable project auto-discovery in favor of explicitly specified set of projects.  \nElements must be paths pointing to Cargo.toml, rust-project.json, or JSON objects in rust-project.json format",
                     "type": "array",
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 3e9c3aa0e59..48a25495fb9 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -353,6 +353,20 @@ export function applyActionGroup(_ctx: Ctx): Cmd {
     };
 }
 
+export function gotoLocation(ctx: Ctx): Cmd {
+    return async (locationLink: lc.LocationLink) => {
+        const client = ctx.client;
+        if (client) {
+            const uri = client.protocol2CodeConverter.asUri(locationLink.targetUri);
+            let range = client.protocol2CodeConverter.asRange(locationLink.targetSelectionRange);
+            // collapse the range to a cursor position
+            range = range.with({ end: range.start });
+
+            await vscode.window.showTextDocument(uri, { selection: range });
+        }
+    };
+}
+
 export function resolveCodeAction(ctx: Ctx): Cmd {
     const client = ctx.client;
     return async (params: ra.ResolveCodeActionParams) => {
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 22ebdf6366d..9591d4fe32c 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -135,6 +135,9 @@ export class Config {
         return {
             enable: this.get<boolean>("hoverActions.enable"),
             implementations: this.get<boolean>("hoverActions.implementations"),
+            run: this.get<boolean>("hoverActions.run"),
+            debug: this.get<boolean>("hoverActions.debug"),
+            gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
         };
     }
 }
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a92c676fa2d..270fbcb6448 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -100,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
     ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
     ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
+    ctx.registerCommand('gotoLocation', commands.gotoLocation);
 
     ctx.pushCleanup(activateTaskProvider(workspaceFolder));