Skip to content

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

Merged
merged 1 commit into from
Dec 31, 2018

Conversation

farodin91
Copy link
Contributor

@farodin91 farodin91 commented Oct 28, 2018

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.

@matklad
Copy link
Member

matklad commented Oct 30, 2018

The main problem is that module_tree only supports FileId and not Module in files.

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.

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from 3fa32cc to 09b7adc Compare October 30, 2018 22:04
@farodin91
Copy link
Contributor Author

I would like to making the command line a bit better by adding the package. Any idea? To get crate name of a file.

@matklad
Copy link
Member

matklad commented Oct 30, 2018

I would like to making the command line a bit better by adding the package.

I think this line should add the neccessary --package foo --test bar arguments:
https://github.com/rust-analyzer/rust-analyzer/pull/165/files#diff-57a6a05c79db4a0461f95762e92206d3R314

@farodin91
Copy link
Contributor Author

@matklad
Copy link
Member

matklad commented Oct 31, 2018

@farodin91 yep, I've linked the wrong line

@matklad
Copy link
Member

matklad commented Nov 5, 2018

@farodin91 #193 adds inline modules to the module tree

@aochagavia
Copy link
Contributor

Besides rebasing, what needs to happen so this PR can be merged?

@farodin91
Copy link
Contributor Author

The rebase is a bit complexer.

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from 09b7adc to cdde466 Compare November 12, 2018 19:57
@farodin91
Copy link
Contributor Author

farodin91 commented Nov 12, 2018

@matklad The module parent function seems to behave wrong. test_resolve_parent_module_for_inline_to_lib it returns the current mod.
I tried to resolve this problem, but i'm not sure what the problem is.


loop {
println!("current_position {:?}", current_position);
if let Some((file_id, file_symbol)) = self.parent_module(current_position)?.first() {
Copy link
Member

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:

https://github.com/rust-analyzer/rust-analyzer/blob/923483e321acace3bbf38688bd70d4d38f49b35e/crates/ra_analysis/src/descriptors/module/mod.rs#L82

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from cdde466 to da79637 Compare November 26, 2018 22:20
@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from da79637 to 13b7985 Compare December 27, 2018 20:45
@matklad
Copy link
Member

matklad commented Dec 30, 2018

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!

Copy link
Contributor

@DJMcNab DJMcNab left a 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

@@ -184,6 +184,28 @@ impl AnalysisImpl {
};
Ok(query.search(&buf))
}

pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<String> {
Copy link
Contributor

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.

let path = modules
.into_iter()
.filter_map(|s| s.name())
.skip(1)
Copy link
Contributor

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.

let modules = descr.path_to_root();

let path = modules
.into_iter()
Copy link
Member

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.

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from 13b7985 to 9e5a896 Compare December 31, 2018 11:10
let path = modules
.iter()
.filter_map(|s| s.name())
.skip(1) // name is already part of the string.
Copy link
Contributor

@DJMcNab DJMcNab Dec 31, 2018

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.

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from 9e5a896 to 1a46eff Compare December 31, 2018 11:26
@DJMcNab
Copy link
Contributor

DJMcNab commented Dec 31, 2018

bors delegate+

This looks good - all that's missing is you have an extra import.

@bors
Copy link
Contributor

bors bot commented Dec 31, 2018

✌️ farodin91 can now approve this pull request

@farodin91 farodin91 force-pushed the modules-with-tests-runnable branch from 1a46eff to 05daa86 Compare December 31, 2018 14:00
@farodin91
Copy link
Contributor Author

bors r+

bors bot added a commit that referenced this pull request Dec 31, 2018
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]>
@bors
Copy link
Contributor

bors bot commented Dec 31, 2018

Build succeeded

And happy new year from bors! 🎉

@bors bors bot merged commit 05daa86 into rust-lang:master Dec 31, 2018
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.

4 participants