Skip to content
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

Return multiple modules in parent_module feature #8028

Merged
merged 2 commits into from Mar 15, 2021

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Mar 15, 2021

No description provided.

@@ -18,8 +19,7 @@ use crate::NavigationTarget;
// | VS Code | **Rust Analyzer: Locate parent module**
// |===

/// This returns `Vec` because a module may be included from several places. We
/// don't handle this case yet though, so the Vec has length at most one.
/// This returns `Vec` because a module may be included from several places.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭

@lnicola
Copy link
Member

lnicola commented Mar 15, 2021

changelog internal prepare for returning parents in the "Locate parent module" command.

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines 261 to +265
pub fn to_module_def(&self, file: FileId) -> Option<Module> {
self.imp.to_module_def(file).next()
}

pub fn to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we should get rid of the first function. It's problematic in that it's not obvious, at the call site, that more than one result can be returned. Although, just returening a vec in call cases seems wrong as well. Rather, the caller probably wants to pass in some kind of predicate object, which is used to select the best possible module.

So, something like fn guess_module_def(file: FiledId, node: &SyntaxNode) might make sens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye was thinking about that as well a bit, getting the predicate/heuristic right seems difficult

@Veykril
Copy link
Member Author

Veykril commented Mar 15, 2021

bors r=matklad

@bors
Copy link
Contributor

bors bot commented Mar 15, 2021

@bors bors bot merged commit d38fd77 into rust-lang:master Mar 15, 2021
@Veykril Veykril deleted the multi-parent branch March 15, 2021 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants