diff options
author | Lukas Wirth <[email protected]> | 2021-03-16 14:28:02 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-03-16 14:28:02 +0000 |
commit | 75fafd6fcc010c71d770d19bea4b744b92c5267b (patch) | |
tree | 8a2426ff2bb880689a331203346c5dc2229fbb37 /crates | |
parent | e97cd709cd91ccfafbd45bab8b2bf01f3ddf6a04 (diff) |
Add new_source_root meta to test fixtures
Diffstat (limited to 'crates')
-rw-r--r-- | crates/base_db/src/fixture.rs | 12 | ||||
-rw-r--r-- | crates/ide/src/references.rs | 8 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 15 |
3 files changed, 28 insertions, 7 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 5c9824814..cad6866aa 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -57,7 +57,7 @@ | |||
57 | //! fn insert_source_code_here() {} | 57 | //! fn insert_source_code_here() {} |
58 | //! " | 58 | //! " |
59 | //! ``` | 59 | //! ``` |
60 | use std::{str::FromStr, sync::Arc}; | 60 | use std::{mem, str::FromStr, sync::Arc}; |
61 | 61 | ||
62 | use cfg::CfgOptions; | 62 | use cfg::CfgOptions; |
63 | use rustc_hash::FxHashMap; | 63 | use rustc_hash::FxHashMap; |
@@ -148,6 +148,7 @@ impl ChangeFixture { | |||
148 | let mut file_set = FileSet::default(); | 148 | let mut file_set = FileSet::default(); |
149 | let source_root_prefix = "/".to_string(); | 149 | let source_root_prefix = "/".to_string(); |
150 | let mut file_id = FileId(0); | 150 | let mut file_id = FileId(0); |
151 | let mut roots = Vec::new(); | ||
151 | 152 | ||
152 | let mut file_position = None; | 153 | let mut file_position = None; |
153 | 154 | ||
@@ -168,6 +169,10 @@ impl ChangeFixture { | |||
168 | let meta = FileMeta::from(entry); | 169 | let meta = FileMeta::from(entry); |
169 | assert!(meta.path.starts_with(&source_root_prefix)); | 170 | assert!(meta.path.starts_with(&source_root_prefix)); |
170 | 171 | ||
172 | if meta.introduce_new_source_root { | ||
173 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); | ||
174 | } | ||
175 | |||
171 | if let Some(krate) = meta.krate { | 176 | if let Some(krate) = meta.krate { |
172 | let crate_name = CrateName::normalize_dashes(&krate); | 177 | let crate_name = CrateName::normalize_dashes(&krate); |
173 | let crate_id = crate_graph.add_crate_root( | 178 | let crate_id = crate_graph.add_crate_root( |
@@ -215,7 +220,8 @@ impl ChangeFixture { | |||
215 | } | 220 | } |
216 | } | 221 | } |
217 | 222 | ||
218 | change.set_roots(vec![SourceRoot::new_local(file_set)]); | 223 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); |
224 | change.set_roots(roots); | ||
219 | change.set_crate_graph(crate_graph); | 225 | change.set_crate_graph(crate_graph); |
220 | 226 | ||
221 | ChangeFixture { file_position, files, change } | 227 | ChangeFixture { file_position, files, change } |
@@ -229,6 +235,7 @@ struct FileMeta { | |||
229 | cfg: CfgOptions, | 235 | cfg: CfgOptions, |
230 | edition: Edition, | 236 | edition: Edition, |
231 | env: Env, | 237 | env: Env, |
238 | introduce_new_source_root: bool, | ||
232 | } | 239 | } |
233 | 240 | ||
234 | impl From<Fixture> for FileMeta { | 241 | impl From<Fixture> for FileMeta { |
@@ -247,6 +254,7 @@ impl From<Fixture> for FileMeta { | |||
247 | .as_ref() | 254 | .as_ref() |
248 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | 255 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), |
249 | env: f.env.into_iter().collect(), | 256 | env: f.env.into_iter().collect(), |
257 | introduce_new_source_root: f.introduce_new_source_root, | ||
250 | } | 258 | } |
251 | } | 259 | } |
252 | } | 260 | } |
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index fc85cd0ce..e10a3ccf7 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -1275,13 +1275,13 @@ fn foo(_: bool) -> bo$0ol { true } | |||
1275 | fn test_transitive() { | 1275 | fn test_transitive() { |
1276 | check( | 1276 | check( |
1277 | r#" | 1277 | r#" |
1278 | //- /level3/level3.rs crate:level3 | 1278 | //- /level3.rs new_source_root: crate:level3 |
1279 | pub struct Fo$0o; | 1279 | pub struct Fo$0o; |
1280 | //- /level2/level2.rs crate:level2 deps:level3 | 1280 | //- /level2.rs new_source_root: crate:level2 deps:level3 |
1281 | pub use level3::Foo; | 1281 | pub use level3::Foo; |
1282 | //- /level1/level1.rs crate:level1 deps:level2 | 1282 | //- /level1.rs new_source_root: crate:level1 deps:level2 |
1283 | pub use level2::Foo; | 1283 | pub use level2::Foo; |
1284 | //- /level0/level0.rs crate:level0 deps:level1 | 1284 | //- /level0.rs new_source_root: crate:level0 deps:level1 |
1285 | pub use level1::Foo; | 1285 | pub use level1::Foo; |
1286 | "#, | 1286 | "#, |
1287 | expect![[r#" | 1287 | expect![[r#" |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index e3f57f3b2..6bc824e94 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -14,6 +14,7 @@ pub struct Fixture { | |||
14 | pub cfg_key_values: Vec<(String, String)>, | 14 | pub cfg_key_values: Vec<(String, String)>, |
15 | pub edition: Option<String>, | 15 | pub edition: Option<String>, |
16 | pub env: FxHashMap<String, String>, | 16 | pub env: FxHashMap<String, String>, |
17 | pub introduce_new_source_root: bool, | ||
17 | } | 18 | } |
18 | 19 | ||
19 | impl Fixture { | 20 | impl Fixture { |
@@ -70,6 +71,7 @@ impl Fixture { | |||
70 | let mut cfg_atoms = Vec::new(); | 71 | let mut cfg_atoms = Vec::new(); |
71 | let mut cfg_key_values = Vec::new(); | 72 | let mut cfg_key_values = Vec::new(); |
72 | let mut env = FxHashMap::default(); | 73 | let mut env = FxHashMap::default(); |
74 | let mut introduce_new_source_root = false; | ||
73 | for component in components[1..].iter() { | 75 | for component in components[1..].iter() { |
74 | let (key, value) = split_once(component, ':').unwrap(); | 76 | let (key, value) = split_once(component, ':').unwrap(); |
75 | match key { | 77 | match key { |
@@ -91,11 +93,22 @@ impl Fixture { | |||
91 | } | 93 | } |
92 | } | 94 | } |
93 | } | 95 | } |
96 | "new_source_root" => introduce_new_source_root = true, | ||
94 | _ => panic!("bad component: {:?}", component), | 97 | _ => panic!("bad component: {:?}", component), |
95 | } | 98 | } |
96 | } | 99 | } |
97 | 100 | ||
98 | Fixture { path, text: String::new(), krate, deps, cfg_atoms, cfg_key_values, edition, env } | 101 | Fixture { |
102 | path, | ||
103 | text: String::new(), | ||
104 | krate, | ||
105 | deps, | ||
106 | cfg_atoms, | ||
107 | cfg_key_values, | ||
108 | edition, | ||
109 | env, | ||
110 | introduce_new_source_root, | ||
111 | } | ||
99 | } | 112 | } |
100 | } | 113 | } |
101 | 114 | ||