aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/json_project.rs5
-rw-r--r--crates/ra_project_model/src/lib.rs14
2 files changed, 11 insertions, 8 deletions
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")?;