aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoro0Ignition0o <[email protected]>2020-03-31 08:39:04 +0100
committero0Ignition0o <[email protected]>2020-03-31 13:43:39 +0100
commit331d1db3174853a435991c9341367c235e89eca4 (patch)
tree84a2bab2fe9c53afb4f7503c68f44610b8f4d2a2
parent668980d8657bd358b83f74e2f54f5e228f7393ed (diff)
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.
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs14
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs2
2 files changed, 15 insertions, 1 deletions
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<TargetData>;
75 75
76#[derive(Debug, Clone)] 76#[derive(Debug, Clone)]
77pub struct PackageData { 77pub struct PackageData {
78 pub id: String,
78 pub name: String, 79 pub name: String,
79 pub manifest: PathBuf, 80 pub manifest: PathBuf,
80 pub targets: Vec<Target>, 81 pub targets: Vec<Target>,
@@ -180,6 +181,7 @@ impl CargoWorkspace {
180 .with_context(|| format!("Failed to parse edition {}", edition))?; 181 .with_context(|| format!("Failed to parse edition {}", edition))?;
181 let pkg = packages.alloc(PackageData { 182 let pkg = packages.alloc(PackageData {
182 name, 183 name,
184 id: id.to_string(),
183 manifest: manifest_path, 185 manifest: manifest_path,
184 targets: Vec::new(), 186 targets: Vec::new(),
185 is_member, 187 is_member,
@@ -249,6 +251,18 @@ impl CargoWorkspace {
249 pub fn workspace_root(&self) -> &Path { 251 pub fn workspace_root(&self) -> &Path {
250 &self.workspace_root 252 &self.workspace_root
251 } 253 }
254
255 pub fn package_flag(&self, package: &PackageData) -> String {
256 if self.is_unique(&*package.name) {
257 package.name.clone()
258 } else {
259 package.id.clone()
260 }
261 }
262
263 fn is_unique(&self, name: &str) -> bool {
264 self.packages.iter().filter(|(_, v)| v.name == name).count() == 1
265 }
252} 266}
253 267
254#[derive(Debug, Clone, Default)] 268#[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 {
77 ProjectWorkspace::Cargo { cargo, .. } => { 77 ProjectWorkspace::Cargo { cargo, .. } => {
78 let tgt = cargo.target_by_root(&path)?; 78 let tgt = cargo.target_by_root(&path)?;
79 Some(CargoTargetSpec { 79 Some(CargoTargetSpec {
80 package: cargo[cargo[tgt].package].name.clone(), 80 package: cargo.package_flag(&cargo[cargo[tgt].package]),
81 target: cargo[tgt].name.clone(), 81 target: cargo[tgt].name.clone(),
82 target_kind: cargo[tgt].kind, 82 target_kind: cargo[tgt].kind,
83 }) 83 })