-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Make modules with tests runnable #165
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
Conversation
Yeah, it indeed does not handle modules inside the file for the time being, so it's ok to just write custom code for modules in files. In the future, we need to modify module tree to work uniformly with all modules. |
3fa32cc
to
09b7adc
Compare
I would like to making the command line a bit better by adding the package. Any idea? To get crate name of a file. |
I think this line should add the neccessary |
If i'm correct line https://github.com/rust-analyzer/rust-analyzer/pull/165/files#diff-57a6a05c79db4a0461f95762e92206d3R310 already add the package. |
@farodin91 yep, I've linked the wrong line |
@farodin91 #193 adds inline modules to the module tree |
Besides rebasing, what needs to happen so this PR can be merged? |
The rebase is a bit complexer. |
09b7adc
to
cdde466
Compare
@matklad The module parent function seems to behave wrong. test_resolve_parent_module_for_inline_to_lib it returns the current mod. |
crates/ra_analysis/src/imp.rs
Outdated
|
||
loop { | ||
println!("current_position {:?}", current_position); | ||
if let Some((file_id, file_symbol)) = self.parent_module(current_position)?.first() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, calling Analysis::parent_module
is probably not the right thing to do here: this function is an API function used by LSP to implement "go to super module" feature.
We should add a path_to_root
method to ModuleId
instead, here:
then, we should use this method directly here, but constructing ModuleSource, converting it to ModuleId, etc, like we do in the implementation of Analysis::parent_module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is an API function used by LSP to implement "go to super module" feature.
This explains why, for inline modules, it returns the location of module's own identifier: this mirrors the way it woks for non-inline modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to get a the module name by the ModuleId and it seems a bit problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at #234: it introduces a more OO-flavored API for modules, which hopefully should be easier to use.
In particular, a ModuleDescriptor
now has a ::name
method.
cdde466
to
da79637
Compare
da79637
to
13b7985
Compare
Oups, @farodin91 sorry for the long delay here: GitHub does not send notifications for force-pushes, so I've missed the latest developments. Will take a look soom! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from a few nits and CI failing due to an invalid borrow
crates/ra_analysis/src/imp.rs
Outdated
@@ -184,6 +184,28 @@ impl AnalysisImpl { | |||
}; | |||
Ok(query.search(&buf)) | |||
} | |||
|
|||
pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should return Cancelable<Option<String>>
as opposed to returning Ok("")
in the failure cases.
crates/ra_analysis/src/imp.rs
Outdated
let path = modules | ||
.into_iter() | ||
.filter_map(|s| s.name()) | ||
.skip(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure it's there for a reason, but a comment explaining what skip(1)
does in this case would be useful.
crates/ra_analysis/src/imp.rs
Outdated
let modules = descr.path_to_root(); | ||
|
||
let path = modules | ||
.into_iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this .into_iter()
into .iter()
should fix the borrowing error.
13b7985
to
9e5a896
Compare
let path = modules | ||
.iter() | ||
.filter_map(|s| s.name()) | ||
.skip(1) // name is already part of the string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
EDIT: Maybe we can clarify that it's used as the fold root.
9e5a896
to
1a46eff
Compare
bors delegate+ This looks good - all that's missing is you have an extra import. |
✌️ farodin91 can now approve this pull request |
1a46eff
to
05daa86
Compare
bors r+ |
165: Make modules with tests runnable r=farodin91 a=farodin91 Fixes #154 I having problems to traverse the path to module. The main problem is that module_tree only supports `FileId` and not `Module` in files. Any idea? I need to clean up the code a bit later. Co-authored-by: Jan Jansen <[email protected]>
Build succeededAnd happy new year from bors! 🎉 |
Fixes #154
I having problems to traverse the path to module. The main problem is that module_tree only supports
FileId
and notModule
in files. Any idea?I need to clean up the code a bit later.