add open Cargo.toml action

This commit is contained in:
Anatol Liu 2020-11-12 17:48:07 -08:00
parent 111cc34c8f
commit b1b7727e04
15 changed files with 114 additions and 42 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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);