Skip to content

Commit c6303d9

Browse files
committed
Use raw cfgs in json project and fix typo
1 parent b271cb1 commit c6303d9

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

crates/ra_lsp_server/tests/heavy_tests/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ fn test_missing_module_code_action_in_json_project() {
286286

287287
let project = json!({
288288
"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+
} ]
290296
});
291297

292298
let code = format!(

crates/ra_project_model/src/json_project.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::path::PathBuf;
44

5+
use rustc_hash::{FxHashMap, FxHashSet};
56
use serde::Deserialize;
67

78
/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
@@ -19,8 +20,8 @@ pub struct Crate {
1920
pub(crate) root_module: PathBuf,
2021
pub(crate) edition: Edition,
2122
pub(crate) deps: Vec<Dep>,
22-
#[serde(default)]
23-
pub(crate) features: Vec<String>,
23+
pub(crate) atom_cfgs: FxHashSet<String>,
24+
pub(crate) key_value_cfgs: FxHashMap<String, String>,
2425
}
2526

2627
#[derive(Clone, Copy, Debug, Deserialize)]

crates/ra_project_model/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ impl ProjectWorkspace {
134134
json_project::Edition::Edition2015 => Edition::Edition2015,
135135
json_project::Edition::Edition2018 => Edition::Edition2018,
136136
};
137-
// FIXME: cfg options
138-
// Default to enable test for workspace crates.
139-
let cfg_options = default_cfg_options
140-
.clone()
141-
.features(krate.features.iter().map(Into::into));
137+
let mut cfg_options = default_cfg_options.clone();
138+
for name in &krate.atom_cfgs {
139+
cfg_options = cfg_options.atom(name.into());
140+
}
141+
for (key, value) in &krate.key_value_cfgs {
142+
cfg_options = cfg_options.key_value(key.into(), value.into());
143+
}
142144
crates.insert(
143145
crate_id,
144146
crate_graph.add_crate_root(file_id, edition, cfg_options),
@@ -309,7 +311,7 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
309311
let mut cfg_options = CfgOptions::default();
310312

311313
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.
313315
let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?;
314316
if !output.status.success() {
315317
Err("failed to get rustc cfgs")?;

0 commit comments

Comments
 (0)