aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/mock_analysis.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-05 15:25:59 +0100
committerGitHub <[email protected]>2019-10-05 15:25:59 +0100
commitae6305b90c80eb919cfde985cba66975b6222ed2 (patch)
treede601daf3714c4bda937e7cad05d048b69d16e71 /crates/ra_ide_api/src/mock_analysis.rs
parentdbf869b4d2dac09df17609edf6e67c1611b71dc5 (diff)
parentc6303d9fee98232ac83a77f943c39d65c9c6b6db (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_ide_api/src/mock_analysis.rs')
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs
index 16870c7ae..80b71894c 100644
--- a/crates/ra_ide_api/src/mock_analysis.rs
+++ b/crates/ra_ide_api/src/mock_analysis.rs
@@ -2,6 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_cfg::CfgOptions;
5use relative_path::RelativePathBuf; 6use relative_path::RelativePathBuf;
6use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; 7use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
7 8
@@ -93,10 +94,11 @@ impl MockAnalysis {
93 assert!(path.starts_with('/')); 94 assert!(path.starts_with('/'));
94 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 95 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
95 let file_id = FileId(i as u32 + 1); 96 let file_id = FileId(i as u32 + 1);
97 let cfg_options = CfgOptions::default();
96 if path == "/lib.rs" || path == "/main.rs" { 98 if path == "/lib.rs" || path == "/main.rs" {
97 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018)); 99 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options));
98 } else if path.ends_with("/lib.rs") { 100 } else if path.ends_with("/lib.rs") {
99 let other_crate = crate_graph.add_crate_root(file_id, Edition2018); 101 let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options);
100 let crate_name = path.parent().unwrap().file_name().unwrap(); 102 let crate_name = path.parent().unwrap().file_name().unwrap();
101 if let Some(root_crate) = root_crate { 103 if let Some(root_crate) = root_crate {
102 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); 104 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap();