mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 18:58:41 +00:00
added children modules
This commit is contained in:
parent
c5882732e6
commit
1f7c3e8b92
10 changed files with 196 additions and 0 deletions
|
@ -170,6 +170,11 @@
|
|||
"title": "Locate parent module",
|
||||
"category": "rust-analyzer"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.childrenModules",
|
||||
"title": "Locate children modules",
|
||||
"category": "rust-analyzer"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.joinLines",
|
||||
"title": "Join lines",
|
||||
|
@ -3373,6 +3378,10 @@
|
|||
"command": "rust-analyzer.parentModule",
|
||||
"when": "inRustProject"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.childrenModule",
|
||||
"when": "inRustProject"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.joinLines",
|
||||
"when": "inRustProject"
|
||||
|
|
|
@ -266,6 +266,43 @@ export function parentModule(ctx: CtxInit): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function childrenModules(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) return;
|
||||
if (!(isRustDocument(editor.document) || isCargoTomlDocument(editor.document))) return;
|
||||
|
||||
const client = ctx.client;
|
||||
|
||||
const locations = await client.sendRequest(ra.childrenModules, {
|
||||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
|
||||
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
|
||||
});
|
||||
if (!locations) return;
|
||||
|
||||
if (locations.length === 1) {
|
||||
const loc = unwrapUndefinable(locations[0]);
|
||||
|
||||
const uri = client.protocol2CodeConverter.asUri(loc.targetUri);
|
||||
const range = client.protocol2CodeConverter.asRange(loc.targetRange);
|
||||
|
||||
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);
|
||||
} else {
|
||||
const uri = editor.document.uri.toString();
|
||||
const position = client.code2ProtocolConverter.asPosition(editor.selection.active);
|
||||
await showReferencesImpl(
|
||||
client,
|
||||
uri,
|
||||
position,
|
||||
locations.map((loc) => lc.Location.create(loc.targetUri, loc.targetRange)),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function openCargoToml(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
|
|
@ -194,6 +194,11 @@ export const parentModule = new lc.RequestType<
|
|||
lc.LocationLink[] | null,
|
||||
void
|
||||
>("experimental/parentModule");
|
||||
export const childrenModules = new lc.RequestType<
|
||||
lc.TextDocumentPositionParams,
|
||||
lc.LocationLink[] | null,
|
||||
void
|
||||
>("experimental/childrenModule");
|
||||
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
|
||||
"experimental/runnables",
|
||||
);
|
||||
|
|
|
@ -158,6 +158,7 @@ function createCommands(): Record<string, CommandFactory> {
|
|||
matchingBrace: { enabled: commands.matchingBrace },
|
||||
joinLines: { enabled: commands.joinLines },
|
||||
parentModule: { enabled: commands.parentModule },
|
||||
childrenModules: { enabled: commands.childrenModules },
|
||||
viewHir: { enabled: commands.viewHir },
|
||||
viewMir: { enabled: commands.viewMir },
|
||||
interpretFunction: { enabled: commands.interpretFunction },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue