"Locate child modules", inverse of the "Locate parent modules" feature
We currently have a feature that allows running a command to open the parent module(s) of a file's corresponding modules. We should have the inverse of this, opening a popup with the selection of all direct children modules of the currently open file's module(s).
See https://github.com/rust-lang/rust-analyzer/blob/4af21ffb026c7ec3a97a484ca27b36f703eb5fb1/crates/ide/src/parent_module.rs for the parent module implementation, you should be able to trace how this is used to know what to edit to add a similar feature.
This will need an lsp-extension like https://github.com/veykril/rust-analyzer/blob/4af21ffb026c7ec3a97a484ca27b36f703eb5fb1/crates/rust-analyzer/src/lsp/ext.rs#L389-L395 and vscode glue like https://github.com/rust-lang/rust-analyzer/blob/4af21ffb026c7ec3a97a484ca27b36f703eb5fb1/editors/code/src/lsp_ext.ts#L188-L192
Hello @Veykril, I would like to work on it!
Hi I would like to work on this.
After reading parent_module code I found that find_node_at_offset return the ancestor modules which contains the sourcefile.
For the Locate child modules feature we want to get the children which are of type Module. Am I correct here?
If yes then I just have to check sourcefile.descendants and filter out modules from this list?
what would be the output in the following cases?
//- /lib.rs $0 mod foo;
is the ans foo here?
//- /lib.rs
mod foo {
mod bar {
mod $0baz {}
}
}
is the ans baz here?
//- /lib.rs
$0
mod foo {
mod bar {
mod baz {}
}
}
is the ans foo here?
Once you have the hir::Module of the current file you can iterate its children via its children method
what would be the output in the following cases?
//- /lib.rs $0 mod foo;
is the ans
foohere?
Yes sounds reasonable
//- /lib.rs mod foo { mod bar { mod $0baz {} } }
is the ans
bazhere? Yes sounds reasonable
//- /lib.rs $0 mod foo { mod bar { mod baz {} } }
is the ans
foohere?
Yes
Basically just one level of modules, no more
Implemented in #19255.