aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
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 /crates/ra_project_model
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.
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs14
1 files changed, 14 insertions, 0 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)]