From 7e986d1504e6fd6dc1fc9b64f5fb9eac2bef952a Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 10 Jun 2020 23:01:19 +0300 Subject: Add `rust-analyzer.gotoLocation` command --- editors/code/src/commands.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'editors/code/src/commands.ts') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 3e9c3aa0e..48a25495f 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) => { -- cgit v1.2.3