diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-30 00:38:16 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-10-02 19:28:02 +0100 |
commit | d2ea776b8fbb5286a04dde75a9a8f8b14f12bfe9 (patch) | |
tree | d6ddac6dc88b327aaf956843dc53b3e635f699b9 /crates/ra_project_model/src | |
parent | b1ed887d813bf5775a16624694939fdf836f97b1 (diff) |
Enable CfgOptions `test` for workspace crates
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 5d3078598..5ff3971e0 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -11,6 +11,7 @@ use std::{ | |||
11 | path::{Path, PathBuf}, | 11 | path::{Path, PathBuf}, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use ra_cfg::CfgOptions; | ||
14 | use ra_db::{CrateGraph, CrateId, Edition, FileId}; | 15 | use ra_db::{CrateGraph, CrateId, Edition, FileId}; |
15 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
16 | use serde_json::from_reader; | 17 | use serde_json::from_reader; |
@@ -131,7 +132,13 @@ impl ProjectWorkspace { | |||
131 | json_project::Edition::Edition2015 => Edition::Edition2015, | 132 | json_project::Edition::Edition2015 => Edition::Edition2015, |
132 | json_project::Edition::Edition2018 => Edition::Edition2018, | 133 | json_project::Edition::Edition2018 => Edition::Edition2018, |
133 | }; | 134 | }; |
134 | crates.insert(crate_id, crate_graph.add_crate_root(file_id, edition)); | 135 | // FIXME: cfg options |
136 | // Default to enable test for workspace crates. | ||
137 | let cfg_options = CfgOptions::default().atom("test".into()); | ||
138 | crates.insert( | ||
139 | crate_id, | ||
140 | crate_graph.add_crate_root(file_id, edition, cfg_options), | ||
141 | ); | ||
135 | } | 142 | } |
136 | } | 143 | } |
137 | 144 | ||
@@ -157,7 +164,11 @@ impl ProjectWorkspace { | |||
157 | let mut sysroot_crates = FxHashMap::default(); | 164 | let mut sysroot_crates = FxHashMap::default(); |
158 | for krate in sysroot.crates() { | 165 | for krate in sysroot.crates() { |
159 | if let Some(file_id) = load(krate.root(&sysroot)) { | 166 | if let Some(file_id) = load(krate.root(&sysroot)) { |
160 | let crate_id = crate_graph.add_crate_root(file_id, Edition::Edition2018); | 167 | // FIXME: cfg options |
168 | // Crates from sysroot have `cfg(test)` disabled | ||
169 | let cfg_options = CfgOptions::default(); | ||
170 | let crate_id = | ||
171 | crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); | ||
161 | sysroot_crates.insert(krate, crate_id); | 172 | sysroot_crates.insert(krate, crate_id); |
162 | names.insert(crate_id, krate.name(&sysroot).to_string()); | 173 | names.insert(crate_id, krate.name(&sysroot).to_string()); |
163 | } | 174 | } |
@@ -186,7 +197,11 @@ impl ProjectWorkspace { | |||
186 | let root = tgt.root(&cargo); | 197 | let root = tgt.root(&cargo); |
187 | if let Some(file_id) = load(root) { | 198 | if let Some(file_id) = load(root) { |
188 | let edition = pkg.edition(&cargo); | 199 | let edition = pkg.edition(&cargo); |
189 | let crate_id = crate_graph.add_crate_root(file_id, edition); | 200 | // FIXME: cfg options |
201 | // Default to enable test for workspace crates. | ||
202 | let cfg_options = CfgOptions::default().atom("test".into()); | ||
203 | let crate_id = | ||
204 | crate_graph.add_crate_root(file_id, edition, cfg_options); | ||
190 | names.insert(crate_id, pkg.name(&cargo).to_string()); | 205 | names.insert(crate_id, pkg.name(&cargo).to_string()); |
191 | if tgt.kind(&cargo) == TargetKind::Lib { | 206 | if tgt.kind(&cargo) == TargetKind::Lib { |
192 | lib_tgt = Some(crate_id); | 207 | lib_tgt = Some(crate_id); |