Skip to content

"Locate child modules", inverse of the "Locate parent modules" feature #17401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Veykril opened this issue Jun 12, 2024 · 7 comments
Closed

"Locate child modules", inverse of the "Locate parent modules" feature #17401

Veykril opened this issue Jun 12, 2024 · 7 comments
Labels
A-ide general IDE features A-lsp LSP conformance issues and missing features C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@Veykril
Copy link
Member

Veykril commented Jun 12, 2024

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

export const parentModule = new lc.RequestType<
lc.TextDocumentPositionParams,
lc.LocationLink[] | null,
void
>("experimental/parentModule");

@Veykril Veykril added E-has-instructions Issue has some instructions and pointers to code to get started C-feature Category: feature request A-lsp LSP conformance issues and missing features A-ide general IDE features labels Jun 12, 2024
@randomicon00
Copy link
Contributor

randomicon00 commented Jun 14, 2024

Hello @Veykril, I would like to work on it!

@geetanshjuneja
Copy link
Contributor

Hi I would like to work on this.

@geetanshjuneja
Copy link
Contributor

geetanshjuneja commented Mar 1, 2025

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?

@geetanshjuneja
Copy link
Contributor

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?

@Veykril
Copy link
Member Author

Veykril commented Mar 1, 2025

Once you have the hir::Module of the current file you can iterate its children via its children method

@Veykril
Copy link
Member Author

Veykril commented Mar 1, 2025

what would be the output in the following cases?

//- /lib.rs $0 mod foo;

is the ans foo here?

Yes sounds reasonable

//- /lib.rs mod foo { mod bar { mod $0baz {} } }

is the ans baz here?
Yes sounds reasonable

//- /lib.rs $0 mod foo { mod bar { mod baz {} } }

is the ans foo here?

Yes

Basically just one level of modules, no more

@lnicola
Copy link
Member

lnicola commented Apr 14, 2025

Implemented in #19255.

@lnicola lnicola closed this as completed Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features A-lsp LSP conformance issues and missing features C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

No branches or pull requests

4 participants