aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/cargo_workspace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/cargo_workspace.rs')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs19
1 files changed, 8 insertions, 11 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}
13use ra_arena::{Arena, Idx}; 13use ra_arena::{Arena, Idx};
14use ra_db::Edition; 14use ra_db::Edition;
15use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
16use 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)] 46pub struct CargoConfig {
48pub 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
63impl Default for CargoFeatures { 61impl 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 {
141impl CargoWorkspace { 139impl 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
276pub fn load_extern_resources( 274pub 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);