diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 19 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 6 |
2 files changed, 11 insertions, 14 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index f4fd6ad28..c1b6e1ddc 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -13,7 +13,6 @@ use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId} | |||
13 | use ra_arena::{Arena, Idx}; | 13 | use ra_arena::{Arena, Idx}; |
14 | use ra_db::Edition; | 14 | use ra_db::Edition; |
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
16 | use serde::Deserialize; | ||
17 | 16 | ||
18 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo | 17 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo |
19 | /// workspace. It pretty closely mirrors `cargo metadata` output. | 18 | /// workspace. It pretty closely mirrors `cargo metadata` output. |
@@ -43,9 +42,8 @@ impl ops::Index<Target> for CargoWorkspace { | |||
43 | } | 42 | } |
44 | } | 43 | } |
45 | 44 | ||
46 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] | 45 | #[derive(Clone, Debug, PartialEq, Eq)] |
47 | #[serde(rename_all = "camelCase", default)] | 46 | pub struct CargoConfig { |
48 | pub struct CargoFeatures { | ||
49 | /// Do not activate the `default` feature. | 47 | /// Do not activate the `default` feature. |
50 | pub no_default_features: bool, | 48 | pub no_default_features: bool, |
51 | 49 | ||
@@ -60,9 +58,9 @@ pub struct CargoFeatures { | |||
60 | pub load_out_dirs_from_check: bool, | 58 | pub load_out_dirs_from_check: bool, |
61 | } | 59 | } |
62 | 60 | ||
63 | impl Default for CargoFeatures { | 61 | impl Default for CargoConfig { |
64 | fn default() -> Self { | 62 | fn default() -> Self { |
65 | CargoFeatures { | 63 | CargoConfig { |
66 | no_default_features: false, | 64 | no_default_features: false, |
67 | all_features: true, | 65 | all_features: true, |
68 | features: Vec::new(), | 66 | features: Vec::new(), |
@@ -141,7 +139,7 @@ impl PackageData { | |||
141 | impl CargoWorkspace { | 139 | impl CargoWorkspace { |
142 | pub fn from_cargo_metadata( | 140 | pub fn from_cargo_metadata( |
143 | cargo_toml: &Path, | 141 | cargo_toml: &Path, |
144 | cargo_features: &CargoFeatures, | 142 | cargo_features: &CargoConfig, |
145 | ) -> Result<CargoWorkspace> { | 143 | ) -> Result<CargoWorkspace> { |
146 | let mut meta = MetadataCommand::new(); | 144 | let mut meta = MetadataCommand::new(); |
147 | meta.manifest_path(cargo_toml); | 145 | meta.manifest_path(cargo_toml); |
@@ -275,7 +273,7 @@ pub struct ExternResources { | |||
275 | 273 | ||
276 | pub fn load_extern_resources( | 274 | pub fn load_extern_resources( |
277 | cargo_toml: &Path, | 275 | cargo_toml: &Path, |
278 | cargo_features: &CargoFeatures, | 276 | cargo_features: &CargoConfig, |
279 | ) -> Result<ExternResources> { | 277 | ) -> Result<ExternResources> { |
280 | let mut cmd = Command::new(cargo_binary()); | 278 | let mut cmd = Command::new(cargo_binary()); |
281 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); | 279 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); |
@@ -293,9 +291,8 @@ pub fn load_extern_resources( | |||
293 | 291 | ||
294 | let mut res = ExternResources::default(); | 292 | let mut res = ExternResources::default(); |
295 | 293 | ||
296 | let stdout = String::from_utf8(output.stdout)?; | 294 | for message in cargo_metadata::parse_messages(output.stdout.as_slice()) { |
297 | for line in stdout.lines() { | 295 | if let Ok(message) = message { |
298 | if let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(&line) { | ||
299 | match message { | 296 | match message { |
300 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { | 297 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { |
301 | res.out_dirs.insert(package_id, out_dir); | 298 | res.out_dirs.insert(package_id, out_dir); |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 444d3bb3f..dd9c80691 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -19,7 +19,7 @@ use rustc_hash::FxHashMap; | |||
19 | use serde_json::from_reader; | 19 | use serde_json::from_reader; |
20 | 20 | ||
21 | pub use crate::{ | 21 | pub use crate::{ |
22 | cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind}, | 22 | cargo_workspace::{CargoConfig, CargoWorkspace, Package, Target, TargetKind}, |
23 | json_project::JsonProject, | 23 | json_project::JsonProject, |
24 | sysroot::Sysroot, | 24 | sysroot::Sysroot, |
25 | }; | 25 | }; |
@@ -78,14 +78,14 @@ impl PackageRoot { | |||
78 | } | 78 | } |
79 | 79 | ||
80 | impl ProjectWorkspace { | 80 | impl ProjectWorkspace { |
81 | pub fn discover(path: &Path, cargo_features: &CargoFeatures) -> Result<ProjectWorkspace> { | 81 | pub fn discover(path: &Path, cargo_features: &CargoConfig) -> Result<ProjectWorkspace> { |
82 | ProjectWorkspace::discover_with_sysroot(path, true, cargo_features) | 82 | ProjectWorkspace::discover_with_sysroot(path, true, cargo_features) |
83 | } | 83 | } |
84 | 84 | ||
85 | pub fn discover_with_sysroot( | 85 | pub fn discover_with_sysroot( |
86 | path: &Path, | 86 | path: &Path, |
87 | with_sysroot: bool, | 87 | with_sysroot: bool, |
88 | cargo_features: &CargoFeatures, | 88 | cargo_features: &CargoConfig, |
89 | ) -> Result<ProjectWorkspace> { | 89 | ) -> Result<ProjectWorkspace> { |
90 | match find_rust_project_json(path) { | 90 | match find_rust_project_json(path) { |
91 | Some(json_path) => { | 91 | Some(json_path) => { |