From 331d1db3174853a435991c9341367c235e89eca4 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Tue, 31 Mar 2020 09:39:04 +0200 Subject: Add crate versions when running cargo -p commands. Until now cargo commands with the -p flag would pass the package name only. It doesn't play super well with the toml Renaming dependencies feature. This commit specifies the package name and version when a cargo command is run with the -p flag, to avoid ambiguities. --- crates/ra_project_model/src/cargo_workspace.rs | 14 ++++++++++++++ crates/rust-analyzer/src/cargo_target_spec.rs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 291594e2a..738fd6f61 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -75,6 +75,7 @@ pub type Target = Idx; #[derive(Debug, Clone)] pub struct PackageData { + pub id: String, pub name: String, pub manifest: PathBuf, pub targets: Vec, @@ -180,6 +181,7 @@ impl CargoWorkspace { .with_context(|| format!("Failed to parse edition {}", edition))?; let pkg = packages.alloc(PackageData { name, + id: id.to_string(), manifest: manifest_path, targets: Vec::new(), is_member, @@ -249,6 +251,18 @@ impl CargoWorkspace { pub fn workspace_root(&self) -> &Path { &self.workspace_root } + + pub fn package_flag(&self, package: &PackageData) -> String { + if self.is_unique(&*package.name) { + package.name.clone() + } else { + package.id.clone() + } + } + + fn is_unique(&self, name: &str) -> bool { + self.packages.iter().filter(|(_, v)| v.name == name).count() == 1 + } } #[derive(Debug, Clone, Default)] diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index f87bdcec5..942c30328 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs @@ -77,7 +77,7 @@ impl CargoTargetSpec { ProjectWorkspace::Cargo { cargo, .. } => { let tgt = cargo.target_by_root(&path)?; Some(CargoTargetSpec { - package: cargo[cargo[tgt].package].name.clone(), + package: cargo.package_flag(&cargo[cargo[tgt].package]), target: cargo[tgt].name.clone(), target_kind: cargo[tgt].kind, }) -- cgit v1.2.3