Skip to content

Commit

Permalink
feat: add rust-analyzer.openCargoToml
Browse files Browse the repository at this point in the history
FYI #256
  • Loading branch information
fannheyward committed Nov 15, 2020
1 parent d84a05f commit 35958ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
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);
Expand Down
6 changes: 6 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,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;
}

0 comments on commit 35958ab

Please sign in to comment.