aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
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)]