diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 20 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 6 |
5 files changed, 16 insertions, 21 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} | |||
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,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)] | 46 | pub struct CargoConfig { |
48 | #[serde(rename_all = "camelCase", default)] | ||
49 | pub 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 | ||
64 | impl Default for CargoFeatures { | 61 | impl 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 { | |||
142 | impl CargoWorkspace { | 139 | impl 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 | ||
277 | pub fn load_extern_resources( | 274 | pub 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; | |||
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) => { |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index a3897b728..608f4f67b 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -4,7 +4,6 @@ | |||
4 | mod args; | 4 | mod args; |
5 | 5 | ||
6 | use lsp_server::Connection; | 6 | use lsp_server::Connection; |
7 | |||
8 | use rust_analyzer::{cli, config::Config, from_json, Result}; | 7 | use rust_analyzer::{cli, config::Config, from_json, Result}; |
9 | 8 | ||
10 | use crate::args::HelpPrinted; | 9 | use crate::args::HelpPrinted; |
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 832f04226..2c0bde920 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -8,7 +8,7 @@ use crossbeam_channel::{unbounded, Receiver}; | |||
8 | use ra_db::{ExternSourceId, FileId, SourceRootId}; | 8 | use ra_db::{ExternSourceId, FileId, SourceRootId}; |
9 | use ra_ide::{AnalysisChange, AnalysisHost}; | 9 | use ra_ide::{AnalysisChange, AnalysisHost}; |
10 | use ra_project_model::{ | 10 | use ra_project_model::{ |
11 | get_rustc_cfg_options, CargoFeatures, PackageRoot, ProcMacroClient, ProjectWorkspace, | 11 | get_rustc_cfg_options, CargoConfig, PackageRoot, ProcMacroClient, ProjectWorkspace, |
12 | }; | 12 | }; |
13 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; | 13 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; |
14 | use rustc_hash::{FxHashMap, FxHashSet}; | 14 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -29,7 +29,7 @@ pub(crate) fn load_cargo( | |||
29 | let root = std::env::current_dir()?.join(root); | 29 | let root = std::env::current_dir()?.join(root); |
30 | let ws = ProjectWorkspace::discover( | 30 | let ws = ProjectWorkspace::discover( |
31 | root.as_ref(), | 31 | root.as_ref(), |
32 | &CargoFeatures { load_out_dirs_from_check, ..Default::default() }, | 32 | &CargoConfig { load_out_dirs_from_check, ..Default::default() }, |
33 | )?; | 33 | )?; |
34 | 34 | ||
35 | let mut extern_dirs = FxHashSet::default(); | 35 | let mut extern_dirs = FxHashSet::default(); |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index e72017dcc..57372768c 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -10,7 +10,7 @@ | |||
10 | use lsp_types::TextDocumentClientCapabilities; | 10 | use lsp_types::TextDocumentClientCapabilities; |
11 | use ra_flycheck::FlycheckConfig; | 11 | use ra_flycheck::FlycheckConfig; |
12 | use ra_ide::{CompletionConfig, InlayHintsConfig}; | 12 | use ra_ide::{CompletionConfig, InlayHintsConfig}; |
13 | use ra_project_model::CargoFeatures; | 13 | use ra_project_model::CargoConfig; |
14 | use serde::Deserialize; | 14 | use serde::Deserialize; |
15 | 15 | ||
16 | #[derive(Debug, Clone)] | 16 | #[derive(Debug, Clone)] |
@@ -29,7 +29,7 @@ pub struct Config { | |||
29 | pub lru_capacity: Option<usize>, | 29 | pub lru_capacity: Option<usize>, |
30 | pub use_client_watching: bool, | 30 | pub use_client_watching: bool, |
31 | pub exclude_globs: Vec<String>, | 31 | pub exclude_globs: Vec<String>, |
32 | pub cargo: CargoFeatures, | 32 | pub cargo: CargoConfig, |
33 | pub with_sysroot: bool, | 33 | pub with_sysroot: bool, |
34 | } | 34 | } |
35 | 35 | ||
@@ -92,7 +92,7 @@ impl Default for Config { | |||
92 | lru_capacity: None, | 92 | lru_capacity: None, |
93 | use_client_watching: false, | 93 | use_client_watching: false, |
94 | exclude_globs: Vec::new(), | 94 | exclude_globs: Vec::new(), |
95 | cargo: CargoFeatures::default(), | 95 | cargo: CargoConfig::default(), |
96 | with_sysroot: true, | 96 | with_sysroot: true, |
97 | } | 97 | } |
98 | } | 98 | } |