diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-05 15:25:59 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-05 15:25:59 +0100 |
commit | ae6305b90c80eb919cfde985cba66975b6222ed2 (patch) | |
tree | de601daf3714c4bda937e7cad05d048b69d16e71 /crates/ra_batch/src | |
parent | dbf869b4d2dac09df17609edf6e67c1611b71dc5 (diff) | |
parent | c6303d9fee98232ac83a77f943c39d65c9c6b6db (diff) |
Merge #1928
1928: Support `#[cfg(..)]` r=matklad a=oxalica
This PR implement `#[cfg(..)]` conditional compilation. It read default cfg options from `rustc --print cfg` with also hard-coded `test` and `debug_assertion` enabled.
Front-end settings are **not** included in this PR.
There is also a known issue that inner control attributes are totally ignored. I think it is **not** a part of `cfg` and create a separated issue for it. #1949
Fixes #1920
Related: #1073
Co-authored-by: uHOOCCOOHu <[email protected]>
Co-authored-by: oxalica <[email protected]>
Diffstat (limited to 'crates/ra_batch/src')
-rw-r--r-- | crates/ra_batch/src/lib.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index 939f72037..a5fc2a23e 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -7,7 +7,7 @@ use rustc_hash::FxHashMap; | |||
7 | use crossbeam_channel::{unbounded, Receiver}; | 7 | use crossbeam_channel::{unbounded, Receiver}; |
8 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 8 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
9 | use ra_ide_api::{AnalysisChange, AnalysisHost, FeatureFlags}; | 9 | use ra_ide_api::{AnalysisChange, AnalysisHost, FeatureFlags}; |
10 | use ra_project_model::{PackageRoot, ProjectWorkspace}; | 10 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; |
11 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; | 11 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; |
12 | use ra_vfs_glob::RustPackageFilterBuilder; | 12 | use ra_vfs_glob::RustPackageFilterBuilder; |
13 | 13 | ||
@@ -41,11 +41,17 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, | |||
41 | sender, | 41 | sender, |
42 | Watch(false), | 42 | Watch(false), |
43 | ); | 43 | ); |
44 | let (crate_graph, _crate_names) = ws.to_crate_graph(&mut |path: &Path| { | 44 | |
45 | let vfs_file = vfs.load(path); | 45 | // FIXME: cfg options? |
46 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | 46 | let default_cfg_options = |
47 | vfs_file.map(vfs_file_to_id) | 47 | get_rustc_cfg_options().atom("test".into()).atom("debug_assertion".into()); |
48 | }); | 48 | |
49 | let (crate_graph, _crate_names) = | ||
50 | ws.to_crate_graph(&default_cfg_options, &mut |path: &Path| { | ||
51 | let vfs_file = vfs.load(path); | ||
52 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | ||
53 | vfs_file.map(vfs_file_to_id) | ||
54 | }); | ||
49 | log::debug!("crate graph: {:?}", crate_graph); | 55 | log::debug!("crate graph: {:?}", crate_graph); |
50 | 56 | ||
51 | let source_roots = roots | 57 | let source_roots = roots |