From c6303d9fee98232ac83a77f943c39d65c9c6b6db Mon Sep 17 00:00:00 2001 From: oxalica Date: Sat, 5 Oct 2019 20:55:27 +0800 Subject: Use raw cfgs in json project and fix typo --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 8 +++++++- crates/ra_project_model/src/json_project.rs | 5 +++-- crates/ra_project_model/src/lib.rs | 14 ++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'crates') 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() { let project = json!({ "roots": [path], - "crates": [ { "root_module": path.join("src/lib.rs"), "deps": [], "edition": "2015" } ] + "crates": [ { + "root_module": path.join("src/lib.rs"), + "deps": [], + "edition": "2015", + "atom_cfgs": [], + "key_value_cfgs": {} + } ] }); 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 @@ use std::path::PathBuf; +use rustc_hash::{FxHashMap, FxHashSet}; use serde::Deserialize; /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in @@ -19,8 +20,8 @@ pub struct Crate { pub(crate) root_module: PathBuf, pub(crate) edition: Edition, pub(crate) deps: Vec, - #[serde(default)] - pub(crate) features: Vec, + pub(crate) atom_cfgs: FxHashSet, + pub(crate) key_value_cfgs: FxHashMap, } #[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 { json_project::Edition::Edition2015 => Edition::Edition2015, json_project::Edition::Edition2018 => Edition::Edition2018, }; - // FIXME: cfg options - // Default to enable test for workspace crates. - let cfg_options = default_cfg_options - .clone() - .features(krate.features.iter().map(Into::into)); + let mut cfg_options = default_cfg_options.clone(); + for name in &krate.atom_cfgs { + cfg_options = cfg_options.atom(name.into()); + } + for (key, value) in &krate.key_value_cfgs { + cfg_options = cfg_options.key_value(key.into(), value.into()); + } crates.insert( crate_id, crate_graph.add_crate_root(file_id, edition, cfg_options), @@ -309,7 +311,7 @@ pub fn get_rustc_cfg_options() -> CfgOptions { let mut cfg_options = CfgOptions::default(); match (|| -> Result<_> { - // `cfg(test)` ans `cfg(debug_assertion)` is handled outside, so we suppress them here. + // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?; if !output.status.success() { Err("failed to get rustc cfgs")?; -- cgit v1.2.3