aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authoroxalica <[email protected]>2019-10-05 13:55:27 +0100
committeroxalica <[email protected]>2019-10-05 13:55:27 +0100
commitc6303d9fee98232ac83a77f943c39d65c9c6b6db (patch)
tree9c0f29993289916e3cc43d7be9cfa6f0a62b7754 /crates
parentb271cb18d5ab19624e751867df6705cd1e94edbc (diff)
Use raw cfgs in json project and fix typo
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs8
-rw-r--r--crates/ra_project_model/src/json_project.rs5
-rw-r--r--crates/ra_project_model/src/lib.rs14
3 files changed, 18 insertions, 9 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 152681062..2ba82ab05 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -286,7 +286,13 @@ fn test_missing_module_code_action_in_json_project() {
286 286
287 let project = json!({ 287 let project = json!({
288 "roots": [path], 288 "roots": [path],
289 "crates": [ { "root_module": path.join("src/lib.rs"), "deps": [], "edition": "2015" } ] 289 "crates": [ {
290 "root_module": path.join("src/lib.rs"),
291 "deps": [],
292 "edition": "2015",
293 "atom_cfgs": [],
294 "key_value_cfgs": {}
295 } ]
290 }); 296 });
291 297
292 let code = format!( 298 let code = format!(
diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs
index b0d339f38..1bacb1d09 100644
--- a/crates/ra_project_model/src/json_project.rs
+++ b/crates/ra_project_model/src/json_project.rs
@@ -2,6 +2,7 @@
2 2
3use std::path::PathBuf; 3use std::path::PathBuf;
4 4
5use rustc_hash::{FxHashMap, FxHashSet};
5use serde::Deserialize; 6use serde::Deserialize;
6 7
7/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in 8/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
@@ -19,8 +20,8 @@ pub struct Crate {
19 pub(crate) root_module: PathBuf, 20 pub(crate) root_module: PathBuf,
20 pub(crate) edition: Edition, 21 pub(crate) edition: Edition,
21 pub(crate) deps: Vec<Dep>, 22 pub(crate) deps: Vec<Dep>,
22 #[serde(default)] 23 pub(crate) atom_cfgs: FxHashSet<String>,
23 pub(crate) features: Vec<String>, 24 pub(crate) key_value_cfgs: FxHashMap<String, String>,
24} 25}
25 26
26#[derive(Clone, Copy, Debug, Deserialize)] 27#[derive(Clone, Copy, Debug, Deserialize)]
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 05e49f5ce..640a5ebd3 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -134,11 +134,13 @@ impl ProjectWorkspace {
134 json_project::Edition::Edition2015 => Edition::Edition2015, 134 json_project::Edition::Edition2015 => Edition::Edition2015,
135 json_project::Edition::Edition2018 => Edition::Edition2018, 135 json_project::Edition::Edition2018 => Edition::Edition2018,
136 }; 136 };
137 // FIXME: cfg options 137 let mut cfg_options = default_cfg_options.clone();
138 // Default to enable test for workspace crates. 138 for name in &krate.atom_cfgs {
139 let cfg_options = default_cfg_options 139 cfg_options = cfg_options.atom(name.into());
140 .clone() 140 }
141 .features(krate.features.iter().map(Into::into)); 141 for (key, value) in &krate.key_value_cfgs {
142 cfg_options = cfg_options.key_value(key.into(), value.into());
143 }
142 crates.insert( 144 crates.insert(
143 crate_id, 145 crate_id,
144 crate_graph.add_crate_root(file_id, edition, cfg_options), 146 crate_graph.add_crate_root(file_id, edition, cfg_options),
@@ -309,7 +311,7 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
309 let mut cfg_options = CfgOptions::default(); 311 let mut cfg_options = CfgOptions::default();
310 312
311 match (|| -> Result<_> { 313 match (|| -> Result<_> {
312 // `cfg(test)` ans `cfg(debug_assertion)` is handled outside, so we suppress them here. 314 // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
313 let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?; 315 let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?;
314 if !output.status.success() { 316 if !output.status.success() {
315 Err("failed to get rustc cfgs")?; 317 Err("failed to get rustc cfgs")?;