This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
Allow project model to download crates #1020
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
54e5273
Allow project model to download crates
kngwyu bf66a15
Enable completion in test/example dir
kngwyu 1efd7c0
Update racer
kngwyu caf2427
Convert - -> _ in libname
kngwyu 746ffb5
Update rustfmt
kngwyu 2ae5662
Change the way to complete self-crate name in tests dir
kngwyu 1352bdf
Add a regression test for completion in test dir
kngwyu a98c9a0
Add a line comment about - to _ conversion
kngwyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/// This module represents the RLS view of the Cargo project model: | ||
/// a graph of interdependent packages. | ||
//! This module represents the RLS view of the Cargo project model: | ||
//! a graph of interdependent packages. | ||
use std::{ | ||
collections::HashMap, | ||
sync::Arc, | ||
|
@@ -20,6 +20,7 @@ use racer; | |
|
||
#[derive(Debug)] | ||
pub struct ProjectModel { | ||
manifest_to_id: HashMap<PathBuf, Package>, | ||
packages: Vec<PackageData>, | ||
} | ||
|
||
|
@@ -28,7 +29,6 @@ pub struct Package(usize); | |
|
||
#[derive(Debug)] | ||
struct PackageData { | ||
manifest: PathBuf, | ||
lib: Option<PathBuf>, | ||
deps: Vec<Dep>, | ||
} | ||
|
@@ -43,8 +43,8 @@ impl ProjectModel { | |
pub fn load(manifest: &Path, vfs: &Vfs) -> Result<ProjectModel, failure::Error> { | ||
assert!(manifest.ends_with("Cargo.toml")); | ||
let mut config = Config::default()?; | ||
// frozen=true, locked=true | ||
config.configure(0, Some(true), &None, true, true, &None, &[])?; | ||
// frozen = false, locked = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
config.configure(0, Some(true), &None, false, false, &None, &[])?; | ||
let ws = Workspace::new(&manifest, &config)?; | ||
// get resolve from lock file | ||
let prev = { | ||
|
@@ -55,26 +55,28 @@ impl ProjectModel { | |
let v: EncodableResolve = resolve.try_into()?; | ||
Some(v.into_resolve(&ws)?) | ||
} | ||
_ => None | ||
_ => None, | ||
} | ||
}; | ||
// then resolve precisely and add overrides | ||
let mut registry = PackageRegistry::new(ws.config())?; | ||
let resolve = resolve_with_prev(&mut registry, &ws, prev.as_ref())?; | ||
let cargo_packages = { | ||
let ids: Vec<PackageId> = resolve.iter().cloned().collect(); | ||
registry.get(&ids) | ||
}; | ||
|
||
let mut pkg_id_to_pkg = HashMap::new(); | ||
let mut manifest_to_id = HashMap::new(); | ||
let mut packages = Vec::new(); | ||
for (idx, pkg_id) in resolve.iter().enumerate() { | ||
let pkg = Package(idx); | ||
pkg_id_to_pkg.insert(pkg_id.clone(), pkg); | ||
let cargo_pkg = cargo_packages.get(pkg_id)?; | ||
let manifest = cargo_pkg.manifest_path().to_owned(); | ||
manifest_to_id.insert(manifest, pkg); | ||
packages.push(PackageData { | ||
manifest: cargo_pkg.manifest_path().to_owned(), | ||
lib: cargo_pkg.targets().iter() | ||
lib: cargo_pkg | ||
.targets() | ||
.iter() | ||
.find(|t| t.is_lib()) | ||
.map(|t| t.src_path().to_owned()), | ||
deps: Vec::new(), | ||
|
@@ -99,20 +101,19 @@ impl ProjectModel { | |
} | ||
} | ||
} | ||
Ok(ProjectModel { packages }) | ||
Ok(ProjectModel { | ||
manifest_to_id, | ||
packages, | ||
}) | ||
} | ||
|
||
pub fn package_for_manifest(&self, manifest_path: &Path) -> Option<Package> { | ||
self.packages.iter() | ||
.enumerate() | ||
.find(|(_idx, p)| p.manifest == manifest_path) | ||
.map(|(idx, _p)| Package(idx)) | ||
self.manifest_to_id.get(manifest_path).map(|&x| x) | ||
} | ||
|
||
fn get(&self, pkg: Package) -> &PackageData { | ||
&self.packages[pkg.0] | ||
} | ||
|
||
} | ||
|
||
impl Package { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍