From 35958ab810aba603e18677aaaa0706ae3f30d299 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Sun, 15 Nov 2020 21:20:14 +0800 Subject: [PATCH] feat: add rust-analyzer.openCargoToml FYI #256 --- package.json | 5 +++++ src/commands.ts | 14 ++++++++++++++ src/index.ts | 1 + src/lsp_ext.ts | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/package.json b/package.json index 12128df9..036536d2 100644 --- a/package.json +++ b/package.json @@ -501,6 +501,11 @@ "title": "Open docs under cursor", "category": "Rust Analyzer" }, + { + "command": "rust-analyzer.openCargoToml", + "title": "Open Cargo.toml", + "category": "Rust Analyzer" + }, { "command": "rust-analyzer.parentModule", "title": "Locate parent module", diff --git a/src/commands.ts b/src/commands.ts index 83fb57d3..a648dbd9 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -472,3 +472,17 @@ export function openDocs(ctx: Ctx): Cmd { } }; } + +export function openCargoToml(ctx: Ctx): Cmd { + return async () => { + const { document } = await workspace.getCurrentState(); + if (!isRustDocument(document)) return; + + const location = await ctx.client.sendRequest(ra.openCargoToml, { + textDocument: { uri: document.uri }, + }); + if (!location) return; + + await workspace.jumpTo(location.uri); + }; +} diff --git a/src/index.ts b/src/index.ts index d1167551..de07d692 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ export async function activate(context: ExtensionContext): Promise { ctx.registerCommand('joinLines', cmds.joinLines); ctx.registerCommand('matchingBrace', cmds.matchingBrace); ctx.registerCommand('openDocs', cmds.openDocs); + ctx.registerCommand('openCargoToml', cmds.openCargoToml); ctx.registerCommand('parentModule', cmds.parentModule); ctx.registerCommand('run', cmds.run); ctx.registerCommand('debugSingle', cmds.debugSingle); diff --git a/src/lsp_ext.ts b/src/lsp_ext.ts index 1871571d..a14762d9 100644 --- a/src/lsp_ext.ts +++ b/src/lsp_ext.ts @@ -119,3 +119,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; +}