mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
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:
parent
b1a1d20e06
commit
00d927a188
9 changed files with 309 additions and 96 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue