Initial implementation of project-lock.json.

This commit adds a initial implementation of project-lock.json, a build
system agnostic method of specifying the crate graph and roots.
This commit is contained in:
David Wood 2019-03-05 22:29:23 +01:00
parent b1a1d20e06
commit 00d927a188
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
9 changed files with 309 additions and 96 deletions

View file

@ -1,5 +1,5 @@
use crate::{
project_model::TargetKind,
project_model::{self, TargetKind},
server_world::ServerWorld,
Result
};
@ -65,14 +65,16 @@ impl CargoTargetSpec {
};
let file_id = world.analysis().crate_root(crate_id)?;
let path = world.vfs.read().file2path(ra_vfs::VfsFile(file_id.0.into()));
let res = world.workspaces.iter().find_map(|ws| {
let tgt = ws.cargo.target_by_root(&path)?;
let res = CargoTargetSpec {
package: tgt.package(&ws.cargo).name(&ws.cargo).to_string(),
target: tgt.name(&ws.cargo).to_string(),
target_kind: tgt.kind(&ws.cargo),
};
Some(res)
let res = world.workspaces.iter().find_map(|ws| match ws {
project_model::ProjectWorkspace::Cargo { cargo, .. } => {
let tgt = cargo.target_by_root(&path)?;
Some(CargoTargetSpec {
package: tgt.package(&cargo).name(&cargo).to_string(),
target: tgt.name(&cargo).to_string(),
target_kind: tgt.kind(&cargo),
})
}
project_model::ProjectWorkspace::Json { .. } => None,
});
Ok(res)
}

View file

@ -40,12 +40,7 @@ impl ServerWorldState {
let mut roots = Vec::new();
roots.push(root.clone());
for ws in workspaces.iter() {
for pkg in ws.cargo.packages() {
roots.push(pkg.root(&ws.cargo).to_path_buf());
}
for krate in ws.sysroot.crates() {
roots.push(krate.root_dir(&ws.sysroot).to_path_buf())
}
ws.add_roots(&mut roots);
}
let (mut vfs, roots) = Vfs::new(roots);
let roots_to_scan = roots.len();
@ -185,7 +180,7 @@ impl ServerWorld {
} else {
res.push_str("workspaces:\n");
for w in self.workspaces.iter() {
res += &format!("{} packages loaded\n", w.cargo.packages().count());
res += &format!("{} packages loaded\n", w.count());
}
}
res.push_str("\nanalysis:\n");