Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 113 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ languageserver-types = "0.45"
lazy_static = "1"
log = "0.4"
num_cpus = "1"
racer = { version = "2.1.4", default-features = false }
racer = { version = "2.1.5", default-features = false }
rayon = "1"
rls-analysis = "0.16"
rls-blacklist = "0.1.2"
Expand Down
27 changes: 21 additions & 6 deletions src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use racer;
pub struct ProjectModel {
manifest_to_id: HashMap<PathBuf, Package>,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

packages: Vec<PackageData>,
current_lib: Option<(String, PathBuf)>,
Copy link
Contributor

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?

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 see 🤔

Copy link
Contributor Author

@kngwyu kngwyu Aug 27, 2018

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.

}

#[derive(Debug, Clone, Copy)]
Expand All @@ -40,12 +41,12 @@ pub struct Dep {
}

impl ProjectModel {
pub fn load(manifest: &Path, vfs: &Vfs) -> Result<ProjectModel, failure::Error> {
assert!(manifest.ends_with("Cargo.toml"));
pub fn load(current_manifest: &Path, vfs: &Vfs) -> Result<ProjectModel, failure::Error> {
assert!(current_manifest.ends_with("Cargo.toml"));
let mut config = Config::default()?;
// frozen = false, locked = false
Copy link
Contributor

@Xanewok Xanewok Aug 27, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)?;
let ws = Workspace::new(&current_manifest, &config)?;
// get resolve from lock file
let prev = {
let lock_path = ws.root().to_owned().join("Cargo.lock");
Expand All @@ -67,20 +68,27 @@ impl ProjectModel {
let mut pkg_id_to_pkg = HashMap::new();
let mut manifest_to_id = HashMap::new();
let mut packages = Vec::new();
let mut current_lib = None;
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 {
lib: cargo_pkg
.targets()
.iter()
.find(|t| t.is_lib())
.map(|t| t.src_path().to_owned()),
.map(|t| {
let src_path = t.src_path().to_owned();
if manifest == current_manifest {
current_lib = Some((t.name().replace('-', "_"), src_path.clone()));
}
src_path
}),
deps: Vec::new(),
})
});
manifest_to_id.insert(manifest, pkg);
}
for pkg_id in resolve.iter() {
for (dep_id, _) in resolve.deps(&pkg_id) {
Expand All @@ -104,6 +112,7 @@ impl ProjectModel {
Ok(ProjectModel {
manifest_to_id,
packages,
current_lib,
})
}

Expand Down Expand Up @@ -141,6 +150,12 @@ impl racer::ProjectModelProvider for RacerProjectModel {
}
}
fn resolve_dependency(&self, manifest: &Path, libname: &str) -> Option<PathBuf> {
// for completion in tests/examples dir
if let Some(ref current_lib) = self.0.current_lib {
if current_lib.0 == libname {
return Some(current_lib.1.clone());
}
}
let pkg = self.0.package_for_manifest(manifest)?;
let dep = pkg.deps(&self.0)
.iter()
Expand Down