Skip to content

Commit 7e986d1

Browse files
committed
Add rust-analyzer.gotoLocation command
1 parent d4e7531 commit 7e986d1

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

.vscode/launch.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@
120120
"sourceMaps": true,
121121
"outFiles": [ "${workspaceFolder}/editors/code/out/tests/unit/**/*.js" ],
122122
"preLaunchTask": "Pretest"
123-
},
124-
{
125-
"name": "(Windows) Attach",
126-
"type": "cppvsdbg",
127-
"request": "attach",
128-
"processId": "${command:pickProcess}"
129-
}
123+
}
130124
]
131125
}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = [ "crates/*", "xtask/" ]
44
[profile.dev]
55
# disabling debug info speeds up builds a bunch,
66
# and we don't rely on it for debugging that much.
7-
debug = 2
7+
debug = 0
88

99
[profile.release]
1010
incremental = true

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@
510510
"type": "boolean",
511511
"default": true
512512
},
513+
"rust-analyzer.hoverActions.gotoTypeDef": {
514+
"markdownDescription": "Whether to show `Go to Type Definition` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set.",
515+
"type": "boolean",
516+
"default": true
517+
},
513518
"rust-analyzer.linkedProjects": {
514519
"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",
515520
"type": "array",

editors/code/src/commands.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ export function applyActionGroup(_ctx: Ctx): Cmd {
353353
};
354354
}
355355

356+
export function gotoLocation(ctx: Ctx): Cmd {
357+
return async (locationLink: lc.LocationLink) => {
358+
const client = ctx.client;
359+
if (client) {
360+
const uri = client.protocol2CodeConverter.asUri(locationLink.targetUri);
361+
let range = client.protocol2CodeConverter.asRange(locationLink.targetSelectionRange);
362+
// collapse the range to a cursor position
363+
range = range.with({ end: range.start });
364+
365+
await vscode.window.showTextDocument(uri, { selection: range });
366+
}
367+
};
368+
}
369+
356370
export function resolveCodeAction(ctx: Ctx): Cmd {
357371
const client = ctx.client;
358372
return async (params: ra.ResolveCodeActionParams) => {

editors/code/src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export class Config {
135135
return {
136136
enable: this.get<boolean>("hoverActions.enable"),
137137
implementations: this.get<boolean>("hoverActions.implementations"),
138+
run: this.get<boolean>("hoverActions.run"),
139+
debug: this.get<boolean>("hoverActions.debug"),
140+
gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
138141
};
139142
}
140143
}

editors/code/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext) {
100100
ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
101101
ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
102102
ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
103+
ctx.registerCommand('gotoLocation', commands.gotoLocation);
103104

104105
ctx.pushCleanup(activateTaskProvider(workspaceFolder));
105106

0 commit comments

Comments
 (0)