add open Cargo.toml action
This commit is contained in:
@@ -187,6 +187,11 @@
|
||||
"command": "rust-analyzer.openDocs",
|
||||
"title": "Open docs under cursor",
|
||||
"category": "Rust Analyzer"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.openCargoToml",
|
||||
"title": "Open Cargo.toml",
|
||||
"category": "Rust Analyzer"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
@@ -1057,6 +1062,10 @@
|
||||
{
|
||||
"command": "rust-analyzer.openDocs",
|
||||
"when": "inRustProject"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.openCargoToml",
|
||||
"when": "inRustProject"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user