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

Racer now uses rustup to find the stdlib source code even when used as a library. #799

Merged
merged 7 commits into from
Oct 30, 2017

Conversation

golddranks
Copy link
Contributor

@golddranks golddranks commented Sep 23, 2017

Refactored the stdlib source code search a bit: It now stores the path in a lazy_static, and doesn't load it directly from an env var at usage sites. When initializing the lazy_static, it checks both the RUST_SRC_PATH env var and rustup's rust-src component. It used use rustup only when using Racer as a binary. Now it does it even when used as a library.

This allows using RLS without setting RUST_SRC_PATH; it suffices that rustup is installed. Before, it just used to crash if RUST_SRC_PATH wasn't set.

Also got rid of the warnings: converted a few \\\ doc comments that weren't actual item doc comments to \\ normal comments, and got rid of the non-used extern crates that were likely left from when the binary and library were not separated.

@golddranks
Copy link
Contributor Author

This helps with, although doesn't eliminate this: #751

@golddranks
Copy link
Contributor Author

Oops, tests fail because the env_logger was still needed in tests. Fixing!

Copy link
Contributor

@TedDriggs TedDriggs left a comment

Choose a reason for hiding this comment

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

Added comments; most are minor.

Is it possible to include a test for this? I know that the fixtures directory is pretty out-of-date, so if we can't then that's fine.

@@ -0,0 +1,23 @@
use std::path::PathBuf;
Copy link
Contributor

Choose a reason for hiding this comment

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

Having a generic config.rs makes me suspicious; it seems likely that it'll become a parking lot for a bunch of unrelated items. Can you make the name for this more specific to file paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can; however, I originally thought that it would be actually good to have a centralised module for reading any needed configuration from the environment and keeping the state. Do you think it would make sense to move this to nameres.rs where RUST_SRC_PATHS is used?

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 personally a fan of smaller, purpose-oriented modules, so I'd suggest one that only contained this and have that be used by nameres. However, I'm fine with it living in nameres.rs directly for the time-being.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, I'll refactor that.

/// Test if the **path expression** starts with `::`, in which case the path
/// should be checked against the global namespace rather than the items currently
/// in scope.
// Test if the **path expression** starts with `::`, in which case the path
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning these up; it makes me sad to lose the ability to add doc comments to locals and have them show up in completions, but the rustdoc team has spoken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did they actually consider that use case? It might be that they just missed it, and deprecated this as an useless thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

They considered it; I asked them about it, which was what prompted the discussion which ended in deprecation.

@@ -11,13 +11,9 @@ use matchers::find_doc;
use cargo;
use std::path::{Path, PathBuf};
use std::{self, vec};
use std::iter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you combine this with the use on the previous line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aye.

let srcpaths = match std::env::var("RUST_SRC_PATH") {
Ok(paths) => paths,
Err(_) => return out.into_iter()
if config::RUST_SRC_PATHS.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change makes the comment above inaccurate; can you please update it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@golddranks
Copy link
Contributor Author

What is the purpose of the fixtures directory?

@golddranks
Copy link
Contributor Author

Ping @TedDriggs , in case you didn't notice my updates and question.

@TedDriggs
Copy link
Contributor

What is the purpose of the fixtures directory?

I actually don't know, but I got the impression that it was supposed to do something around environment tests like this.

@jwilm
Copy link
Collaborator

jwilm commented Oct 3, 2017

The fixtures directory has projects for tests. It allows us to test very specific setups; although, it hasn't gotten much use outside of 1-2 tests.

@golddranks
Copy link
Contributor Author

Since there was a TODO comment that indicated that a more thorough refactoring might be good, I went ahead and did that.

It now resolves to a single path using multiple sources (the env var, rustup and default path list) that is verified to contain the stdlib source.

Also added tests.

@golddranks
Copy link
Contributor Author

I'd very much appreciate if, when this gets pulled in, a new version of Racer would be released; updating RLS to use the new version, it would make RLS setup one step easier.

@golddranks
Copy link
Contributor Author

The Windows build fails the test that uses rustup to get the path. Is rustup present on Windows? And does it work similarly than on macOS, which is the system I'm using?

@TedDriggs
Copy link
Contributor

The Windows build seems to work on all but one architecture, so I don't think it's a problem with the AppVeyor config.

@golddranks
Copy link
Contributor Author

All right, all requested changes are done (Although Github claims otherwise) and tests are passing.

@golddranks
Copy link
Contributor Author

Friendly ping to @TedDriggs . This PR is waiting for a (hopefylly) final review for merge.

}
assert!(get_rust_src_path().is_ok());

match original {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: You could create a struct, that stores the original RUST_SRC_PATH and implement Drop. If drop is called, you would reset to the original env var. This could reduce some code duplication in the tests :)

Copy link
Contributor

@TedDriggs TedDriggs left a comment

Choose a reason for hiding this comment

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

LGTM. If @jwilm is happy then we can go ahead and merge.

@golddranks
Copy link
Contributor Author

Ping @jwilm , is there anything I can do to make this go forward?

@golddranks
Copy link
Contributor Author

@TedDriggs is there any other maintainers that could approve of this?

@jwilm jwilm merged commit cd80078 into racer-rust:master Oct 30, 2017
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