Merge pull request #19554 from davidbarsky/davidbarsky/rename-children-modules-to-child-modules

internal: rename `children_modules` to `child_modules`
This commit is contained in:
Laurențiu Nicola 2025-04-09 16:55:23 +00:00 committed by GitHub
commit a556f72735
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 45 additions and 39 deletions

View File

@ -7,16 +7,16 @@ use syntax::{
use crate::NavigationTarget; use crate::NavigationTarget;
// Feature: Children Modules // Feature: Child Modules
// //
// Navigates to the children modules of the current module. // Navigates to the child modules of the current module.
// //
// | Editor | Action Name | // | Editor | Action Name |
// |---------|-------------| // |---------|-------------|
// | VS Code | **rust-analyzer: Locate children modules** | // | VS Code | **rust-analyzer: Locate child modules** |
/// This returns `Vec` because a module may be included from several places. /// This returns `Vec` because a module may be included from several places.
pub(crate) fn children_modules(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { pub(crate) fn child_modules(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> {
let sema = Semantics::new(db); let sema = Semantics::new(db);
let source_file = sema.parse_guess_edition(position.file_id); let source_file = sema.parse_guess_edition(position.file_id);
// First go to the parent module which contains the cursor // First go to the parent module which contains the cursor
@ -24,7 +24,7 @@ pub(crate) fn children_modules(db: &RootDatabase, position: FilePosition) -> Vec
match module { match module {
Some(module) => { Some(module) => {
// Return all the children module inside the ItemList of the parent module // Return all child modules inside the ItemList of the parent module
sema.to_def(&module) sema.to_def(&module)
.into_iter() .into_iter()
.flat_map(|module| module.children(db)) .flat_map(|module| module.children(db))
@ -32,7 +32,7 @@ pub(crate) fn children_modules(db: &RootDatabase, position: FilePosition) -> Vec
.collect() .collect()
} }
None => { None => {
// Return all the children module inside the source file // Return all the child modules inside the source file
sema.file_to_module_defs(position.file_id) sema.file_to_module_defs(position.file_id)
.flat_map(|module| module.children(db)) .flat_map(|module| module.children(db))
.map(|module| NavigationTarget::from_module_to_decl(db, module).call_site()) .map(|module| NavigationTarget::from_module_to_decl(db, module).call_site())
@ -47,9 +47,9 @@ mod tests {
use crate::fixture; use crate::fixture;
fn check_children_module(#[rust_analyzer::rust_fixture] ra_fixture: &str) { fn check_child_module(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
let (analysis, position, expected) = fixture::annotations(ra_fixture); let (analysis, position, expected) = fixture::annotations(ra_fixture);
let navs = analysis.children_modules(position).unwrap(); let navs = analysis.child_modules(position).unwrap();
let navs = navs let navs = navs
.iter() .iter()
.map(|nav| FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() }) .map(|nav| FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() })
@ -58,8 +58,8 @@ mod tests {
} }
#[test] #[test]
fn test_resolve_children_module() { fn test_resolve_child_module() {
check_children_module( check_child_module(
r#" r#"
//- /lib.rs //- /lib.rs
$0 $0
@ -73,8 +73,8 @@ mod foo;
} }
#[test] #[test]
fn test_resolve_children_module_on_module_decl() { fn test_resolve_child_module_on_module_decl() {
check_children_module( check_child_module(
r#" r#"
//- /lib.rs //- /lib.rs
mod $0foo; mod $0foo;
@ -89,8 +89,8 @@ mod bar;
} }
#[test] #[test]
fn test_resolve_children_module_for_inline() { fn test_resolve_child_module_for_inline() {
check_children_module( check_child_module(
r#" r#"
//- /lib.rs //- /lib.rs
mod foo { mod foo {
@ -104,7 +104,7 @@ mod foo {
#[test] #[test]
fn test_resolve_multi_child_module() { fn test_resolve_multi_child_module() {
check_children_module( check_child_module(
r#" r#"
//- /main.rs //- /main.rs
$0 $0

View File

@ -20,7 +20,7 @@ mod navigation_target;
mod annotations; mod annotations;
mod call_hierarchy; mod call_hierarchy;
mod children_modules; mod child_modules;
mod doc_links; mod doc_links;
mod expand_macro; mod expand_macro;
mod extend_selection; mod extend_selection;
@ -607,8 +607,8 @@ impl Analysis {
} }
/// Returns vec of `mod name;` declaration which are created by the current module. /// Returns vec of `mod name;` declaration which are created by the current module.
pub fn children_modules(&self, position: FilePosition) -> Cancellable<Vec<NavigationTarget>> { pub fn child_modules(&self, position: FilePosition) -> Cancellable<Vec<NavigationTarget>> {
self.with_db(|db| children_modules::children_modules(db, position)) self.with_db(|db| child_modules::child_modules(db, position))
} }
/// Returns crates that this file belongs to. /// Returns crates that this file belongs to.

View File

@ -943,14 +943,14 @@ pub(crate) fn handle_parent_module(
Ok(Some(res)) Ok(Some(res))
} }
pub(crate) fn handle_children_modules( pub(crate) fn handle_child_modules(
snap: GlobalStateSnapshot, snap: GlobalStateSnapshot,
params: lsp_types::TextDocumentPositionParams, params: lsp_types::TextDocumentPositionParams,
) -> anyhow::Result<Option<lsp_types::GotoDefinitionResponse>> { ) -> anyhow::Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = tracing::info_span!("handle_children_module").entered(); let _p = tracing::info_span!("handle_child_modules").entered();
// locate children module by semantics // locate child module by semantics
let position = try_default!(from_proto::file_position(&snap, params)?); let position = try_default!(from_proto::file_position(&snap, params)?);
let navs = snap.analysis.children_modules(position)?; let navs = snap.analysis.child_modules(position)?;
let res = to_proto::goto_definition_response(&snap, None, navs)?; let res = to_proto::goto_definition_response(&snap, None, navs)?;
Ok(Some(res)) Ok(Some(res))
} }

View File

@ -157,7 +157,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
"onEnter": true, "onEnter": true,
"openCargoToml": true, "openCargoToml": true,
"parentModule": true, "parentModule": true,
"childrenModules": true, "childModules": true,
"runnables": { "runnables": {
"kinds": [ "cargo" ], "kinds": [ "cargo" ],
}, },

View File

@ -399,12 +399,12 @@ impl Request for ParentModule {
const METHOD: &'static str = "experimental/parentModule"; const METHOD: &'static str = "experimental/parentModule";
} }
pub enum ChildrenModules {} pub enum ChildModules {}
impl Request for ChildrenModules { impl Request for ChildModules {
type Params = lsp_types::TextDocumentPositionParams; type Params = lsp_types::TextDocumentPositionParams;
type Result = Option<lsp_types::GotoDefinitionResponse>; type Result = Option<lsp_types::GotoDefinitionResponse>;
const METHOD: &'static str = "experimental/childrenModule"; const METHOD: &'static str = "experimental/childModules";
} }
pub enum JoinLines {} pub enum JoinLines {}

View File

@ -1172,7 +1172,7 @@ impl GlobalState {
.on::<NO_RETRY, lsp_ext::InterpretFunction>(handlers::handle_interpret_function) .on::<NO_RETRY, lsp_ext::InterpretFunction>(handlers::handle_interpret_function)
.on::<NO_RETRY, lsp_ext::ExpandMacro>(handlers::handle_expand_macro) .on::<NO_RETRY, lsp_ext::ExpandMacro>(handlers::handle_expand_macro)
.on::<NO_RETRY, lsp_ext::ParentModule>(handlers::handle_parent_module) .on::<NO_RETRY, lsp_ext::ParentModule>(handlers::handle_parent_module)
.on::<NO_RETRY, lsp_ext::ChildrenModules>(handlers::handle_children_modules) .on::<NO_RETRY, lsp_ext::ChildModules>(handlers::handle_child_modules)
.on::<NO_RETRY, lsp_ext::Runnables>(handlers::handle_runnables) .on::<NO_RETRY, lsp_ext::Runnables>(handlers::handle_runnables)
.on::<NO_RETRY, lsp_ext::RelatedTests>(handlers::handle_related_tests) .on::<NO_RETRY, lsp_ext::RelatedTests>(handlers::handle_related_tests)
.on::<NO_RETRY, lsp_ext::CodeActionRequest>(handlers::handle_code_action) .on::<NO_RETRY, lsp_ext::CodeActionRequest>(handlers::handle_code_action)

View File

@ -1,5 +1,5 @@
<!--- <!---
lsp/ext.rs hash: 300b4be5841cee6f lsp/ext.rs hash: 78e87a78de8f288e
If you need to change the above hash to make the test pass, please check if you If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue: need to adjust this doc as well and ping this issue:

View File

@ -171,8 +171,8 @@
"category": "rust-analyzer" "category": "rust-analyzer"
}, },
{ {
"command": "rust-analyzer.childrenModules", "command": "rust-analyzer.childModules",
"title": "Locate children modules", "title": "Locate child modules",
"category": "rust-analyzer" "category": "rust-analyzer"
}, },
{ {
@ -3379,7 +3379,7 @@
"when": "inRustProject" "when": "inRustProject"
}, },
{ {
"command": "rust-analyzer.childrenModule", "command": "rust-analyzer.childModules",
"when": "inRustProject" "when": "inRustProject"
}, },
{ {

View File

@ -266,7 +266,7 @@ export function parentModule(ctx: CtxInit): Cmd {
}; };
} }
export function childrenModules(ctx: CtxInit): Cmd { export function childModules(ctx: CtxInit): Cmd {
return async () => { return async () => {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
if (!editor) return; if (!editor) return;
@ -274,7 +274,7 @@ export function childrenModules(ctx: CtxInit): Cmd {
const client = ctx.client; const client = ctx.client;
const locations = await client.sendRequest(ra.childrenModules, { const locations = await client.sendRequest(ra.childModules, {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
position: client.code2ProtocolConverter.asPosition(editor.selection.active), position: client.code2ProtocolConverter.asPosition(editor.selection.active),
}); });

View File

@ -194,11 +194,11 @@ export const parentModule = new lc.RequestType<
lc.LocationLink[] | null, lc.LocationLink[] | null,
void void
>("experimental/parentModule"); >("experimental/parentModule");
export const childrenModules = new lc.RequestType< export const childModules = new lc.RequestType<
lc.TextDocumentPositionParams, lc.TextDocumentPositionParams,
lc.LocationLink[] | null, lc.LocationLink[] | null,
void void
>("experimental/childrenModule"); >("experimental/childModules");
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>( export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
"experimental/runnables", "experimental/runnables",
); );

View File

@ -158,7 +158,7 @@ function createCommands(): Record<string, CommandFactory> {
matchingBrace: { enabled: commands.matchingBrace }, matchingBrace: { enabled: commands.matchingBrace },
joinLines: { enabled: commands.joinLines }, joinLines: { enabled: commands.joinLines },
parentModule: { enabled: commands.parentModule }, parentModule: { enabled: commands.parentModule },
childrenModules: { enabled: commands.childrenModules }, childModules: { enabled: commands.childModules },
viewHir: { enabled: commands.viewHir }, viewHir: { enabled: commands.viewHir },
viewMir: { enabled: commands.viewMir }, viewMir: { enabled: commands.viewMir },
interpretFunction: { enabled: commands.interpretFunction }, interpretFunction: { enabled: commands.interpretFunction },
@ -188,7 +188,9 @@ function createCommands(): Record<string, CommandFactory> {
openWalkthrough: { enabled: commands.openWalkthrough }, openWalkthrough: { enabled: commands.openWalkthrough },
// Internal commands which are invoked by the server. // Internal commands which are invoked by the server.
applyActionGroup: { enabled: commands.applyActionGroup }, applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand }, applySnippetWorkspaceEdit: {
enabled: commands.applySnippetWorkspaceEditCommand,
},
debugSingle: { enabled: commands.debugSingle }, debugSingle: { enabled: commands.debugSingle },
gotoLocation: { enabled: commands.gotoLocation }, gotoLocation: { enabled: commands.gotoLocation },
hoverRefCommandProxy: { enabled: commands.hoverRefCommandProxy }, hoverRefCommandProxy: { enabled: commands.hoverRefCommandProxy },
@ -201,8 +203,12 @@ function createCommands(): Record<string, CommandFactory> {
revealDependency: { enabled: commands.revealDependency }, revealDependency: { enabled: commands.revealDependency },
syntaxTreeReveal: { enabled: commands.syntaxTreeReveal }, syntaxTreeReveal: { enabled: commands.syntaxTreeReveal },
syntaxTreeCopy: { enabled: commands.syntaxTreeCopy }, syntaxTreeCopy: { enabled: commands.syntaxTreeCopy },
syntaxTreeHideWhitespace: { enabled: commands.syntaxTreeHideWhitespace }, syntaxTreeHideWhitespace: {
syntaxTreeShowWhitespace: { enabled: commands.syntaxTreeShowWhitespace }, enabled: commands.syntaxTreeHideWhitespace,
},
syntaxTreeShowWhitespace: {
enabled: commands.syntaxTreeShowWhitespace,
},
}; };
} }