diff options
author | vsrs <[email protected]> | 2020-05-16 13:23:43 +0100 |
---|---|---|
committer | vsrs <[email protected]> | 2020-05-16 13:23:43 +0100 |
commit | 2c00bd8c6a9476dbac427c84941fe6f54a8a95b1 (patch) | |
tree | 9baa7a6b0cc0864ce2af3627404f6393402287be | |
parent | 2dde9b19943d3f9557520428c92a52d75fb1deb3 (diff) |
Propogate fixture meta to AnalysisHost
Except crate name.
-rw-r--r-- | crates/ra_db/src/fixture.rs | 10 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 15 | ||||
-rw-r--r-- | crates/ra_ide/src/call_hierarchy.rs | 29 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 31 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 44 |
5 files changed, 113 insertions, 16 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 8b62fe9aa..fd535ab15 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -254,20 +254,14 @@ impl From<&FixtureMeta> for ParsedMeta { | |||
254 | } | 254 | } |
255 | FixtureMeta::File(f) => Self::File(FileMeta { | 255 | FixtureMeta::File(f) => Self::File(FileMeta { |
256 | path: f.path.to_owned().into(), | 256 | path: f.path.to_owned().into(), |
257 | krate: f.krate.to_owned().into(), | 257 | krate: f.crate_name.to_owned().into(), |
258 | deps: f.deps.to_owned(), | 258 | deps: f.deps.to_owned(), |
259 | cfg: f.cfg.to_owned(), | 259 | cfg: f.cfg.to_owned(), |
260 | edition: f | 260 | edition: f |
261 | .edition | 261 | .edition |
262 | .as_ref() | 262 | .as_ref() |
263 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | 263 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), |
264 | env: { | 264 | env: Env::from(f.env.iter()), |
265 | let mut env = Env::default(); | ||
266 | for (k, v) in &f.env { | ||
267 | env.set(&k, v.to_owned()); | ||
268 | } | ||
269 | env | ||
270 | }, | ||
271 | }), | 265 | }), |
272 | } | 266 | } |
273 | } | 267 | } |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index ab14e2d5e..4d2d3b48a 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -311,6 +311,21 @@ impl fmt::Display for Edition { | |||
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | impl<'a, T> From<T> for Env | ||
315 | where | ||
316 | T: Iterator<Item = (&'a String, &'a String)>, | ||
317 | { | ||
318 | fn from(iter: T) -> Self { | ||
319 | let mut result = Self::default(); | ||
320 | |||
321 | for (k, v) in iter { | ||
322 | result.entries.insert(k.to_owned(), v.to_owned()); | ||
323 | } | ||
324 | |||
325 | result | ||
326 | } | ||
327 | } | ||
328 | |||
314 | impl Env { | 329 | impl Env { |
315 | pub fn set(&mut self, env: &str, value: String) { | 330 | pub fn set(&mut self, env: &str, value: String) { |
316 | self.entries.insert(env.to_owned(), value); | 331 | self.entries.insert(env.to_owned(), value); |
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 85d1f0cb1..defd8176f 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs | |||
@@ -246,6 +246,35 @@ mod tests { | |||
246 | } | 246 | } |
247 | 247 | ||
248 | #[test] | 248 | #[test] |
249 | fn test_call_hierarchy_in_tests_mod() { | ||
250 | check_hierarchy( | ||
251 | r#" | ||
252 | //- /lib.rs cfg:test | ||
253 | fn callee() {} | ||
254 | fn caller1() { | ||
255 | call<|>ee(); | ||
256 | } | ||
257 | |||
258 | #[cfg(test)] | ||
259 | mod tests { | ||
260 | use super::*; | ||
261 | |||
262 | #[test] | ||
263 | fn test_caller() { | ||
264 | callee(); | ||
265 | } | ||
266 | } | ||
267 | "#, | ||
268 | "callee FN_DEF FileId(1) 0..14 3..9", | ||
269 | &[ | ||
270 | "caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]", | ||
271 | "test_caller FN_DEF FileId(1) 93..147 108..119 : [132..138]", | ||
272 | ], | ||
273 | &[], | ||
274 | ); | ||
275 | } | ||
276 | |||
277 | #[test] | ||
249 | fn test_call_hierarchy_in_different_files() { | 278 | fn test_call_hierarchy_in_different_files() { |
250 | check_hierarchy( | 279 | check_hierarchy( |
251 | r#" | 280 | r#" |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 8d8e30714..ad78d2d93 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::str::FromStr; | ||
3 | use std::sync::Arc; | 4 | use std::sync::Arc; |
4 | 5 | ||
5 | use ra_cfg::CfgOptions; | 6 | use ra_cfg::CfgOptions; |
@@ -7,8 +8,8 @@ use ra_db::{CrateName, Env, RelativePathBuf}; | |||
7 | use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; | 8 | use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; |
8 | 9 | ||
9 | use crate::{ | 10 | use crate::{ |
10 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition::Edition2018, FileId, FilePosition, | 11 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, |
11 | FileRange, SourceRootId, | 12 | SourceRootId, |
12 | }; | 13 | }; |
13 | 14 | ||
14 | #[derive(Debug)] | 15 | #[derive(Debug)] |
@@ -46,6 +47,22 @@ impl MockFileData { | |||
46 | _ => CfgOptions::default(), | 47 | _ => CfgOptions::default(), |
47 | } | 48 | } |
48 | } | 49 | } |
50 | |||
51 | fn edition(&self) -> Edition { | ||
52 | match self { | ||
53 | MockFileData::Fixture(f) => { | ||
54 | f.meta.edition().map_or(Edition::Edition2018, |v| Edition::from_str(v).unwrap()) | ||
55 | } | ||
56 | _ => Edition::Edition2018, | ||
57 | } | ||
58 | } | ||
59 | |||
60 | fn env(&self) -> Env { | ||
61 | match self { | ||
62 | MockFileData::Fixture(f) => Env::from(f.meta.env()), | ||
63 | _ => Env::default(), | ||
64 | } | ||
65 | } | ||
49 | } | 66 | } |
50 | 67 | ||
51 | impl From<FixtureEntry> for MockFileData { | 68 | impl From<FixtureEntry> for MockFileData { |
@@ -153,13 +170,15 @@ impl MockAnalysis { | |||
153 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | 170 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); |
154 | let cfg_options = data.cfg_options(); | 171 | let cfg_options = data.cfg_options(); |
155 | let file_id = FileId(i as u32 + 1); | 172 | let file_id = FileId(i as u32 + 1); |
173 | let edition = data.edition(); | ||
174 | let env = data.env(); | ||
156 | if path == "/lib.rs" || path == "/main.rs" { | 175 | if path == "/lib.rs" || path == "/main.rs" { |
157 | root_crate = Some(crate_graph.add_crate_root( | 176 | root_crate = Some(crate_graph.add_crate_root( |
158 | file_id, | 177 | file_id, |
159 | Edition2018, | 178 | edition, |
160 | None, | 179 | None, |
161 | cfg_options, | 180 | cfg_options, |
162 | Env::default(), | 181 | env, |
163 | Default::default(), | 182 | Default::default(), |
164 | Default::default(), | 183 | Default::default(), |
165 | )); | 184 | )); |
@@ -167,10 +186,10 @@ impl MockAnalysis { | |||
167 | let crate_name = path.parent().unwrap().file_name().unwrap(); | 186 | let crate_name = path.parent().unwrap().file_name().unwrap(); |
168 | let other_crate = crate_graph.add_crate_root( | 187 | let other_crate = crate_graph.add_crate_root( |
169 | file_id, | 188 | file_id, |
170 | Edition2018, | 189 | edition, |
171 | Some(CrateName::new(crate_name).unwrap()), | 190 | Some(CrateName::new(crate_name).unwrap()), |
172 | cfg_options, | 191 | cfg_options, |
173 | Env::default(), | 192 | env, |
174 | Default::default(), | 193 | Default::default(), |
175 | Default::default(), | 194 | Default::default(), |
176 | ); | 195 | ); |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 584ca5c39..e7fa201e9 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -174,7 +174,7 @@ pub enum FixtureMeta { | |||
174 | #[derive(Debug, Eq, PartialEq)] | 174 | #[derive(Debug, Eq, PartialEq)] |
175 | pub struct FileMeta { | 175 | pub struct FileMeta { |
176 | pub path: RelativePathBuf, | 176 | pub path: RelativePathBuf, |
177 | pub krate: Option<String>, | 177 | pub crate_name: Option<String>, |
178 | pub deps: Vec<String>, | 178 | pub deps: Vec<String>, |
179 | pub cfg: CfgOptions, | 179 | pub cfg: CfgOptions, |
180 | pub edition: Option<String>, | 180 | pub edition: Option<String>, |
@@ -189,12 +189,52 @@ impl FixtureMeta { | |||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | pub fn crate_name(&self) -> Option<&String> { | ||
193 | match self { | ||
194 | FixtureMeta::File(f) => f.crate_name.as_ref(), | ||
195 | _ => None, | ||
196 | } | ||
197 | } | ||
198 | |||
192 | pub fn cfg_options(&self) -> Option<&CfgOptions> { | 199 | pub fn cfg_options(&self) -> Option<&CfgOptions> { |
193 | match self { | 200 | match self { |
194 | FixtureMeta::File(f) => Some(&f.cfg), | 201 | FixtureMeta::File(f) => Some(&f.cfg), |
195 | _ => None, | 202 | _ => None, |
196 | } | 203 | } |
197 | } | 204 | } |
205 | |||
206 | pub fn edition(&self) -> Option<&String> { | ||
207 | match self { | ||
208 | FixtureMeta::File(f) => f.edition.as_ref(), | ||
209 | _ => None, | ||
210 | } | ||
211 | } | ||
212 | |||
213 | pub fn env(&self) -> impl Iterator<Item = (&String, &String)> { | ||
214 | struct EnvIter<'a> { | ||
215 | iter: Option<std::collections::hash_map::Iter<'a, String, String>>, | ||
216 | } | ||
217 | |||
218 | impl<'a> EnvIter<'a> { | ||
219 | fn new(meta: &'a FixtureMeta) -> Self { | ||
220 | Self { | ||
221 | iter: match meta { | ||
222 | FixtureMeta::File(f) => Some(f.env.iter()), | ||
223 | _ => None, | ||
224 | }, | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | |||
229 | impl<'a> Iterator for EnvIter<'a> { | ||
230 | type Item = (&'a String, &'a String); | ||
231 | fn next(&mut self) -> Option<Self::Item> { | ||
232 | self.iter.as_mut().and_then(|i| i.next()) | ||
233 | } | ||
234 | } | ||
235 | |||
236 | EnvIter::new(self) | ||
237 | } | ||
198 | } | 238 | } |
199 | 239 | ||
200 | /// Parses text which looks like this: | 240 | /// Parses text which looks like this: |
@@ -289,7 +329,7 @@ fn parse_meta(meta: &str) -> FixtureMeta { | |||
289 | } | 329 | } |
290 | } | 330 | } |
291 | 331 | ||
292 | FixtureMeta::File(FileMeta { path, krate, deps, edition, cfg, env }) | 332 | FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) |
293 | } | 333 | } |
294 | 334 | ||
295 | fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> { | 335 | fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> { |