aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-01 17:51:16 +0100
committerAleksey Kladov <[email protected]>2020-04-01 17:51:16 +0100
commit4936abdd49b1d0ba6b2a858bee3a5a665de9d6f3 (patch)
treebd71ed664cb86aa8f3a33896a2ee36e11f17cd50 /crates/ra_project_model/src
parente870cbc23d78f5bc424983b1d9ef945888f9dc49 (diff)
Reduce scope of deserialization
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs20
-rw-r--r--crates/ra_project_model/src/lib.rs6
2 files changed, 11 insertions, 15 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 91735a726..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,10 +42,8 @@ impl ops::Index<Target> for CargoWorkspace {
43 } 42 }
44} 43}
45 44
46// TODO: rename to CargoConfig, kill `rename_all`, kill serde dep? 45#[derive(Clone, Debug, PartialEq, Eq)]
47#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] 46pub struct CargoConfig {
48#[serde(rename_all = "camelCase", default)]
49pub struct CargoFeatures {
50 /// Do not activate the `default` feature. 47 /// Do not activate the `default` feature.
51 pub no_default_features: bool, 48 pub no_default_features: bool,
52 49
@@ -61,9 +58,9 @@ pub struct CargoFeatures {
61 pub load_out_dirs_from_check: bool, 58 pub load_out_dirs_from_check: bool,
62} 59}
63 60
64impl Default for CargoFeatures { 61impl Default for CargoConfig {
65 fn default() -> Self { 62 fn default() -> Self {
66 CargoFeatures { 63 CargoConfig {
67 no_default_features: false, 64 no_default_features: false,
68 all_features: true, 65 all_features: true,
69 features: Vec::new(), 66 features: Vec::new(),
@@ -142,7 +139,7 @@ impl PackageData {
142impl CargoWorkspace { 139impl CargoWorkspace {
143 pub fn from_cargo_metadata( 140 pub fn from_cargo_metadata(
144 cargo_toml: &Path, 141 cargo_toml: &Path,
145 cargo_features: &CargoFeatures, 142 cargo_features: &CargoConfig,
146 ) -> Result<CargoWorkspace> { 143 ) -> Result<CargoWorkspace> {
147 let mut meta = MetadataCommand::new(); 144 let mut meta = MetadataCommand::new();
148 meta.manifest_path(cargo_toml); 145 meta.manifest_path(cargo_toml);
@@ -276,7 +273,7 @@ pub struct ExternResources {
276 273
277pub fn load_extern_resources( 274pub fn load_extern_resources(
278 cargo_toml: &Path, 275 cargo_toml: &Path,
279 cargo_features: &CargoFeatures, 276 cargo_features: &CargoConfig,
280) -> Result<ExternResources> { 277) -> Result<ExternResources> {
281 let mut cmd = Command::new(cargo_binary()); 278 let mut cmd = Command::new(cargo_binary());
282 cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); 279 cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
@@ -294,9 +291,8 @@ pub fn load_extern_resources(
294 291
295 let mut res = ExternResources::default(); 292 let mut res = ExternResources::default();
296 293
297 let stdout = String::from_utf8(output.stdout)?; 294 for message in cargo_metadata::parse_messages(output.stdout.as_slice()) {
298 for line in stdout.lines() { 295 if let Ok(message) = message {
299 if let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(&line) {
300 match message { 296 match message {
301 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { 297 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => {
302 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;
19use serde_json::from_reader; 19use serde_json::from_reader;
20 20
21pub use crate::{ 21pub 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
80impl ProjectWorkspace { 80impl 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) => {