aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-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 })