diff options
Diffstat (limited to 'crates/project_model/src/cargo_workspace.rs')
-rw-r--r-- | crates/project_model/src/cargo_workspace.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index 1d8d34a0b..bc6e20341 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::path::PathBuf; | ||
3 | use std::{convert::TryInto, ops, process::Command, sync::Arc}; | 4 | use std::{convert::TryInto, ops, process::Command, sync::Arc}; |
4 | 5 | ||
5 | use anyhow::{Context, Result}; | 6 | use anyhow::{Context, Result}; |
@@ -8,6 +9,8 @@ use cargo_metadata::{CargoOpt, MetadataCommand}; | |||
8 | use la_arena::{Arena, Idx}; | 9 | use la_arena::{Arena, Idx}; |
9 | use paths::{AbsPath, AbsPathBuf}; | 10 | use paths::{AbsPath, AbsPathBuf}; |
10 | use rustc_hash::FxHashMap; | 11 | use rustc_hash::FxHashMap; |
12 | use serde::Deserialize; | ||
13 | use serde_json::from_value; | ||
11 | 14 | ||
12 | use crate::build_data::BuildDataConfig; | 15 | use crate::build_data::BuildDataConfig; |
13 | use crate::utf8_stdout; | 16 | use crate::utf8_stdout; |
@@ -103,6 +106,13 @@ pub struct PackageData { | |||
103 | pub active_features: Vec<String>, | 106 | pub active_features: Vec<String>, |
104 | // String representation of package id | 107 | // String representation of package id |
105 | pub id: String, | 108 | pub id: String, |
109 | // The contents of [package.metadata.rust-analyzer] | ||
110 | pub metadata: RustAnalyzerPackageMetaData, | ||
111 | } | ||
112 | |||
113 | #[derive(Deserialize, Default, Debug, Clone, Eq, PartialEq)] | ||
114 | pub struct RustAnalyzerPackageMetaData { | ||
115 | pub rustc_private: bool, | ||
106 | } | 116 | } |
107 | 117 | ||
108 | #[derive(Debug, Clone, Eq, PartialEq)] | 118 | #[derive(Debug, Clone, Eq, PartialEq)] |
@@ -160,6 +170,13 @@ impl PackageData { | |||
160 | } | 170 | } |
161 | } | 171 | } |
162 | 172 | ||
173 | #[derive(Deserialize, Default)] | ||
174 | // Deserialise helper for the cargo metadata | ||
175 | struct PackageMetadata { | ||
176 | #[serde(rename = "rust-analyzer")] | ||
177 | rust_analyzer: Option<RustAnalyzerPackageMetaData>, | ||
178 | } | ||
179 | |||
163 | impl CargoWorkspace { | 180 | impl CargoWorkspace { |
164 | pub fn from_cargo_metadata( | 181 | pub fn from_cargo_metadata( |
165 | cargo_toml: &AbsPath, | 182 | cargo_toml: &AbsPath, |
@@ -243,23 +260,27 @@ impl CargoWorkspace { | |||
243 | 260 | ||
244 | meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); | 261 | meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); |
245 | for meta_pkg in &meta.packages { | 262 | for meta_pkg in &meta.packages { |
246 | let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } = | 263 | let cargo_metadata::Package { |
247 | meta_pkg; | 264 | id, edition, name, manifest_path, version, metadata, .. |
265 | } = meta_pkg; | ||
266 | let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default(); | ||
248 | let is_member = ws_members.contains(&id); | 267 | let is_member = ws_members.contains(&id); |
249 | let edition = edition | 268 | let edition = edition |
250 | .parse::<Edition>() | 269 | .parse::<Edition>() |
251 | .with_context(|| format!("Failed to parse edition {}", edition))?; | 270 | .with_context(|| format!("Failed to parse edition {}", edition))?; |
271 | |||
252 | let pkg = packages.alloc(PackageData { | 272 | let pkg = packages.alloc(PackageData { |
253 | id: id.repr.clone(), | 273 | id: id.repr.clone(), |
254 | name: name.clone(), | 274 | name: name.clone(), |
255 | version: version.to_string(), | 275 | version: version.to_string(), |
256 | manifest: AbsPathBuf::assert(manifest_path.clone()), | 276 | manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)), |
257 | targets: Vec::new(), | 277 | targets: Vec::new(), |
258 | is_member, | 278 | is_member, |
259 | edition, | 279 | edition, |
260 | dependencies: Vec::new(), | 280 | dependencies: Vec::new(), |
261 | features: meta_pkg.features.clone().into_iter().collect(), | 281 | features: meta_pkg.features.clone().into_iter().collect(), |
262 | active_features: Vec::new(), | 282 | active_features: Vec::new(), |
283 | metadata: meta.rust_analyzer.unwrap_or_default(), | ||
263 | }); | 284 | }); |
264 | let pkg_data = &mut packages[pkg]; | 285 | let pkg_data = &mut packages[pkg]; |
265 | pkg_by_id.insert(id, pkg); | 286 | pkg_by_id.insert(id, pkg); |
@@ -268,7 +289,7 @@ impl CargoWorkspace { | |||
268 | let tgt = targets.alloc(TargetData { | 289 | let tgt = targets.alloc(TargetData { |
269 | package: pkg, | 290 | package: pkg, |
270 | name: meta_tgt.name.clone(), | 291 | name: meta_tgt.name.clone(), |
271 | root: AbsPathBuf::assert(meta_tgt.src_path.clone()), | 292 | root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)), |
272 | kind: TargetKind::new(meta_tgt.kind.as_slice()), | 293 | kind: TargetKind::new(meta_tgt.kind.as_slice()), |
273 | is_proc_macro, | 294 | is_proc_macro, |
274 | }); | 295 | }); |
@@ -305,7 +326,8 @@ impl CargoWorkspace { | |||
305 | packages[source].active_features.extend(node.features); | 326 | packages[source].active_features.extend(node.features); |
306 | } | 327 | } |
307 | 328 | ||
308 | let workspace_root = AbsPathBuf::assert(meta.workspace_root); | 329 | let workspace_root = |
330 | AbsPathBuf::assert(PathBuf::from(meta.workspace_root.into_os_string())); | ||
309 | let build_data_config = BuildDataConfig::new( | 331 | let build_data_config = BuildDataConfig::new( |
310 | cargo_toml.to_path_buf(), | 332 | cargo_toml.to_path_buf(), |
311 | config.clone(), | 333 | config.clone(), |