-
Notifications
You must be signed in to change notification settings - Fork 256
Allow project model to download crates #1020
Conversation
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.
LGTM!
I wonder if the racer might have the same issue? I've originally copied this code from racer, but maybe I've messed up smth along the way :D
@@ -20,6 +20,7 @@ use racer; | |||
|
|||
#[derive(Debug)] | |||
pub struct ProjectModel { | |||
manifest_to_id: HashMap<PathBuf, Package>, |
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.
👍
@matklad |
Now I noticed racer sometimes throws package query for stdlib, which causes unintended behavior. |
Yep, |
src/project_model.rs
Outdated
@@ -22,6 +22,7 @@ use racer; | |||
pub struct ProjectModel { | |||
manifest_to_id: HashMap<PathBuf, Package>, | |||
packages: Vec<PackageData>, | |||
current_lib: Option<(String, PathBuf)>, |
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.
current_lib
seems like it shouldn't be here ideally? Like, project model is for worksapce, and workspace contains many libraries, none of which is primary or current.
Perhaps some other code should be adjusted to specify the package?
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 see 🤔
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 changed to just have all package's name, so that we can match libname to current package name.
To reduce compile time in CI
I think now it's ready.
|
@@ -28,8 +29,7 @@ pub struct Package(usize); | |||
|
|||
#[derive(Debug)] | |||
struct PackageData { | |||
manifest: PathBuf, | |||
lib: Option<PathBuf>, | |||
lib: Option<(PathBuf, 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.
This String
doesn't feel exactly right: package itself does not really know its library name: the same pacakge might be used with different names by different dependencies:
# one crate
[dependecies]
bar = { package = "foo"}
# another
[dependecies]
baz = { package = "foo"}
Here, foo
's library is known under the name of bar
or baz
, depending on which package are you asking.
If I understand correctly, we use this mainly for self-dependneices in tests. Perhaps we should adjust Cargo to always include self-dependency? Will try to look into that, but, until than, current solution is actually fine!
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.
OMG, I didn't know cargo is such a complex tool 😲
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, thanks! Left some comments inline.
// frozen=true, locked=true | ||
config.configure(0, Some(true), &None, true, true, &None, &[])?; | ||
let ws = Workspace::new(&manifest, &config)?; | ||
// frozen = false, locked = false |
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.
Note: It's definitely not making things any more worse/more complicated, since we currently https://github.com/rust-lang-nursery/rls/blob/master/src/build/cargo.rs#L572 a Cargo config with defaults (frozen, locked = false) as well.
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.
👍
src/project_model.rs
Outdated
.find(|t| t.is_lib()) | ||
.map(|t| t.src_path().to_owned()), | ||
.map(|t| (t.src_path().to_owned(), t.name().replace('-', "_"))), |
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.
Is this mapping performed because we get a Cargo package name and somehow need to map it to a rust crate name, as Racer would expect to? Could you please add a note why the conversion is necessary?
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.
Is this mapping performed because we get a Cargo package name and somehow need to map it to a rust crate name, as Racer would expect to?
Yes.
I'm going to add some comments.
@matklad re |
@Xanewok cargo metadata uses the usual logic for lockfile update: create if does not exist, if exists, update if Cargo.toml has newer dependencies. |
Okay, thanks. While it seems sensible to do something when there's a mismatch between a lockfile and the manifest, I'm not sure about the part where our @kngwyu meanwhile, if it's something that is reproducible with local path crate dependencies (not sure if we can/should download stuff during Rust CI run), could you also set up a simple regression test under |
I added a test. |
FWIW, IntelliJ Rust calls There was one person who complained about that, so we've added an "auto sync" checkbox for them. |
It'd be great to have this now and we currently use Later on we should vet against and provide an option to enable networking but I'd rather we have deps autocompletion. EDIT: This mostly refers to |
Update RLS and Rustfmt RLS * Allow project model to download crates ([#1020](rust-lang/rls#1020)) * Support simple external builds ([#988](rust-lang/rls#988)) * Support using external Rustfmt ([#990](rust-lang/rls#990)) Rustfmt (0.99.4) * Format chains with comment ([#2899](https://github.com/rust-lang-nursery/rls/pull/2899)) * Do not show wildcard pattern in slice pattern ([#2912](https://github.com/rust-lang-nursery/rls/pull/2912)) * Impl only use ([#2951](https://github.com/rust-lang-nursery/rls/pull/2951)) * ... and [more](rust-lang/rustfmt@5c9a2b6...1c40881) Bumped in tandem to pull a single version of `rustc-ap-*` libs. r? @nrc
Fix #1017
cc: @matklad