diff options
author | Aleksey Kladov <[email protected]> | 2020-10-02 15:13:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-10-02 16:31:20 +0100 |
commit | 09348b247465864c6462a39055803bcbb0156cfe (patch) | |
tree | d57122ddcaa21d6f4ea50204afc3e3bc341583fc | |
parent | eeb27f95f1025128f8a1d24a515eb009498a1d44 (diff) |
Get rid of MockAnalysis
-rw-r--r-- | crates/base_db/src/fixture.rs | 14 | ||||
-rw-r--r-- | crates/ide/src/call_hierarchy.rs | 52 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_keyword.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_mod.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_qualified_path.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_unqualified_path.rs | 14 | ||||
-rw-r--r-- | crates/ide/src/completion/presentation.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/diagnostics.rs | 28 | ||||
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/goto_definition.rs | 24 | ||||
-rw-r--r-- | crates/ide/src/goto_implementation.rs | 6 | ||||
-rw-r--r-- | crates/ide/src/goto_type_definition.rs | 7 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 92 | ||||
-rw-r--r-- | crates/ide/src/mock_analysis.rs | 209 | ||||
-rw-r--r-- | crates/ide/src/parent_module.rs | 40 | ||||
-rw-r--r-- | crates/ide/src/references.rs | 118 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 34 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 40 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 6 |
19 files changed, 288 insertions, 420 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 48fa73bf0..b7286fc7d 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -117,13 +117,13 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
117 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} | 117 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} |
118 | 118 | ||
119 | pub struct ChangeFixture { | 119 | pub struct ChangeFixture { |
120 | file_position: Option<(FileId, RangeOrOffset)>, | 120 | pub file_position: Option<(FileId, RangeOrOffset)>, |
121 | files: Vec<FileId>, | 121 | pub files: Vec<FileId>, |
122 | change: Change, | 122 | pub change: Change, |
123 | } | 123 | } |
124 | 124 | ||
125 | impl ChangeFixture { | 125 | impl ChangeFixture { |
126 | fn parse(ra_fixture: &str) -> ChangeFixture { | 126 | pub fn parse(ra_fixture: &str) -> ChangeFixture { |
127 | let fixture = Fixture::parse(ra_fixture); | 127 | let fixture = Fixture::parse(ra_fixture); |
128 | let mut change = Change::new(); | 128 | let mut change = Change::new(); |
129 | 129 | ||
@@ -132,6 +132,7 @@ impl ChangeFixture { | |||
132 | let mut crates = FxHashMap::default(); | 132 | let mut crates = FxHashMap::default(); |
133 | let mut crate_deps = Vec::new(); | 133 | let mut crate_deps = Vec::new(); |
134 | let mut default_crate_root: Option<FileId> = None; | 134 | let mut default_crate_root: Option<FileId> = None; |
135 | let mut default_cfg = CfgOptions::default(); | ||
135 | 136 | ||
136 | let mut file_set = FileSet::default(); | 137 | let mut file_set = FileSet::default(); |
137 | let source_root_prefix = "/".to_string(); | 138 | let source_root_prefix = "/".to_string(); |
@@ -171,6 +172,7 @@ impl ChangeFixture { | |||
171 | } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { | 172 | } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { |
172 | assert!(default_crate_root.is_none()); | 173 | assert!(default_crate_root.is_none()); |
173 | default_crate_root = Some(file_id); | 174 | default_crate_root = Some(file_id); |
175 | default_cfg = meta.cfg; | ||
174 | } | 176 | } |
175 | 177 | ||
176 | change.change_file(file_id, Some(Arc::new(text))); | 178 | change.change_file(file_id, Some(Arc::new(text))); |
@@ -185,8 +187,8 @@ impl ChangeFixture { | |||
185 | crate_graph.add_crate_root( | 187 | crate_graph.add_crate_root( |
186 | crate_root, | 188 | crate_root, |
187 | Edition::Edition2018, | 189 | Edition::Edition2018, |
188 | None, | 190 | Some("test".to_string()), |
189 | CfgOptions::default(), | 191 | default_cfg, |
190 | Env::default(), | 192 | Env::default(), |
191 | Default::default(), | 193 | Default::default(), |
192 | ); | 194 | ); |
diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 58e26b94c..0fb49de71 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs | |||
@@ -181,8 +181,8 @@ fn caller() { | |||
181 | call<|>ee(); | 181 | call<|>ee(); |
182 | } | 182 | } |
183 | "#, | 183 | "#, |
184 | "callee FN FileId(1) 0..14 3..9", | 184 | "callee FN FileId(0) 0..14 3..9", |
185 | &["caller FN FileId(1) 15..44 18..24 : [33..39]"], | 185 | &["caller FN FileId(0) 15..44 18..24 : [33..39]"], |
186 | &[], | 186 | &[], |
187 | ); | 187 | ); |
188 | } | 188 | } |
@@ -197,8 +197,8 @@ fn caller() { | |||
197 | callee(); | 197 | callee(); |
198 | } | 198 | } |
199 | "#, | 199 | "#, |
200 | "callee FN FileId(1) 0..14 3..9", | 200 | "callee FN FileId(0) 0..14 3..9", |
201 | &["caller FN FileId(1) 15..44 18..24 : [33..39]"], | 201 | &["caller FN FileId(0) 15..44 18..24 : [33..39]"], |
202 | &[], | 202 | &[], |
203 | ); | 203 | ); |
204 | } | 204 | } |
@@ -214,8 +214,8 @@ fn caller() { | |||
214 | callee(); | 214 | callee(); |
215 | } | 215 | } |
216 | "#, | 216 | "#, |
217 | "callee FN FileId(1) 0..14 3..9", | 217 | "callee FN FileId(0) 0..14 3..9", |
218 | &["caller FN FileId(1) 15..58 18..24 : [33..39, 47..53]"], | 218 | &["caller FN FileId(0) 15..58 18..24 : [33..39, 47..53]"], |
219 | &[], | 219 | &[], |
220 | ); | 220 | ); |
221 | } | 221 | } |
@@ -234,10 +234,10 @@ fn caller2() { | |||
234 | callee(); | 234 | callee(); |
235 | } | 235 | } |
236 | "#, | 236 | "#, |
237 | "callee FN FileId(1) 0..14 3..9", | 237 | "callee FN FileId(0) 0..14 3..9", |
238 | &[ | 238 | &[ |
239 | "caller1 FN FileId(1) 15..45 18..25 : [34..40]", | 239 | "caller1 FN FileId(0) 15..45 18..25 : [34..40]", |
240 | "caller2 FN FileId(1) 47..77 50..57 : [66..72]", | 240 | "caller2 FN FileId(0) 47..77 50..57 : [66..72]", |
241 | ], | 241 | ], |
242 | &[], | 242 | &[], |
243 | ); | 243 | ); |
@@ -263,10 +263,10 @@ mod tests { | |||
263 | } | 263 | } |
264 | } | 264 | } |
265 | "#, | 265 | "#, |
266 | "callee FN FileId(1) 0..14 3..9", | 266 | "callee FN FileId(0) 0..14 3..9", |
267 | &[ | 267 | &[ |
268 | "caller1 FN FileId(1) 15..45 18..25 : [34..40]", | 268 | "caller1 FN FileId(0) 15..45 18..25 : [34..40]", |
269 | "test_caller FN FileId(1) 95..149 110..121 : [134..140]", | 269 | "test_caller FN FileId(0) 95..149 110..121 : [134..140]", |
270 | ], | 270 | ], |
271 | &[], | 271 | &[], |
272 | ); | 272 | ); |
@@ -287,8 +287,8 @@ fn caller() { | |||
287 | //- /foo/mod.rs | 287 | //- /foo/mod.rs |
288 | pub fn callee() {} | 288 | pub fn callee() {} |
289 | "#, | 289 | "#, |
290 | "callee FN FileId(2) 0..18 7..13", | 290 | "callee FN FileId(1) 0..18 7..13", |
291 | &["caller FN FileId(1) 27..56 30..36 : [45..51]"], | 291 | &["caller FN FileId(0) 27..56 30..36 : [45..51]"], |
292 | &[], | 292 | &[], |
293 | ); | 293 | ); |
294 | } | 294 | } |
@@ -304,9 +304,9 @@ fn call<|>er() { | |||
304 | callee(); | 304 | callee(); |
305 | } | 305 | } |
306 | "#, | 306 | "#, |
307 | "caller FN FileId(1) 15..58 18..24", | 307 | "caller FN FileId(0) 15..58 18..24", |
308 | &[], | 308 | &[], |
309 | &["callee FN FileId(1) 0..14 3..9 : [33..39, 47..53]"], | 309 | &["callee FN FileId(0) 0..14 3..9 : [33..39, 47..53]"], |
310 | ); | 310 | ); |
311 | } | 311 | } |
312 | 312 | ||
@@ -325,9 +325,9 @@ fn call<|>er() { | |||
325 | //- /foo/mod.rs | 325 | //- /foo/mod.rs |
326 | pub fn callee() {} | 326 | pub fn callee() {} |
327 | "#, | 327 | "#, |
328 | "caller FN FileId(1) 27..56 30..36", | 328 | "caller FN FileId(0) 27..56 30..36", |
329 | &[], | 329 | &[], |
330 | &["callee FN FileId(2) 0..18 7..13 : [45..51]"], | 330 | &["callee FN FileId(1) 0..18 7..13 : [45..51]"], |
331 | ); | 331 | ); |
332 | } | 332 | } |
333 | 333 | ||
@@ -348,9 +348,9 @@ fn caller3() { | |||
348 | 348 | ||
349 | } | 349 | } |
350 | "#, | 350 | "#, |
351 | "caller2 FN FileId(1) 33..64 36..43", | 351 | "caller2 FN FileId(0) 33..64 36..43", |
352 | &["caller1 FN FileId(1) 0..31 3..10 : [19..26]"], | 352 | &["caller1 FN FileId(0) 0..31 3..10 : [19..26]"], |
353 | &["caller3 FN FileId(1) 66..83 69..76 : [52..59]"], | 353 | &["caller3 FN FileId(0) 66..83 69..76 : [52..59]"], |
354 | ); | 354 | ); |
355 | } | 355 | } |
356 | 356 | ||
@@ -368,9 +368,9 @@ fn main() { | |||
368 | a<|>() | 368 | a<|>() |
369 | } | 369 | } |
370 | "#, | 370 | "#, |
371 | "a FN FileId(1) 0..18 3..4", | 371 | "a FN FileId(0) 0..18 3..4", |
372 | &["main FN FileId(1) 31..52 34..38 : [47..48]"], | 372 | &["main FN FileId(0) 31..52 34..38 : [47..48]"], |
373 | &["b FN FileId(1) 20..29 23..24 : [13..14]"], | 373 | &["b FN FileId(0) 20..29 23..24 : [13..14]"], |
374 | ); | 374 | ); |
375 | 375 | ||
376 | check_hierarchy( | 376 | check_hierarchy( |
@@ -385,8 +385,8 @@ fn main() { | |||
385 | a() | 385 | a() |
386 | } | 386 | } |
387 | "#, | 387 | "#, |
388 | "b FN FileId(1) 20..29 23..24", | 388 | "b FN FileId(0) 20..29 23..24", |
389 | &["a FN FileId(1) 0..18 3..4 : [13..14]"], | 389 | &["a FN FileId(0) 0..18 3..4 : [13..14]"], |
390 | &[], | 390 | &[], |
391 | ); | 391 | ); |
392 | } | 392 | } |
diff --git a/crates/ide/src/completion/complete_keyword.rs b/crates/ide/src/completion/complete_keyword.rs index 5645b41fa..e59747095 100644 --- a/crates/ide/src/completion/complete_keyword.rs +++ b/crates/ide/src/completion/complete_keyword.rs | |||
@@ -495,13 +495,13 @@ Some multi-line comment<|> | |||
495 | fn test_completion_await_impls_future() { | 495 | fn test_completion_await_impls_future() { |
496 | check( | 496 | check( |
497 | r#" | 497 | r#" |
498 | //- /main.rs | 498 | //- /main.rs crate:main deps:std |
499 | use std::future::*; | 499 | use std::future::*; |
500 | struct A {} | 500 | struct A {} |
501 | impl Future for A {} | 501 | impl Future for A {} |
502 | fn foo(a: A) { a.<|> } | 502 | fn foo(a: A) { a.<|> } |
503 | 503 | ||
504 | //- /std/lib.rs | 504 | //- /std/lib.rs crate:std |
505 | pub mod future { | 505 | pub mod future { |
506 | #[lang = "future_trait"] | 506 | #[lang = "future_trait"] |
507 | pub trait Future {} | 507 | pub trait Future {} |
@@ -514,14 +514,14 @@ pub mod future { | |||
514 | 514 | ||
515 | check( | 515 | check( |
516 | r#" | 516 | r#" |
517 | //- /main.rs | 517 | //- /main.rs crate:main deps:std |
518 | use std::future::*; | 518 | use std::future::*; |
519 | fn foo() { | 519 | fn foo() { |
520 | let a = async {}; | 520 | let a = async {}; |
521 | a.<|> | 521 | a.<|> |
522 | } | 522 | } |
523 | 523 | ||
524 | //- /std/lib.rs | 524 | //- /std/lib.rs crate:std |
525 | pub mod future { | 525 | pub mod future { |
526 | #[lang = "future_trait"] | 526 | #[lang = "future_trait"] |
527 | pub trait Future { | 527 | pub trait Future { |
diff --git a/crates/ide/src/completion/complete_mod.rs b/crates/ide/src/completion/complete_mod.rs index 3cfc2e131..c7a99bdc3 100644 --- a/crates/ide/src/completion/complete_mod.rs +++ b/crates/ide/src/completion/complete_mod.rs | |||
@@ -300,7 +300,7 @@ mod tests { | |||
300 | // "#, | 300 | // "#, |
301 | // expect![[r#" | 301 | // expect![[r#" |
302 | // md bar; | 302 | // md bar; |
303 | // "#]], | 303 | // "#]],foo |
304 | // ); | 304 | // ); |
305 | // } | 305 | // } |
306 | 306 | ||
@@ -308,7 +308,7 @@ mod tests { | |||
308 | fn already_declared_bin_module_completion_omitted() { | 308 | fn already_declared_bin_module_completion_omitted() { |
309 | check( | 309 | check( |
310 | r#" | 310 | r#" |
311 | //- /src/bin.rs | 311 | //- /src/bin.rs crate:main |
312 | fn main() {} | 312 | fn main() {} |
313 | //- /src/bin/foo.rs | 313 | //- /src/bin/foo.rs |
314 | mod <|> | 314 | mod <|> |
diff --git a/crates/ide/src/completion/complete_qualified_path.rs b/crates/ide/src/completion/complete_qualified_path.rs index 00e89f0fd..2fafedd47 100644 --- a/crates/ide/src/completion/complete_qualified_path.rs +++ b/crates/ide/src/completion/complete_qualified_path.rs | |||
@@ -422,10 +422,10 @@ fn foo() { let _ = U::<|> } | |||
422 | fn completes_use_paths_across_crates() { | 422 | fn completes_use_paths_across_crates() { |
423 | check( | 423 | check( |
424 | r#" | 424 | r#" |
425 | //- /main.rs | 425 | //- /main.rs crate:main deps:foo |
426 | use foo::<|>; | 426 | use foo::<|>; |
427 | 427 | ||
428 | //- /foo/lib.rs | 428 | //- /foo/lib.rs crate:foo |
429 | pub mod bar { pub struct S; } | 429 | pub mod bar { pub struct S; } |
430 | "#, | 430 | "#, |
431 | expect![[r#" | 431 | expect![[r#" |
diff --git a/crates/ide/src/completion/complete_unqualified_path.rs b/crates/ide/src/completion/complete_unqualified_path.rs index 8eda4b64d..2010d9a2f 100644 --- a/crates/ide/src/completion/complete_unqualified_path.rs +++ b/crates/ide/src/completion/complete_unqualified_path.rs | |||
@@ -271,10 +271,10 @@ fn quux() { <|> } | |||
271 | fn completes_extern_prelude() { | 271 | fn completes_extern_prelude() { |
272 | check( | 272 | check( |
273 | r#" | 273 | r#" |
274 | //- /lib.rs | 274 | //- /lib.rs crate:main deps:other_crate |
275 | use <|>; | 275 | use <|>; |
276 | 276 | ||
277 | //- /other_crate/lib.rs | 277 | //- /other_crate/lib.rs crate:other_crate |
278 | // nothing here | 278 | // nothing here |
279 | "#, | 279 | "#, |
280 | expect![[r#" | 280 | expect![[r#" |
@@ -350,10 +350,10 @@ fn foo() { | |||
350 | fn completes_prelude() { | 350 | fn completes_prelude() { |
351 | check( | 351 | check( |
352 | r#" | 352 | r#" |
353 | //- /main.rs | 353 | //- /main.rs crate:main deps:std |
354 | fn foo() { let x: <|> } | 354 | fn foo() { let x: <|> } |
355 | 355 | ||
356 | //- /std/lib.rs | 356 | //- /std/lib.rs crate:std |
357 | #[prelude_import] | 357 | #[prelude_import] |
358 | use prelude::*; | 358 | use prelude::*; |
359 | 359 | ||
@@ -371,16 +371,16 @@ mod prelude { struct Option; } | |||
371 | fn completes_std_prelude_if_core_is_defined() { | 371 | fn completes_std_prelude_if_core_is_defined() { |
372 | check( | 372 | check( |
373 | r#" | 373 | r#" |
374 | //- /main.rs | 374 | //- /main.rs crate:main deps:core,std |
375 | fn foo() { let x: <|> } | 375 | fn foo() { let x: <|> } |
376 | 376 | ||
377 | //- /core/lib.rs | 377 | //- /core/lib.rs crate:core |
378 | #[prelude_import] | 378 | #[prelude_import] |
379 | use prelude::*; | 379 | use prelude::*; |
380 | 380 | ||
381 | mod prelude { struct Option; } | 381 | mod prelude { struct Option; } |
382 | 382 | ||
383 | //- /std/lib.rs | 383 | //- /std/lib.rs crate:std deps:core |
384 | #[prelude_import] | 384 | #[prelude_import] |
385 | use prelude::*; | 385 | use prelude::*; |
386 | 386 | ||
diff --git a/crates/ide/src/completion/presentation.rs b/crates/ide/src/completion/presentation.rs index 987cbfa7a..a5172b87e 100644 --- a/crates/ide/src/completion/presentation.rs +++ b/crates/ide/src/completion/presentation.rs | |||
@@ -1172,9 +1172,9 @@ fn foo(xs: Vec<i128>) | |||
1172 | check_edit( | 1172 | check_edit( |
1173 | "frobnicate!", | 1173 | "frobnicate!", |
1174 | r#" | 1174 | r#" |
1175 | //- /main.rs | 1175 | //- /main.rs crate:main deps:foo |
1176 | use foo::<|>; | 1176 | use foo::<|>; |
1177 | //- /foo/lib.rs | 1177 | //- /foo/lib.rs crate:foo |
1178 | #[macro_export] | 1178 | #[macro_export] |
1179 | macro_rules frobnicate { () => () } | 1179 | macro_rules frobnicate { () => () } |
1180 | "#, | 1180 | "#, |
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index dc815a483..906f72a42 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -219,7 +219,7 @@ mod tests { | |||
219 | use test_utils::assert_eq_text; | 219 | use test_utils::assert_eq_text; |
220 | 220 | ||
221 | use crate::{ | 221 | use crate::{ |
222 | mock_analysis::{analysis_and_position, single_file, MockAnalysis}, | 222 | mock_analysis::{analysis_and_position, many_files, single_file}, |
223 | DiagnosticsConfig, | 223 | DiagnosticsConfig, |
224 | }; | 224 | }; |
225 | 225 | ||
@@ -282,9 +282,7 @@ mod tests { | |||
282 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics | 282 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics |
283 | /// apply to the file containing the cursor. | 283 | /// apply to the file containing the cursor. |
284 | fn check_no_diagnostics(ra_fixture: &str) { | 284 | fn check_no_diagnostics(ra_fixture: &str) { |
285 | let mock = MockAnalysis::with_files(ra_fixture); | 285 | let (analysis, files) = many_files(ra_fixture); |
286 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); | ||
287 | let analysis = mock.analysis(); | ||
288 | let diagnostics = files | 286 | let diagnostics = files |
289 | .into_iter() | 287 | .into_iter() |
290 | .flat_map(|file_id| { | 288 | .flat_map(|file_id| { |
@@ -304,7 +302,7 @@ mod tests { | |||
304 | fn test_wrap_return_type() { | 302 | fn test_wrap_return_type() { |
305 | check_fix( | 303 | check_fix( |
306 | r#" | 304 | r#" |
307 | //- /main.rs | 305 | //- /main.rs crate:main deps:core |
308 | use core::result::Result::{self, Ok, Err}; | 306 | use core::result::Result::{self, Ok, Err}; |
309 | 307 | ||
310 | fn div(x: i32, y: i32) -> Result<i32, ()> { | 308 | fn div(x: i32, y: i32) -> Result<i32, ()> { |
@@ -313,7 +311,7 @@ fn div(x: i32, y: i32) -> Result<i32, ()> { | |||
313 | } | 311 | } |
314 | x / y<|> | 312 | x / y<|> |
315 | } | 313 | } |
316 | //- /core/lib.rs | 314 | //- /core/lib.rs crate:core |
317 | pub mod result { | 315 | pub mod result { |
318 | pub enum Result<T, E> { Ok(T), Err(E) } | 316 | pub enum Result<T, E> { Ok(T), Err(E) } |
319 | } | 317 | } |
@@ -335,7 +333,7 @@ fn div(x: i32, y: i32) -> Result<i32, ()> { | |||
335 | fn test_wrap_return_type_handles_generic_functions() { | 333 | fn test_wrap_return_type_handles_generic_functions() { |
336 | check_fix( | 334 | check_fix( |
337 | r#" | 335 | r#" |
338 | //- /main.rs | 336 | //- /main.rs crate:main deps:core |
339 | use core::result::Result::{self, Ok, Err}; | 337 | use core::result::Result::{self, Ok, Err}; |
340 | 338 | ||
341 | fn div<T>(x: T) -> Result<T, i32> { | 339 | fn div<T>(x: T) -> Result<T, i32> { |
@@ -344,7 +342,7 @@ fn div<T>(x: T) -> Result<T, i32> { | |||
344 | } | 342 | } |
345 | <|>x | 343 | <|>x |
346 | } | 344 | } |
347 | //- /core/lib.rs | 345 | //- /core/lib.rs crate:core |
348 | pub mod result { | 346 | pub mod result { |
349 | pub enum Result<T, E> { Ok(T), Err(E) } | 347 | pub enum Result<T, E> { Ok(T), Err(E) } |
350 | } | 348 | } |
@@ -366,7 +364,7 @@ fn div<T>(x: T) -> Result<T, i32> { | |||
366 | fn test_wrap_return_type_handles_type_aliases() { | 364 | fn test_wrap_return_type_handles_type_aliases() { |
367 | check_fix( | 365 | check_fix( |
368 | r#" | 366 | r#" |
369 | //- /main.rs | 367 | //- /main.rs crate:main deps:core |
370 | use core::result::Result::{self, Ok, Err}; | 368 | use core::result::Result::{self, Ok, Err}; |
371 | 369 | ||
372 | type MyResult<T> = Result<T, ()>; | 370 | type MyResult<T> = Result<T, ()>; |
@@ -377,7 +375,7 @@ fn div(x: i32, y: i32) -> MyResult<i32> { | |||
377 | } | 375 | } |
378 | x <|>/ y | 376 | x <|>/ y |
379 | } | 377 | } |
380 | //- /core/lib.rs | 378 | //- /core/lib.rs crate:core |
381 | pub mod result { | 379 | pub mod result { |
382 | pub enum Result<T, E> { Ok(T), Err(E) } | 380 | pub enum Result<T, E> { Ok(T), Err(E) } |
383 | } | 381 | } |
@@ -401,12 +399,12 @@ fn div(x: i32, y: i32) -> MyResult<i32> { | |||
401 | fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { | 399 | fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { |
402 | check_no_diagnostics( | 400 | check_no_diagnostics( |
403 | r#" | 401 | r#" |
404 | //- /main.rs | 402 | //- /main.rs crate:main deps:core |
405 | use core::result::Result::{self, Ok, Err}; | 403 | use core::result::Result::{self, Ok, Err}; |
406 | 404 | ||
407 | fn foo() -> Result<(), i32> { 0 } | 405 | fn foo() -> Result<(), i32> { 0 } |
408 | 406 | ||
409 | //- /core/lib.rs | 407 | //- /core/lib.rs crate:core |
410 | pub mod result { | 408 | pub mod result { |
411 | pub enum Result<T, E> { Ok(T), Err(E) } | 409 | pub enum Result<T, E> { Ok(T), Err(E) } |
412 | } | 410 | } |
@@ -418,14 +416,14 @@ pub mod result { | |||
418 | fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { | 416 | fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { |
419 | check_no_diagnostics( | 417 | check_no_diagnostics( |
420 | r#" | 418 | r#" |
421 | //- /main.rs | 419 | //- /main.rs crate:main deps:core |
422 | use core::result::Result::{self, Ok, Err}; | 420 | use core::result::Result::{self, Ok, Err}; |
423 | 421 | ||
424 | enum SomeOtherEnum { Ok(i32), Err(String) } | 422 | enum SomeOtherEnum { Ok(i32), Err(String) } |
425 | 423 | ||
426 | fn foo() -> SomeOtherEnum { 0 } | 424 | fn foo() -> SomeOtherEnum { 0 } |
427 | 425 | ||
428 | //- /core/lib.rs | 426 | //- /core/lib.rs crate:core |
429 | pub mod result { | 427 | pub mod result { |
430 | pub enum Result<T, E> { Ok(T), Err(E) } | 428 | pub enum Result<T, E> { Ok(T), Err(E) } |
431 | } | 429 | } |
@@ -567,7 +565,7 @@ fn test_fn() { | |||
567 | file_system_edits: [ | 565 | file_system_edits: [ |
568 | CreateFile { | 566 | CreateFile { |
569 | anchor: FileId( | 567 | anchor: FileId( |
570 | 1, | 568 | 0, |
571 | ), | 569 | ), |
572 | dst: "foo.rs", | 570 | dst: "foo.rs", |
573 | }, | 571 | }, |
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 1ee80c2dd..bace2f3a3 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -439,7 +439,7 @@ fn foo() { enum FooInner { } } | |||
439 | [ | 439 | [ |
440 | NavigationTarget { | 440 | NavigationTarget { |
441 | file_id: FileId( | 441 | file_id: FileId( |
442 | 1, | 442 | 0, |
443 | ), | 443 | ), |
444 | full_range: 0..17, | 444 | full_range: 0..17, |
445 | focus_range: Some( | 445 | focus_range: Some( |
@@ -455,7 +455,7 @@ fn foo() { enum FooInner { } } | |||
455 | }, | 455 | }, |
456 | NavigationTarget { | 456 | NavigationTarget { |
457 | file_id: FileId( | 457 | file_id: FileId( |
458 | 1, | 458 | 0, |
459 | ), | 459 | ), |
460 | full_range: 29..46, | 460 | full_range: 29..46, |
461 | focus_range: Some( | 461 | focus_range: Some( |
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 15e9b7fad..5fd2d1e9a 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -103,12 +103,11 @@ mod tests { | |||
103 | use base_db::FileRange; | 103 | use base_db::FileRange; |
104 | use syntax::{TextRange, TextSize}; | 104 | use syntax::{TextRange, TextSize}; |
105 | 105 | ||
106 | use crate::mock_analysis::MockAnalysis; | 106 | use crate::mock_analysis::analysis_and_annotations; |
107 | 107 | ||
108 | fn check(ra_fixture: &str) { | 108 | fn check(ra_fixture: &str) { |
109 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); | 109 | let (analysis, position, mut annotations) = analysis_and_annotations(ra_fixture); |
110 | let (mut expected, data) = mock.annotation(); | 110 | let (mut expected, data) = annotations.pop().unwrap(); |
111 | let analysis = mock.analysis(); | ||
112 | match data.as_str() { | 111 | match data.as_str() { |
113 | "" => (), | 112 | "" => (), |
114 | "file" => { | 113 | "file" => { |
@@ -133,9 +132,9 @@ mod tests { | |||
133 | fn goto_def_for_extern_crate() { | 132 | fn goto_def_for_extern_crate() { |
134 | check( | 133 | check( |
135 | r#" | 134 | r#" |
136 | //- /main.rs | 135 | //- /main.rs crate:main deps:std |
137 | extern crate std<|>; | 136 | extern crate std<|>; |
138 | //- /std/lib.rs | 137 | //- /std/lib.rs crate:std |
139 | // empty | 138 | // empty |
140 | //^ file | 139 | //^ file |
141 | "#, | 140 | "#, |
@@ -146,9 +145,9 @@ mod tests { | |||
146 | fn goto_def_for_renamed_extern_crate() { | 145 | fn goto_def_for_renamed_extern_crate() { |
147 | check( | 146 | check( |
148 | r#" | 147 | r#" |
149 | //- /main.rs | 148 | //- /main.rs crate:main deps:std |
150 | extern crate std as abc<|>; | 149 | extern crate std as abc<|>; |
151 | //- /std/lib.rs | 150 | //- /std/lib.rs crate:std |
152 | // empty | 151 | // empty |
153 | //^ file | 152 | //^ file |
154 | "#, | 153 | "#, |
@@ -342,10 +341,10 @@ fn bar() { | |||
342 | fn goto_def_for_use_alias() { | 341 | fn goto_def_for_use_alias() { |
343 | check( | 342 | check( |
344 | r#" | 343 | r#" |
345 | //- /lib.rs | 344 | //- /lib.rs crate:main deps:foo |
346 | use foo as bar<|>; | 345 | use foo as bar<|>; |
347 | 346 | ||
348 | //- /foo/lib.rs | 347 | //- /foo/lib.rs crate:foo |
349 | // empty | 348 | // empty |
350 | //^ file | 349 | //^ file |
351 | "#, | 350 | "#, |
@@ -356,10 +355,10 @@ use foo as bar<|>; | |||
356 | fn goto_def_for_use_alias_foo_macro() { | 355 | fn goto_def_for_use_alias_foo_macro() { |
357 | check( | 356 | check( |
358 | r#" | 357 | r#" |
359 | //- /lib.rs | 358 | //- /lib.rs crate:main deps:foo |
360 | use foo::foo as bar<|>; | 359 | use foo::foo as bar<|>; |
361 | 360 | ||
362 | //- /foo/lib.rs | 361 | //- /foo/lib.rs crate:foo |
363 | #[macro_export] | 362 | #[macro_export] |
364 | macro_rules! foo { () => { () } } | 363 | macro_rules! foo { () => { () } } |
365 | //^^^ | 364 | //^^^ |
@@ -371,7 +370,6 @@ macro_rules! foo { () => { () } } | |||
371 | fn goto_def_for_methods() { | 370 | fn goto_def_for_methods() { |
372 | check( | 371 | check( |
373 | r#" | 372 | r#" |
374 | //- /lib.rs | ||
375 | struct Foo; | 373 | struct Foo; |
376 | impl Foo { | 374 | impl Foo { |
377 | fn frobnicate(&self) { } | 375 | fn frobnicate(&self) { } |
diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index f503f4ec5..a88854d05 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs | |||
@@ -76,12 +76,10 @@ fn impls_for_trait( | |||
76 | mod tests { | 76 | mod tests { |
77 | use base_db::FileRange; | 77 | use base_db::FileRange; |
78 | 78 | ||
79 | use crate::mock_analysis::MockAnalysis; | 79 | use crate::mock_analysis::analysis_and_annotations; |
80 | 80 | ||
81 | fn check(ra_fixture: &str) { | 81 | fn check(ra_fixture: &str) { |
82 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); | 82 | let (analysis, position, annotations) = analysis_and_annotations(ra_fixture); |
83 | let annotations = mock.annotations(); | ||
84 | let analysis = mock.analysis(); | ||
85 | 83 | ||
86 | let navs = analysis.goto_implementation(position).unwrap().unwrap().info; | 84 | let navs = analysis.goto_implementation(position).unwrap().unwrap().info; |
87 | 85 | ||
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index 4a151b150..b55a2dbb1 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs | |||
@@ -56,13 +56,12 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | |||
56 | mod tests { | 56 | mod tests { |
57 | use base_db::FileRange; | 57 | use base_db::FileRange; |
58 | 58 | ||
59 | use crate::mock_analysis::MockAnalysis; | 59 | use crate::mock_analysis::analysis_and_annotations; |
60 | 60 | ||
61 | fn check(ra_fixture: &str) { | 61 | fn check(ra_fixture: &str) { |
62 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); | 62 | let (analysis, position, mut annotations) = analysis_and_annotations(ra_fixture); |
63 | let (expected, data) = mock.annotation(); | 63 | let (expected, data) = annotations.pop().unwrap(); |
64 | assert!(data.is_empty()); | 64 | assert!(data.is_empty()); |
65 | let analysis = mock.analysis(); | ||
66 | 65 | ||
67 | let mut navs = analysis.goto_type_definition(position).unwrap().unwrap().info; | 66 | let mut navs = analysis.goto_type_definition(position).unwrap().unwrap().info; |
68 | assert_eq!(navs.len(), 1); | 67 | assert_eq!(navs.len(), 1); |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index bb9f12cd3..008061a39 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1275,7 +1275,7 @@ fn bar() { fo<|>o(); } | |||
1275 | Implementaion( | 1275 | Implementaion( |
1276 | FilePosition { | 1276 | FilePosition { |
1277 | file_id: FileId( | 1277 | file_id: FileId( |
1278 | 1, | 1278 | 0, |
1279 | ), | 1279 | ), |
1280 | offset: 13, | 1280 | offset: 13, |
1281 | }, | 1281 | }, |
@@ -1289,9 +1289,9 @@ fn bar() { fo<|>o(); } | |||
1289 | fn test_hover_extern_crate() { | 1289 | fn test_hover_extern_crate() { |
1290 | check( | 1290 | check( |
1291 | r#" | 1291 | r#" |
1292 | //- /main.rs | 1292 | //- /main.rs crate:main deps:std |
1293 | extern crate st<|>d; | 1293 | extern crate st<|>d; |
1294 | //- /std/lib.rs | 1294 | //- /std/lib.rs crate:std |
1295 | //! Standard library for this test | 1295 | //! Standard library for this test |
1296 | //! | 1296 | //! |
1297 | //! Printed? | 1297 | //! Printed? |
@@ -1307,9 +1307,9 @@ extern crate st<|>d; | |||
1307 | ); | 1307 | ); |
1308 | check( | 1308 | check( |
1309 | r#" | 1309 | r#" |
1310 | //- /main.rs | 1310 | //- /main.rs crate:main deps:std |
1311 | extern crate std as ab<|>c; | 1311 | extern crate std as ab<|>c; |
1312 | //- /std/lib.rs | 1312 | //- /std/lib.rs crate:std |
1313 | //! Standard library for this test | 1313 | //! Standard library for this test |
1314 | //! | 1314 | //! |
1315 | //! Printed? | 1315 | //! Printed? |
@@ -1989,7 +1989,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
1989 | Implementaion( | 1989 | Implementaion( |
1990 | FilePosition { | 1990 | FilePosition { |
1991 | file_id: FileId( | 1991 | file_id: FileId( |
1992 | 1, | 1992 | 0, |
1993 | ), | 1993 | ), |
1994 | offset: 6, | 1994 | offset: 6, |
1995 | }, | 1995 | }, |
@@ -2008,7 +2008,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2008 | Implementaion( | 2008 | Implementaion( |
2009 | FilePosition { | 2009 | FilePosition { |
2010 | file_id: FileId( | 2010 | file_id: FileId( |
2011 | 1, | 2011 | 0, |
2012 | ), | 2012 | ), |
2013 | offset: 7, | 2013 | offset: 7, |
2014 | }, | 2014 | }, |
@@ -2027,7 +2027,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2027 | Implementaion( | 2027 | Implementaion( |
2028 | FilePosition { | 2028 | FilePosition { |
2029 | file_id: FileId( | 2029 | file_id: FileId( |
2030 | 1, | 2030 | 0, |
2031 | ), | 2031 | ), |
2032 | offset: 6, | 2032 | offset: 6, |
2033 | }, | 2033 | }, |
@@ -2046,7 +2046,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2046 | Implementaion( | 2046 | Implementaion( |
2047 | FilePosition { | 2047 | FilePosition { |
2048 | file_id: FileId( | 2048 | file_id: FileId( |
2049 | 1, | 2049 | 0, |
2050 | ), | 2050 | ), |
2051 | offset: 5, | 2051 | offset: 5, |
2052 | }, | 2052 | }, |
@@ -2069,7 +2069,7 @@ fn foo_<|>test() {} | |||
2069 | Runnable { | 2069 | Runnable { |
2070 | nav: NavigationTarget { | 2070 | nav: NavigationTarget { |
2071 | file_id: FileId( | 2071 | file_id: FileId( |
2072 | 1, | 2072 | 0, |
2073 | ), | 2073 | ), |
2074 | full_range: 0..24, | 2074 | full_range: 0..24, |
2075 | focus_range: Some( | 2075 | focus_range: Some( |
@@ -2112,7 +2112,7 @@ mod tests<|> { | |||
2112 | Runnable { | 2112 | Runnable { |
2113 | nav: NavigationTarget { | 2113 | nav: NavigationTarget { |
2114 | file_id: FileId( | 2114 | file_id: FileId( |
2115 | 1, | 2115 | 0, |
2116 | ), | 2116 | ), |
2117 | full_range: 0..46, | 2117 | full_range: 0..46, |
2118 | focus_range: Some( | 2118 | focus_range: Some( |
@@ -2151,7 +2151,7 @@ fn main() { let s<|>t = S{ f1:0 }; } | |||
2151 | mod_path: "test::S", | 2151 | mod_path: "test::S", |
2152 | nav: NavigationTarget { | 2152 | nav: NavigationTarget { |
2153 | file_id: FileId( | 2153 | file_id: FileId( |
2154 | 1, | 2154 | 0, |
2155 | ), | 2155 | ), |
2156 | full_range: 0..19, | 2156 | full_range: 0..19, |
2157 | focus_range: Some( | 2157 | focus_range: Some( |
@@ -2190,7 +2190,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } | |||
2190 | mod_path: "test::S", | 2190 | mod_path: "test::S", |
2191 | nav: NavigationTarget { | 2191 | nav: NavigationTarget { |
2192 | file_id: FileId( | 2192 | file_id: FileId( |
2193 | 1, | 2193 | 0, |
2194 | ), | 2194 | ), |
2195 | full_range: 17..37, | 2195 | full_range: 17..37, |
2196 | focus_range: Some( | 2196 | focus_range: Some( |
@@ -2209,7 +2209,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } | |||
2209 | mod_path: "test::Arg", | 2209 | mod_path: "test::Arg", |
2210 | nav: NavigationTarget { | 2210 | nav: NavigationTarget { |
2211 | file_id: FileId( | 2211 | file_id: FileId( |
2212 | 1, | 2212 | 0, |
2213 | ), | 2213 | ), |
2214 | full_range: 0..16, | 2214 | full_range: 0..16, |
2215 | focus_range: Some( | 2215 | focus_range: Some( |
@@ -2248,7 +2248,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } | |||
2248 | mod_path: "test::S", | 2248 | mod_path: "test::S", |
2249 | nav: NavigationTarget { | 2249 | nav: NavigationTarget { |
2250 | file_id: FileId( | 2250 | file_id: FileId( |
2251 | 1, | 2251 | 0, |
2252 | ), | 2252 | ), |
2253 | full_range: 17..37, | 2253 | full_range: 17..37, |
2254 | focus_range: Some( | 2254 | focus_range: Some( |
@@ -2267,7 +2267,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } | |||
2267 | mod_path: "test::Arg", | 2267 | mod_path: "test::Arg", |
2268 | nav: NavigationTarget { | 2268 | nav: NavigationTarget { |
2269 | file_id: FileId( | 2269 | file_id: FileId( |
2270 | 1, | 2270 | 0, |
2271 | ), | 2271 | ), |
2272 | full_range: 0..16, | 2272 | full_range: 0..16, |
2273 | focus_range: Some( | 2273 | focus_range: Some( |
@@ -2309,7 +2309,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } | |||
2309 | mod_path: "test::A", | 2309 | mod_path: "test::A", |
2310 | nav: NavigationTarget { | 2310 | nav: NavigationTarget { |
2311 | file_id: FileId( | 2311 | file_id: FileId( |
2312 | 1, | 2312 | 0, |
2313 | ), | 2313 | ), |
2314 | full_range: 0..14, | 2314 | full_range: 0..14, |
2315 | focus_range: Some( | 2315 | focus_range: Some( |
@@ -2328,7 +2328,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } | |||
2328 | mod_path: "test::B", | 2328 | mod_path: "test::B", |
2329 | nav: NavigationTarget { | 2329 | nav: NavigationTarget { |
2330 | file_id: FileId( | 2330 | file_id: FileId( |
2331 | 1, | 2331 | 0, |
2332 | ), | 2332 | ), |
2333 | full_range: 15..29, | 2333 | full_range: 15..29, |
2334 | focus_range: Some( | 2334 | focus_range: Some( |
@@ -2347,7 +2347,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } | |||
2347 | mod_path: "test::M::C", | 2347 | mod_path: "test::M::C", |
2348 | nav: NavigationTarget { | 2348 | nav: NavigationTarget { |
2349 | file_id: FileId( | 2349 | file_id: FileId( |
2350 | 1, | 2350 | 0, |
2351 | ), | 2351 | ), |
2352 | full_range: 42..60, | 2352 | full_range: 42..60, |
2353 | focus_range: Some( | 2353 | focus_range: Some( |
@@ -2386,7 +2386,7 @@ fn main() { let s<|>t = foo(); } | |||
2386 | mod_path: "test::Foo", | 2386 | mod_path: "test::Foo", |
2387 | nav: NavigationTarget { | 2387 | nav: NavigationTarget { |
2388 | file_id: FileId( | 2388 | file_id: FileId( |
2389 | 1, | 2389 | 0, |
2390 | ), | 2390 | ), |
2391 | full_range: 0..12, | 2391 | full_range: 0..12, |
2392 | focus_range: Some( | 2392 | focus_range: Some( |
@@ -2426,7 +2426,7 @@ fn main() { let s<|>t = foo(); } | |||
2426 | mod_path: "test::Foo", | 2426 | mod_path: "test::Foo", |
2427 | nav: NavigationTarget { | 2427 | nav: NavigationTarget { |
2428 | file_id: FileId( | 2428 | file_id: FileId( |
2429 | 1, | 2429 | 0, |
2430 | ), | 2430 | ), |
2431 | full_range: 0..15, | 2431 | full_range: 0..15, |
2432 | focus_range: Some( | 2432 | focus_range: Some( |
@@ -2445,7 +2445,7 @@ fn main() { let s<|>t = foo(); } | |||
2445 | mod_path: "test::S", | 2445 | mod_path: "test::S", |
2446 | nav: NavigationTarget { | 2446 | nav: NavigationTarget { |
2447 | file_id: FileId( | 2447 | file_id: FileId( |
2448 | 1, | 2448 | 0, |
2449 | ), | 2449 | ), |
2450 | full_range: 16..25, | 2450 | full_range: 16..25, |
2451 | focus_range: Some( | 2451 | focus_range: Some( |
@@ -2485,7 +2485,7 @@ fn main() { let s<|>t = foo(); } | |||
2485 | mod_path: "test::Foo", | 2485 | mod_path: "test::Foo", |
2486 | nav: NavigationTarget { | 2486 | nav: NavigationTarget { |
2487 | file_id: FileId( | 2487 | file_id: FileId( |
2488 | 1, | 2488 | 0, |
2489 | ), | 2489 | ), |
2490 | full_range: 0..12, | 2490 | full_range: 0..12, |
2491 | focus_range: Some( | 2491 | focus_range: Some( |
@@ -2504,7 +2504,7 @@ fn main() { let s<|>t = foo(); } | |||
2504 | mod_path: "test::Bar", | 2504 | mod_path: "test::Bar", |
2505 | nav: NavigationTarget { | 2505 | nav: NavigationTarget { |
2506 | file_id: FileId( | 2506 | file_id: FileId( |
2507 | 1, | 2507 | 0, |
2508 | ), | 2508 | ), |
2509 | full_range: 13..25, | 2509 | full_range: 13..25, |
2510 | focus_range: Some( | 2510 | focus_range: Some( |
@@ -2547,7 +2547,7 @@ fn main() { let s<|>t = foo(); } | |||
2547 | mod_path: "test::Foo", | 2547 | mod_path: "test::Foo", |
2548 | nav: NavigationTarget { | 2548 | nav: NavigationTarget { |
2549 | file_id: FileId( | 2549 | file_id: FileId( |
2550 | 1, | 2550 | 0, |
2551 | ), | 2551 | ), |
2552 | full_range: 0..15, | 2552 | full_range: 0..15, |
2553 | focus_range: Some( | 2553 | focus_range: Some( |
@@ -2566,7 +2566,7 @@ fn main() { let s<|>t = foo(); } | |||
2566 | mod_path: "test::Bar", | 2566 | mod_path: "test::Bar", |
2567 | nav: NavigationTarget { | 2567 | nav: NavigationTarget { |
2568 | file_id: FileId( | 2568 | file_id: FileId( |
2569 | 1, | 2569 | 0, |
2570 | ), | 2570 | ), |
2571 | full_range: 16..31, | 2571 | full_range: 16..31, |
2572 | focus_range: Some( | 2572 | focus_range: Some( |
@@ -2585,7 +2585,7 @@ fn main() { let s<|>t = foo(); } | |||
2585 | mod_path: "test::S1", | 2585 | mod_path: "test::S1", |
2586 | nav: NavigationTarget { | 2586 | nav: NavigationTarget { |
2587 | file_id: FileId( | 2587 | file_id: FileId( |
2588 | 1, | 2588 | 0, |
2589 | ), | 2589 | ), |
2590 | full_range: 32..44, | 2590 | full_range: 32..44, |
2591 | focus_range: Some( | 2591 | focus_range: Some( |
@@ -2604,7 +2604,7 @@ fn main() { let s<|>t = foo(); } | |||
2604 | mod_path: "test::S2", | 2604 | mod_path: "test::S2", |
2605 | nav: NavigationTarget { | 2605 | nav: NavigationTarget { |
2606 | file_id: FileId( | 2606 | file_id: FileId( |
2607 | 1, | 2607 | 0, |
2608 | ), | 2608 | ), |
2609 | full_range: 45..57, | 2609 | full_range: 45..57, |
2610 | focus_range: Some( | 2610 | focus_range: Some( |
@@ -2641,7 +2641,7 @@ fn foo(ar<|>g: &impl Foo) {} | |||
2641 | mod_path: "test::Foo", | 2641 | mod_path: "test::Foo", |
2642 | nav: NavigationTarget { | 2642 | nav: NavigationTarget { |
2643 | file_id: FileId( | 2643 | file_id: FileId( |
2644 | 1, | 2644 | 0, |
2645 | ), | 2645 | ), |
2646 | full_range: 0..12, | 2646 | full_range: 0..12, |
2647 | focus_range: Some( | 2647 | focus_range: Some( |
@@ -2681,7 +2681,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {} | |||
2681 | mod_path: "test::Foo", | 2681 | mod_path: "test::Foo", |
2682 | nav: NavigationTarget { | 2682 | nav: NavigationTarget { |
2683 | file_id: FileId( | 2683 | file_id: FileId( |
2684 | 1, | 2684 | 0, |
2685 | ), | 2685 | ), |
2686 | full_range: 0..12, | 2686 | full_range: 0..12, |
2687 | focus_range: Some( | 2687 | focus_range: Some( |
@@ -2700,7 +2700,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {} | |||
2700 | mod_path: "test::Bar", | 2700 | mod_path: "test::Bar", |
2701 | nav: NavigationTarget { | 2701 | nav: NavigationTarget { |
2702 | file_id: FileId( | 2702 | file_id: FileId( |
2703 | 1, | 2703 | 0, |
2704 | ), | 2704 | ), |
2705 | full_range: 13..28, | 2705 | full_range: 13..28, |
2706 | focus_range: Some( | 2706 | focus_range: Some( |
@@ -2719,7 +2719,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {} | |||
2719 | mod_path: "test::S", | 2719 | mod_path: "test::S", |
2720 | nav: NavigationTarget { | 2720 | nav: NavigationTarget { |
2721 | file_id: FileId( | 2721 | file_id: FileId( |
2722 | 1, | 2722 | 0, |
2723 | ), | 2723 | ), |
2724 | full_range: 29..39, | 2724 | full_range: 29..39, |
2725 | focus_range: Some( | 2725 | focus_range: Some( |
@@ -2764,7 +2764,7 @@ mod future { | |||
2764 | mod_path: "test::future::Future", | 2764 | mod_path: "test::future::Future", |
2765 | nav: NavigationTarget { | 2765 | nav: NavigationTarget { |
2766 | file_id: FileId( | 2766 | file_id: FileId( |
2767 | 1, | 2767 | 0, |
2768 | ), | 2768 | ), |
2769 | full_range: 101..163, | 2769 | full_range: 101..163, |
2770 | focus_range: Some( | 2770 | focus_range: Some( |
@@ -2783,7 +2783,7 @@ mod future { | |||
2783 | mod_path: "test::S", | 2783 | mod_path: "test::S", |
2784 | nav: NavigationTarget { | 2784 | nav: NavigationTarget { |
2785 | file_id: FileId( | 2785 | file_id: FileId( |
2786 | 1, | 2786 | 0, |
2787 | ), | 2787 | ), |
2788 | full_range: 0..9, | 2788 | full_range: 0..9, |
2789 | focus_range: Some( | 2789 | focus_range: Some( |
@@ -2821,7 +2821,7 @@ fn foo(ar<|>g: &impl Foo<S>) {} | |||
2821 | mod_path: "test::Foo", | 2821 | mod_path: "test::Foo", |
2822 | nav: NavigationTarget { | 2822 | nav: NavigationTarget { |
2823 | file_id: FileId( | 2823 | file_id: FileId( |
2824 | 1, | 2824 | 0, |
2825 | ), | 2825 | ), |
2826 | full_range: 0..15, | 2826 | full_range: 0..15, |
2827 | focus_range: Some( | 2827 | focus_range: Some( |
@@ -2840,7 +2840,7 @@ fn foo(ar<|>g: &impl Foo<S>) {} | |||
2840 | mod_path: "test::S", | 2840 | mod_path: "test::S", |
2841 | nav: NavigationTarget { | 2841 | nav: NavigationTarget { |
2842 | file_id: FileId( | 2842 | file_id: FileId( |
2843 | 1, | 2843 | 0, |
2844 | ), | 2844 | ), |
2845 | full_range: 16..27, | 2845 | full_range: 16..27, |
2846 | focus_range: Some( | 2846 | focus_range: Some( |
@@ -2883,7 +2883,7 @@ fn main() { let s<|>t = foo(); } | |||
2883 | mod_path: "test::B", | 2883 | mod_path: "test::B", |
2884 | nav: NavigationTarget { | 2884 | nav: NavigationTarget { |
2885 | file_id: FileId( | 2885 | file_id: FileId( |
2886 | 1, | 2886 | 0, |
2887 | ), | 2887 | ), |
2888 | full_range: 42..55, | 2888 | full_range: 42..55, |
2889 | focus_range: Some( | 2889 | focus_range: Some( |
@@ -2902,7 +2902,7 @@ fn main() { let s<|>t = foo(); } | |||
2902 | mod_path: "test::Foo", | 2902 | mod_path: "test::Foo", |
2903 | nav: NavigationTarget { | 2903 | nav: NavigationTarget { |
2904 | file_id: FileId( | 2904 | file_id: FileId( |
2905 | 1, | 2905 | 0, |
2906 | ), | 2906 | ), |
2907 | full_range: 0..12, | 2907 | full_range: 0..12, |
2908 | focus_range: Some( | 2908 | focus_range: Some( |
@@ -2939,7 +2939,7 @@ fn foo(ar<|>g: &dyn Foo) {} | |||
2939 | mod_path: "test::Foo", | 2939 | mod_path: "test::Foo", |
2940 | nav: NavigationTarget { | 2940 | nav: NavigationTarget { |
2941 | file_id: FileId( | 2941 | file_id: FileId( |
2942 | 1, | 2942 | 0, |
2943 | ), | 2943 | ), |
2944 | full_range: 0..12, | 2944 | full_range: 0..12, |
2945 | focus_range: Some( | 2945 | focus_range: Some( |
@@ -2977,7 +2977,7 @@ fn foo(ar<|>g: &dyn Foo<S>) {} | |||
2977 | mod_path: "test::Foo", | 2977 | mod_path: "test::Foo", |
2978 | nav: NavigationTarget { | 2978 | nav: NavigationTarget { |
2979 | file_id: FileId( | 2979 | file_id: FileId( |
2980 | 1, | 2980 | 0, |
2981 | ), | 2981 | ), |
2982 | full_range: 0..15, | 2982 | full_range: 0..15, |
2983 | focus_range: Some( | 2983 | focus_range: Some( |
@@ -2996,7 +2996,7 @@ fn foo(ar<|>g: &dyn Foo<S>) {} | |||
2996 | mod_path: "test::S", | 2996 | mod_path: "test::S", |
2997 | nav: NavigationTarget { | 2997 | nav: NavigationTarget { |
2998 | file_id: FileId( | 2998 | file_id: FileId( |
2999 | 1, | 2999 | 0, |
3000 | ), | 3000 | ), |
3001 | full_range: 16..27, | 3001 | full_range: 16..27, |
3002 | focus_range: Some( | 3002 | focus_range: Some( |
@@ -3037,7 +3037,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {} | |||
3037 | mod_path: "test::ImplTrait", | 3037 | mod_path: "test::ImplTrait", |
3038 | nav: NavigationTarget { | 3038 | nav: NavigationTarget { |
3039 | file_id: FileId( | 3039 | file_id: FileId( |
3040 | 1, | 3040 | 0, |
3041 | ), | 3041 | ), |
3042 | full_range: 0..21, | 3042 | full_range: 0..21, |
3043 | focus_range: Some( | 3043 | focus_range: Some( |
@@ -3056,7 +3056,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {} | |||
3056 | mod_path: "test::B", | 3056 | mod_path: "test::B", |
3057 | nav: NavigationTarget { | 3057 | nav: NavigationTarget { |
3058 | file_id: FileId( | 3058 | file_id: FileId( |
3059 | 1, | 3059 | 0, |
3060 | ), | 3060 | ), |
3061 | full_range: 43..57, | 3061 | full_range: 43..57, |
3062 | focus_range: Some( | 3062 | focus_range: Some( |
@@ -3075,7 +3075,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {} | |||
3075 | mod_path: "test::DynTrait", | 3075 | mod_path: "test::DynTrait", |
3076 | nav: NavigationTarget { | 3076 | nav: NavigationTarget { |
3077 | file_id: FileId( | 3077 | file_id: FileId( |
3078 | 1, | 3078 | 0, |
3079 | ), | 3079 | ), |
3080 | full_range: 22..42, | 3080 | full_range: 22..42, |
3081 | focus_range: Some( | 3081 | focus_range: Some( |
@@ -3094,7 +3094,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {} | |||
3094 | mod_path: "test::S", | 3094 | mod_path: "test::S", |
3095 | nav: NavigationTarget { | 3095 | nav: NavigationTarget { |
3096 | file_id: FileId( | 3096 | file_id: FileId( |
3097 | 1, | 3097 | 0, |
3098 | ), | 3098 | ), |
3099 | full_range: 58..69, | 3099 | full_range: 58..69, |
3100 | focus_range: Some( | 3100 | focus_range: Some( |
@@ -3142,7 +3142,7 @@ fn main() { let s<|>t = test().get(); } | |||
3142 | mod_path: "test::Foo", | 3142 | mod_path: "test::Foo", |
3143 | nav: NavigationTarget { | 3143 | nav: NavigationTarget { |
3144 | file_id: FileId( | 3144 | file_id: FileId( |
3145 | 1, | 3145 | 0, |
3146 | ), | 3146 | ), |
3147 | full_range: 0..62, | 3147 | full_range: 0..62, |
3148 | focus_range: Some( | 3148 | focus_range: Some( |
diff --git a/crates/ide/src/mock_analysis.rs b/crates/ide/src/mock_analysis.rs index 6812db9b9..838547599 100644 --- a/crates/ide/src/mock_analysis.rs +++ b/crates/ide/src/mock_analysis.rs | |||
@@ -1,174 +1,73 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | use std::sync::Arc; | ||
3 | 2 | ||
4 | use base_db::{CrateName, FileSet, SourceRoot, VfsPath}; | 3 | use base_db::fixture::ChangeFixture; |
5 | use cfg::CfgOptions; | 4 | use test_utils::{extract_annotations, RangeOrOffset}; |
6 | use test_utils::{ | ||
7 | extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, | ||
8 | }; | ||
9 | 5 | ||
10 | use crate::{Analysis, AnalysisHost, Change, CrateGraph, Edition, FileId, FilePosition, FileRange}; | 6 | use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; |
11 | |||
12 | /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis | ||
13 | /// from a set of in-memory files. | ||
14 | #[derive(Debug, Default)] | ||
15 | pub(crate) struct MockAnalysis { | ||
16 | files: Vec<Fixture>, | ||
17 | } | ||
18 | |||
19 | impl MockAnalysis { | ||
20 | /// Creates `MockAnalysis` using a fixture data in the following format: | ||
21 | /// | ||
22 | /// ```not_rust | ||
23 | /// //- /main.rs | ||
24 | /// mod foo; | ||
25 | /// fn main() {} | ||
26 | /// | ||
27 | /// //- /foo.rs | ||
28 | /// struct Baz; | ||
29 | /// ``` | ||
30 | pub(crate) fn with_files(ra_fixture: &str) -> MockAnalysis { | ||
31 | let (res, pos) = MockAnalysis::with_fixture(ra_fixture); | ||
32 | assert!(pos.is_none()); | ||
33 | res | ||
34 | } | ||
35 | |||
36 | /// Same as `with_files`, but requires that a single file contains a `<|>` marker, | ||
37 | /// whose position is also returned. | ||
38 | pub(crate) fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { | ||
39 | let (res, position) = MockAnalysis::with_fixture(fixture); | ||
40 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); | ||
41 | let offset = match range_or_offset { | ||
42 | RangeOrOffset::Range(_) => panic!(), | ||
43 | RangeOrOffset::Offset(it) => it, | ||
44 | }; | ||
45 | (res, FilePosition { file_id, offset }) | ||
46 | } | ||
47 | |||
48 | fn with_fixture(fixture: &str) -> (MockAnalysis, Option<(FileId, RangeOrOffset)>) { | ||
49 | let mut position = None; | ||
50 | let mut res = MockAnalysis::default(); | ||
51 | for mut entry in Fixture::parse(fixture) { | ||
52 | if entry.text.contains(CURSOR_MARKER) { | ||
53 | assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); | ||
54 | let (range_or_offset, text) = extract_range_or_offset(&entry.text); | ||
55 | entry.text = text; | ||
56 | let file_id = res.add_file_fixture(entry); | ||
57 | position = Some((file_id, range_or_offset)); | ||
58 | } else { | ||
59 | res.add_file_fixture(entry); | ||
60 | } | ||
61 | } | ||
62 | (res, position) | ||
63 | } | ||
64 | |||
65 | fn add_file_fixture(&mut self, fixture: Fixture) -> FileId { | ||
66 | let file_id = FileId((self.files.len() + 1) as u32); | ||
67 | self.files.push(fixture); | ||
68 | file_id | ||
69 | } | ||
70 | |||
71 | pub(crate) fn id_of(&self, path: &str) -> FileId { | ||
72 | let (file_id, _) = | ||
73 | self.files().find(|(_, data)| path == data.path).expect("no file in this mock"); | ||
74 | file_id | ||
75 | } | ||
76 | pub(crate) fn annotations(&self) -> Vec<(FileRange, String)> { | ||
77 | self.files() | ||
78 | .flat_map(|(file_id, fixture)| { | ||
79 | let annotations = extract_annotations(&fixture.text); | ||
80 | annotations | ||
81 | .into_iter() | ||
82 | .map(move |(range, data)| (FileRange { file_id, range }, data)) | ||
83 | }) | ||
84 | .collect() | ||
85 | } | ||
86 | pub(crate) fn files(&self) -> impl Iterator<Item = (FileId, &Fixture)> + '_ { | ||
87 | self.files.iter().enumerate().map(|(idx, fixture)| (FileId(idx as u32 + 1), fixture)) | ||
88 | } | ||
89 | pub(crate) fn annotation(&self) -> (FileRange, String) { | ||
90 | let mut all = self.annotations(); | ||
91 | assert_eq!(all.len(), 1); | ||
92 | all.pop().unwrap() | ||
93 | } | ||
94 | pub(crate) fn analysis_host(self) -> AnalysisHost { | ||
95 | let mut host = AnalysisHost::default(); | ||
96 | let mut change = Change::new(); | ||
97 | let mut file_set = FileSet::default(); | ||
98 | let mut crate_graph = CrateGraph::default(); | ||
99 | let mut root_crate = None; | ||
100 | for (i, data) in self.files.into_iter().enumerate() { | ||
101 | let path = data.path; | ||
102 | assert!(path.starts_with('/')); | ||
103 | |||
104 | let mut cfg = CfgOptions::default(); | ||
105 | data.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); | ||
106 | data.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); | ||
107 | let edition: Edition = | ||
108 | data.edition.and_then(|it| it.parse().ok()).unwrap_or(Edition::Edition2018); | ||
109 | |||
110 | let file_id = FileId(i as u32 + 1); | ||
111 | let env = data.env.into_iter().collect(); | ||
112 | if path == "/lib.rs" || path == "/main.rs" { | ||
113 | root_crate = Some(crate_graph.add_crate_root( | ||
114 | file_id, | ||
115 | edition, | ||
116 | Some("test".to_string()), | ||
117 | cfg, | ||
118 | env, | ||
119 | Default::default(), | ||
120 | )); | ||
121 | } else if path.ends_with("/lib.rs") { | ||
122 | let base = &path[..path.len() - "/lib.rs".len()]; | ||
123 | let crate_name = &base[base.rfind('/').unwrap() + '/'.len_utf8()..]; | ||
124 | let other_crate = crate_graph.add_crate_root( | ||
125 | file_id, | ||
126 | edition, | ||
127 | Some(crate_name.to_string()), | ||
128 | cfg, | ||
129 | env, | ||
130 | Default::default(), | ||
131 | ); | ||
132 | if let Some(root_crate) = root_crate { | ||
133 | crate_graph | ||
134 | .add_dep(root_crate, CrateName::new(crate_name).unwrap(), other_crate) | ||
135 | .unwrap(); | ||
136 | } | ||
137 | } | ||
138 | let path = VfsPath::new_virtual_path(path.to_string()); | ||
139 | file_set.insert(file_id, path); | ||
140 | change.change_file(file_id, Some(Arc::new(data.text).to_owned())); | ||
141 | } | ||
142 | change.set_crate_graph(crate_graph); | ||
143 | change.set_roots(vec![SourceRoot::new_local(file_set)]); | ||
144 | host.apply_change(change); | ||
145 | host | ||
146 | } | ||
147 | pub(crate) fn analysis(self) -> Analysis { | ||
148 | self.analysis_host().analysis() | ||
149 | } | ||
150 | } | ||
151 | 7 | ||
152 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | 8 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. |
153 | pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { | 9 | pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { |
154 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); | 10 | let mut host = AnalysisHost::default(); |
155 | (mock.analysis(), position) | 11 | let change_fixture = ChangeFixture::parse(ra_fixture); |
12 | host.db.apply_change(change_fixture.change); | ||
13 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); | ||
14 | let offset = match range_or_offset { | ||
15 | RangeOrOffset::Range(_) => panic!(), | ||
16 | RangeOrOffset::Offset(it) => it, | ||
17 | }; | ||
18 | (host.analysis(), FilePosition { file_id, offset }) | ||
156 | } | 19 | } |
157 | 20 | ||
158 | /// Creates analysis for a single file. | 21 | /// Creates analysis for a single file. |
159 | pub(crate) fn single_file(ra_fixture: &str) -> (Analysis, FileId) { | 22 | pub(crate) fn single_file(ra_fixture: &str) -> (Analysis, FileId) { |
160 | let mock = MockAnalysis::with_files(ra_fixture); | 23 | let mut host = AnalysisHost::default(); |
161 | let file_id = mock.id_of("/main.rs"); | 24 | let change_fixture = ChangeFixture::parse(ra_fixture); |
162 | (mock.analysis(), file_id) | 25 | host.db.apply_change(change_fixture.change); |
26 | (host.analysis(), change_fixture.files[0]) | ||
27 | } | ||
28 | |||
29 | /// Creates analysis for a single file. | ||
30 | pub(crate) fn many_files(ra_fixture: &str) -> (Analysis, Vec<FileId>) { | ||
31 | let mut host = AnalysisHost::default(); | ||
32 | let change_fixture = ChangeFixture::parse(ra_fixture); | ||
33 | host.db.apply_change(change_fixture.change); | ||
34 | (host.analysis(), change_fixture.files) | ||
163 | } | 35 | } |
164 | 36 | ||
165 | /// Creates analysis for a single file, returns range marked with a pair of <|>. | 37 | /// Creates analysis for a single file, returns range marked with a pair of <|>. |
166 | pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) { | 38 | pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) { |
167 | let (res, position) = MockAnalysis::with_fixture(ra_fixture); | 39 | let mut host = AnalysisHost::default(); |
168 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); | 40 | let change_fixture = ChangeFixture::parse(ra_fixture); |
41 | host.db.apply_change(change_fixture.change); | ||
42 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); | ||
169 | let range = match range_or_offset { | 43 | let range = match range_or_offset { |
170 | RangeOrOffset::Range(it) => it, | 44 | RangeOrOffset::Range(it) => it, |
171 | RangeOrOffset::Offset(_) => panic!(), | 45 | RangeOrOffset::Offset(_) => panic!(), |
172 | }; | 46 | }; |
173 | (res.analysis(), FileRange { file_id, range }) | 47 | (host.analysis(), FileRange { file_id, range }) |
48 | } | ||
49 | |||
50 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | ||
51 | pub(crate) fn analysis_and_annotations( | ||
52 | ra_fixture: &str, | ||
53 | ) -> (Analysis, FilePosition, Vec<(FileRange, String)>) { | ||
54 | let mut host = AnalysisHost::default(); | ||
55 | let change_fixture = ChangeFixture::parse(ra_fixture); | ||
56 | host.db.apply_change(change_fixture.change); | ||
57 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); | ||
58 | let offset = match range_or_offset { | ||
59 | RangeOrOffset::Range(_) => panic!(), | ||
60 | RangeOrOffset::Offset(it) => it, | ||
61 | }; | ||
62 | |||
63 | let annotations = change_fixture | ||
64 | .files | ||
65 | .iter() | ||
66 | .flat_map(|&file_id| { | ||
67 | let file_text = host.analysis().file_text(file_id).unwrap(); | ||
68 | let annotations = extract_annotations(&file_text); | ||
69 | annotations.into_iter().map(move |(range, data)| (FileRange { file_id, range }, data)) | ||
70 | }) | ||
71 | .collect(); | ||
72 | (host.analysis(), FilePosition { file_id, offset }, annotations) | ||
174 | } | 73 | } |
diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 68b107901..253454476 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs | |||
@@ -63,15 +63,9 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | |||
63 | 63 | ||
64 | #[cfg(test)] | 64 | #[cfg(test)] |
65 | mod tests { | 65 | mod tests { |
66 | use base_db::Env; | ||
67 | use cfg::CfgOptions; | ||
68 | use test_utils::mark; | 66 | use test_utils::mark; |
69 | 67 | ||
70 | use crate::{ | 68 | use crate::mock_analysis::{analysis_and_position, single_file}; |
71 | mock_analysis::{analysis_and_position, MockAnalysis}, | ||
72 | Change, CrateGraph, | ||
73 | Edition::Edition2018, | ||
74 | }; | ||
75 | 69 | ||
76 | #[test] | 70 | #[test] |
77 | fn test_resolve_parent_module() { | 71 | fn test_resolve_parent_module() { |
@@ -84,7 +78,7 @@ mod tests { | |||
84 | ", | 78 | ", |
85 | ); | 79 | ); |
86 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 80 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
87 | nav.assert_match("foo MODULE FileId(1) 0..8"); | 81 | nav.assert_match("foo MODULE FileId(0) 0..8"); |
88 | } | 82 | } |
89 | 83 | ||
90 | #[test] | 84 | #[test] |
@@ -103,7 +97,7 @@ mod tests { | |||
103 | ", | 97 | ", |
104 | ); | 98 | ); |
105 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 99 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
106 | nav.assert_match("foo MODULE FileId(1) 0..8"); | 100 | nav.assert_match("foo MODULE FileId(0) 0..8"); |
107 | } | 101 | } |
108 | 102 | ||
109 | #[test] | 103 | #[test] |
@@ -119,37 +113,19 @@ mod tests { | |||
119 | ", | 113 | ", |
120 | ); | 114 | ); |
121 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 115 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
122 | nav.assert_match("baz MODULE FileId(1) 32..44"); | 116 | nav.assert_match("baz MODULE FileId(0) 32..44"); |
123 | } | 117 | } |
124 | 118 | ||
125 | #[test] | 119 | #[test] |
126 | fn test_resolve_crate_root() { | 120 | fn test_resolve_crate_root() { |
127 | let mock = MockAnalysis::with_files( | 121 | let (analysis, file_id) = single_file( |
128 | r#" | 122 | r#" |
129 | //- /bar.rs | 123 | //- /main.rs |
130 | mod foo; | 124 | mod foo; |
131 | //- /foo.rs | 125 | //- /foo.rs |
132 | // empty | 126 | <|> |
133 | "#, | 127 | "#, |
134 | ); | 128 | ); |
135 | let root_file = mock.id_of("/bar.rs"); | 129 | assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1); |
136 | let mod_file = mock.id_of("/foo.rs"); | ||
137 | let mut host = mock.analysis_host(); | ||
138 | assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); | ||
139 | |||
140 | let mut crate_graph = CrateGraph::default(); | ||
141 | let crate_id = crate_graph.add_crate_root( | ||
142 | root_file, | ||
143 | Edition2018, | ||
144 | None, | ||
145 | CfgOptions::default(), | ||
146 | Env::default(), | ||
147 | Default::default(), | ||
148 | ); | ||
149 | let mut change = Change::new(); | ||
150 | change.set_crate_graph(crate_graph); | ||
151 | host.apply_change(change); | ||
152 | |||
153 | assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); | ||
154 | } | 130 | } |
155 | } | 131 | } |
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 1e3e944e9..157e0dc94 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -190,10 +190,11 @@ fn get_struct_def_name_for_struct_literal_search( | |||
190 | 190 | ||
191 | #[cfg(test)] | 191 | #[cfg(test)] |
192 | mod tests { | 192 | mod tests { |
193 | use base_db::FileId; | ||
193 | use expect_test::{expect, Expect}; | 194 | use expect_test::{expect, Expect}; |
194 | use stdx::format_to; | 195 | use stdx::format_to; |
195 | 196 | ||
196 | use crate::{mock_analysis::MockAnalysis, SearchScope}; | 197 | use crate::{mock_analysis::analysis_and_position, SearchScope}; |
197 | 198 | ||
198 | #[test] | 199 | #[test] |
199 | fn test_struct_literal_after_space() { | 200 | fn test_struct_literal_after_space() { |
@@ -211,9 +212,9 @@ fn main() { | |||
211 | } | 212 | } |
212 | "#, | 213 | "#, |
213 | expect![[r#" | 214 | expect![[r#" |
214 | Foo STRUCT FileId(1) 0..26 7..10 Other | 215 | Foo STRUCT FileId(0) 0..26 7..10 Other |
215 | 216 | ||
216 | FileId(1) 101..104 StructLiteral | 217 | FileId(0) 101..104 StructLiteral |
217 | "#]], | 218 | "#]], |
218 | ); | 219 | ); |
219 | } | 220 | } |
@@ -229,10 +230,10 @@ struct Foo<|> {} | |||
229 | } | 230 | } |
230 | "#, | 231 | "#, |
231 | expect![[r#" | 232 | expect![[r#" |
232 | Foo STRUCT FileId(1) 0..13 7..10 Other | 233 | Foo STRUCT FileId(0) 0..13 7..10 Other |
233 | 234 | ||
234 | FileId(1) 41..44 Other | 235 | FileId(0) 41..44 Other |
235 | FileId(1) 54..57 StructLiteral | 236 | FileId(0) 54..57 StructLiteral |
236 | "#]], | 237 | "#]], |
237 | ); | 238 | ); |
238 | } | 239 | } |
@@ -248,9 +249,9 @@ struct Foo<T> <|>{} | |||
248 | } | 249 | } |
249 | "#, | 250 | "#, |
250 | expect![[r#" | 251 | expect![[r#" |
251 | Foo STRUCT FileId(1) 0..16 7..10 Other | 252 | Foo STRUCT FileId(0) 0..16 7..10 Other |
252 | 253 | ||
253 | FileId(1) 64..67 StructLiteral | 254 | FileId(0) 64..67 StructLiteral |
254 | "#]], | 255 | "#]], |
255 | ); | 256 | ); |
256 | } | 257 | } |
@@ -267,9 +268,9 @@ fn main() { | |||
267 | } | 268 | } |
268 | "#, | 269 | "#, |
269 | expect![[r#" | 270 | expect![[r#" |
270 | Foo STRUCT FileId(1) 0..16 7..10 Other | 271 | Foo STRUCT FileId(0) 0..16 7..10 Other |
271 | 272 | ||
272 | FileId(1) 54..57 StructLiteral | 273 | FileId(0) 54..57 StructLiteral |
273 | "#]], | 274 | "#]], |
274 | ); | 275 | ); |
275 | } | 276 | } |
@@ -290,12 +291,12 @@ fn main() { | |||
290 | i = 5; | 291 | i = 5; |
291 | }"#, | 292 | }"#, |
292 | expect![[r#" | 293 | expect![[r#" |
293 | i IDENT_PAT FileId(1) 24..25 Other Write | 294 | i IDENT_PAT FileId(0) 24..25 Other Write |
294 | 295 | ||
295 | FileId(1) 50..51 Other Write | 296 | FileId(0) 50..51 Other Write |
296 | FileId(1) 54..55 Other Read | 297 | FileId(0) 54..55 Other Read |
297 | FileId(1) 76..77 Other Write | 298 | FileId(0) 76..77 Other Write |
298 | FileId(1) 94..95 Other Write | 299 | FileId(0) 94..95 Other Write |
299 | "#]], | 300 | "#]], |
300 | ); | 301 | ); |
301 | } | 302 | } |
@@ -314,10 +315,10 @@ fn bar() { | |||
314 | } | 315 | } |
315 | "#, | 316 | "#, |
316 | expect![[r#" | 317 | expect![[r#" |
317 | spam IDENT_PAT FileId(1) 19..23 Other | 318 | spam IDENT_PAT FileId(0) 19..23 Other |
318 | 319 | ||
319 | FileId(1) 34..38 Other Read | 320 | FileId(0) 34..38 Other Read |
320 | FileId(1) 41..45 Other Read | 321 | FileId(0) 41..45 Other Read |
321 | "#]], | 322 | "#]], |
322 | ); | 323 | ); |
323 | } | 324 | } |
@@ -329,9 +330,9 @@ fn bar() { | |||
329 | fn foo(i : u32) -> u32 { i<|> } | 330 | fn foo(i : u32) -> u32 { i<|> } |
330 | "#, | 331 | "#, |
331 | expect![[r#" | 332 | expect![[r#" |
332 | i IDENT_PAT FileId(1) 7..8 Other | 333 | i IDENT_PAT FileId(0) 7..8 Other |
333 | 334 | ||
334 | FileId(1) 25..26 Other Read | 335 | FileId(0) 25..26 Other Read |
335 | "#]], | 336 | "#]], |
336 | ); | 337 | ); |
337 | } | 338 | } |
@@ -343,9 +344,9 @@ fn foo(i : u32) -> u32 { i<|> } | |||
343 | fn foo(i<|> : u32) -> u32 { i } | 344 | fn foo(i<|> : u32) -> u32 { i } |
344 | "#, | 345 | "#, |
345 | expect![[r#" | 346 | expect![[r#" |
346 | i IDENT_PAT FileId(1) 7..8 Other | 347 | i IDENT_PAT FileId(0) 7..8 Other |
347 | 348 | ||
348 | FileId(1) 25..26 Other Read | 349 | FileId(0) 25..26 Other Read |
349 | "#]], | 350 | "#]], |
350 | ); | 351 | ); |
351 | } | 352 | } |
@@ -364,9 +365,9 @@ fn main(s: Foo) { | |||
364 | } | 365 | } |
365 | "#, | 366 | "#, |
366 | expect![[r#" | 367 | expect![[r#" |
367 | spam RECORD_FIELD FileId(1) 17..30 21..25 Other | 368 | spam RECORD_FIELD FileId(0) 17..30 21..25 Other |
368 | 369 | ||
369 | FileId(1) 67..71 Other Read | 370 | FileId(0) 67..71 Other Read |
370 | "#]], | 371 | "#]], |
371 | ); | 372 | ); |
372 | } | 373 | } |
@@ -381,7 +382,7 @@ impl Foo { | |||
381 | } | 382 | } |
382 | "#, | 383 | "#, |
383 | expect![[r#" | 384 | expect![[r#" |
384 | f FN FileId(1) 27..43 30..31 Other | 385 | f FN FileId(0) 27..43 30..31 Other |
385 | 386 | ||
386 | "#]], | 387 | "#]], |
387 | ); | 388 | ); |
@@ -398,7 +399,7 @@ enum Foo { | |||
398 | } | 399 | } |
399 | "#, | 400 | "#, |
400 | expect![[r#" | 401 | expect![[r#" |
401 | B VARIANT FileId(1) 22..23 22..23 Other | 402 | B VARIANT FileId(0) 22..23 22..23 Other |
402 | 403 | ||
403 | "#]], | 404 | "#]], |
404 | ); | 405 | ); |
@@ -439,10 +440,10 @@ fn f() { | |||
439 | } | 440 | } |
440 | "#, | 441 | "#, |
441 | expect![[r#" | 442 | expect![[r#" |
442 | Foo STRUCT FileId(2) 17..51 28..31 Other | 443 | Foo STRUCT FileId(1) 17..51 28..31 Other |
443 | 444 | ||
444 | FileId(1) 53..56 StructLiteral | 445 | FileId(0) 53..56 StructLiteral |
445 | FileId(3) 79..82 StructLiteral | 446 | FileId(2) 79..82 StructLiteral |
446 | "#]], | 447 | "#]], |
447 | ); | 448 | ); |
448 | } | 449 | } |
@@ -469,9 +470,9 @@ pub struct Foo { | |||
469 | } | 470 | } |
470 | "#, | 471 | "#, |
471 | expect![[r#" | 472 | expect![[r#" |
472 | foo SOURCE_FILE FileId(2) 0..35 Other | 473 | foo SOURCE_FILE FileId(1) 0..35 Other |
473 | 474 | ||
474 | FileId(1) 14..17 Other | 475 | FileId(0) 14..17 Other |
475 | "#]], | 476 | "#]], |
476 | ); | 477 | ); |
477 | } | 478 | } |
@@ -497,10 +498,10 @@ pub(super) struct Foo<|> { | |||
497 | } | 498 | } |
498 | "#, | 499 | "#, |
499 | expect![[r#" | 500 | expect![[r#" |
500 | Foo STRUCT FileId(3) 0..41 18..21 Other | 501 | Foo STRUCT FileId(2) 0..41 18..21 Other |
501 | 502 | ||
502 | FileId(2) 20..23 Other | 503 | FileId(1) 20..23 Other |
503 | FileId(2) 47..50 StructLiteral | 504 | FileId(1) 47..50 StructLiteral |
504 | "#]], | 505 | "#]], |
505 | ); | 506 | ); |
506 | } | 507 | } |
@@ -525,20 +526,20 @@ pub(super) struct Foo<|> { | |||
525 | code, | 526 | code, |
526 | None, | 527 | None, |
527 | expect![[r#" | 528 | expect![[r#" |
528 | quux FN FileId(1) 19..35 26..30 Other | 529 | quux FN FileId(0) 19..35 26..30 Other |
529 | 530 | ||
531 | FileId(1) 16..20 StructLiteral | ||
530 | FileId(2) 16..20 StructLiteral | 532 | FileId(2) 16..20 StructLiteral |
531 | FileId(3) 16..20 StructLiteral | ||
532 | "#]], | 533 | "#]], |
533 | ); | 534 | ); |
534 | 535 | ||
535 | check_with_scope( | 536 | check_with_scope( |
536 | code, | 537 | code, |
537 | Some("/bar.rs"), | 538 | Some(SearchScope::single_file(FileId(2))), |
538 | expect![[r#" | 539 | expect![[r#" |
539 | quux FN FileId(1) 19..35 26..30 Other | 540 | quux FN FileId(0) 19..35 26..30 Other |
540 | 541 | ||
541 | FileId(3) 16..20 StructLiteral | 542 | FileId(2) 16..20 StructLiteral |
542 | "#]], | 543 | "#]], |
543 | ); | 544 | ); |
544 | } | 545 | } |
@@ -556,10 +557,10 @@ fn foo() { | |||
556 | } | 557 | } |
557 | "#, | 558 | "#, |
558 | expect![[r#" | 559 | expect![[r#" |
559 | m1 MACRO_CALL FileId(1) 0..46 29..31 Other | 560 | m1 MACRO_CALL FileId(0) 0..46 29..31 Other |
560 | 561 | ||
561 | FileId(1) 63..65 StructLiteral | 562 | FileId(0) 63..65 StructLiteral |
562 | FileId(1) 73..75 StructLiteral | 563 | FileId(0) 73..75 StructLiteral |
563 | "#]], | 564 | "#]], |
564 | ); | 565 | ); |
565 | } | 566 | } |
@@ -574,10 +575,10 @@ fn foo() { | |||
574 | } | 575 | } |
575 | "#, | 576 | "#, |
576 | expect![[r#" | 577 | expect![[r#" |
577 | i IDENT_PAT FileId(1) 23..24 Other Write | 578 | i IDENT_PAT FileId(0) 23..24 Other Write |
578 | 579 | ||
579 | FileId(1) 34..35 Other Write | 580 | FileId(0) 34..35 Other Write |
580 | FileId(1) 38..39 Other Read | 581 | FileId(0) 38..39 Other Read |
581 | "#]], | 582 | "#]], |
582 | ); | 583 | ); |
583 | } | 584 | } |
@@ -596,10 +597,10 @@ fn foo() { | |||
596 | } | 597 | } |
597 | "#, | 598 | "#, |
598 | expect![[r#" | 599 | expect![[r#" |
599 | f RECORD_FIELD FileId(1) 15..21 15..16 Other | 600 | f RECORD_FIELD FileId(0) 15..21 15..16 Other |
600 | 601 | ||
601 | FileId(1) 55..56 Other Read | 602 | FileId(0) 55..56 Other Read |
602 | FileId(1) 68..69 Other Write | 603 | FileId(0) 68..69 Other Write |
603 | "#]], | 604 | "#]], |
604 | ); | 605 | ); |
605 | } | 606 | } |
@@ -614,9 +615,9 @@ fn foo() { | |||
614 | } | 615 | } |
615 | "#, | 616 | "#, |
616 | expect![[r#" | 617 | expect![[r#" |
617 | i IDENT_PAT FileId(1) 19..20 Other | 618 | i IDENT_PAT FileId(0) 19..20 Other |
618 | 619 | ||
619 | FileId(1) 26..27 Other Write | 620 | FileId(0) 26..27 Other Write |
620 | "#]], | 621 | "#]], |
621 | ); | 622 | ); |
622 | } | 623 | } |
@@ -638,9 +639,9 @@ fn main() { | |||
638 | } | 639 | } |
639 | "#, | 640 | "#, |
640 | expect![[r#" | 641 | expect![[r#" |
641 | new FN FileId(1) 54..81 61..64 Other | 642 | new FN FileId(0) 54..81 61..64 Other |
642 | 643 | ||
643 | FileId(1) 126..129 StructLiteral | 644 | FileId(0) 126..129 StructLiteral |
644 | "#]], | 645 | "#]], |
645 | ); | 646 | ); |
646 | } | 647 | } |
@@ -660,10 +661,10 @@ use crate::f; | |||
660 | fn g() { f(); } | 661 | fn g() { f(); } |
661 | "#, | 662 | "#, |
662 | expect![[r#" | 663 | expect![[r#" |
663 | f FN FileId(1) 22..31 25..26 Other | 664 | f FN FileId(0) 22..31 25..26 Other |
664 | 665 | ||
665 | FileId(2) 11..12 Other | 666 | FileId(1) 11..12 Other |
666 | FileId(2) 24..25 StructLiteral | 667 | FileId(1) 24..25 StructLiteral |
667 | "#]], | 668 | "#]], |
668 | ); | 669 | ); |
669 | } | 670 | } |
@@ -672,11 +673,8 @@ fn g() { f(); } | |||
672 | check_with_scope(ra_fixture, None, expect) | 673 | check_with_scope(ra_fixture, None, expect) |
673 | } | 674 | } |
674 | 675 | ||
675 | fn check_with_scope(ra_fixture: &str, search_scope: Option<&str>, expect: Expect) { | 676 | fn check_with_scope(ra_fixture: &str, search_scope: Option<SearchScope>, expect: Expect) { |
676 | let (mock_analysis, pos) = MockAnalysis::with_files_and_position(ra_fixture); | 677 | let (analysis, pos) = analysis_and_position(ra_fixture); |
677 | let search_scope = | ||
678 | search_scope.map(|path| SearchScope::single_file(mock_analysis.id_of(path))); | ||
679 | let analysis = mock_analysis.analysis(); | ||
680 | let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); | 678 | let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); |
681 | 679 | ||
682 | let mut actual = String::new(); | 680 | let mut actual = String::new(); |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 301629763..366527070 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -602,7 +602,7 @@ mod foo<|>; | |||
602 | source_file_edits: [ | 602 | source_file_edits: [ |
603 | SourceFileEdit { | 603 | SourceFileEdit { |
604 | file_id: FileId( | 604 | file_id: FileId( |
605 | 2, | 605 | 1, |
606 | ), | 606 | ), |
607 | edit: TextEdit { | 607 | edit: TextEdit { |
608 | indels: [ | 608 | indels: [ |
@@ -617,10 +617,10 @@ mod foo<|>; | |||
617 | file_system_edits: [ | 617 | file_system_edits: [ |
618 | MoveFile { | 618 | MoveFile { |
619 | src: FileId( | 619 | src: FileId( |
620 | 3, | 620 | 2, |
621 | ), | 621 | ), |
622 | anchor: FileId( | 622 | anchor: FileId( |
623 | 3, | 623 | 2, |
624 | ), | 624 | ), |
625 | dst: "foo2.rs", | 625 | dst: "foo2.rs", |
626 | }, | 626 | }, |
@@ -655,7 +655,7 @@ use crate::foo<|>::FooContent; | |||
655 | source_file_edits: [ | 655 | source_file_edits: [ |
656 | SourceFileEdit { | 656 | SourceFileEdit { |
657 | file_id: FileId( | 657 | file_id: FileId( |
658 | 1, | 658 | 0, |
659 | ), | 659 | ), |
660 | edit: TextEdit { | 660 | edit: TextEdit { |
661 | indels: [ | 661 | indels: [ |
@@ -668,7 +668,7 @@ use crate::foo<|>::FooContent; | |||
668 | }, | 668 | }, |
669 | SourceFileEdit { | 669 | SourceFileEdit { |
670 | file_id: FileId( | 670 | file_id: FileId( |
671 | 3, | 671 | 2, |
672 | ), | 672 | ), |
673 | edit: TextEdit { | 673 | edit: TextEdit { |
674 | indels: [ | 674 | indels: [ |
@@ -683,10 +683,10 @@ use crate::foo<|>::FooContent; | |||
683 | file_system_edits: [ | 683 | file_system_edits: [ |
684 | MoveFile { | 684 | MoveFile { |
685 | src: FileId( | 685 | src: FileId( |
686 | 2, | 686 | 1, |
687 | ), | 687 | ), |
688 | anchor: FileId( | 688 | anchor: FileId( |
689 | 2, | 689 | 1, |
690 | ), | 690 | ), |
691 | dst: "quux.rs", | 691 | dst: "quux.rs", |
692 | }, | 692 | }, |
@@ -715,7 +715,7 @@ mod fo<|>o; | |||
715 | source_file_edits: [ | 715 | source_file_edits: [ |
716 | SourceFileEdit { | 716 | SourceFileEdit { |
717 | file_id: FileId( | 717 | file_id: FileId( |
718 | 1, | 718 | 0, |
719 | ), | 719 | ), |
720 | edit: TextEdit { | 720 | edit: TextEdit { |
721 | indels: [ | 721 | indels: [ |
@@ -730,10 +730,10 @@ mod fo<|>o; | |||
730 | file_system_edits: [ | 730 | file_system_edits: [ |
731 | MoveFile { | 731 | MoveFile { |
732 | src: FileId( | 732 | src: FileId( |
733 | 2, | 733 | 1, |
734 | ), | 734 | ), |
735 | anchor: FileId( | 735 | anchor: FileId( |
736 | 2, | 736 | 1, |
737 | ), | 737 | ), |
738 | dst: "../foo2/mod.rs", | 738 | dst: "../foo2/mod.rs", |
739 | }, | 739 | }, |
@@ -763,7 +763,7 @@ mod outer { mod fo<|>o; } | |||
763 | source_file_edits: [ | 763 | source_file_edits: [ |
764 | SourceFileEdit { | 764 | SourceFileEdit { |
765 | file_id: FileId( | 765 | file_id: FileId( |
766 | 1, | 766 | 0, |
767 | ), | 767 | ), |
768 | edit: TextEdit { | 768 | edit: TextEdit { |
769 | indels: [ | 769 | indels: [ |
@@ -778,10 +778,10 @@ mod outer { mod fo<|>o; } | |||
778 | file_system_edits: [ | 778 | file_system_edits: [ |
779 | MoveFile { | 779 | MoveFile { |
780 | src: FileId( | 780 | src: FileId( |
781 | 2, | 781 | 1, |
782 | ), | 782 | ), |
783 | anchor: FileId( | 783 | anchor: FileId( |
784 | 2, | 784 | 1, |
785 | ), | 785 | ), |
786 | dst: "bar.rs", | 786 | dst: "bar.rs", |
787 | }, | 787 | }, |
@@ -834,7 +834,7 @@ pub mod foo<|>; | |||
834 | source_file_edits: [ | 834 | source_file_edits: [ |
835 | SourceFileEdit { | 835 | SourceFileEdit { |
836 | file_id: FileId( | 836 | file_id: FileId( |
837 | 2, | 837 | 1, |
838 | ), | 838 | ), |
839 | edit: TextEdit { | 839 | edit: TextEdit { |
840 | indels: [ | 840 | indels: [ |
@@ -847,7 +847,7 @@ pub mod foo<|>; | |||
847 | }, | 847 | }, |
848 | SourceFileEdit { | 848 | SourceFileEdit { |
849 | file_id: FileId( | 849 | file_id: FileId( |
850 | 1, | 850 | 0, |
851 | ), | 851 | ), |
852 | edit: TextEdit { | 852 | edit: TextEdit { |
853 | indels: [ | 853 | indels: [ |
@@ -862,10 +862,10 @@ pub mod foo<|>; | |||
862 | file_system_edits: [ | 862 | file_system_edits: [ |
863 | MoveFile { | 863 | MoveFile { |
864 | src: FileId( | 864 | src: FileId( |
865 | 3, | 865 | 2, |
866 | ), | 866 | ), |
867 | anchor: FileId( | 867 | anchor: FileId( |
868 | 3, | 868 | 2, |
869 | ), | 869 | ), |
870 | dst: "foo2.rs", | 870 | dst: "foo2.rs", |
871 | }, | 871 | }, |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index cfeff40c1..961066277 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -335,7 +335,7 @@ fn bench() {} | |||
335 | Runnable { | 335 | Runnable { |
336 | nav: NavigationTarget { | 336 | nav: NavigationTarget { |
337 | file_id: FileId( | 337 | file_id: FileId( |
338 | 1, | 338 | 0, |
339 | ), | 339 | ), |
340 | full_range: 1..13, | 340 | full_range: 1..13, |
341 | focus_range: Some( | 341 | focus_range: Some( |
@@ -353,7 +353,7 @@ fn bench() {} | |||
353 | Runnable { | 353 | Runnable { |
354 | nav: NavigationTarget { | 354 | nav: NavigationTarget { |
355 | file_id: FileId( | 355 | file_id: FileId( |
356 | 1, | 356 | 0, |
357 | ), | 357 | ), |
358 | full_range: 15..39, | 358 | full_range: 15..39, |
359 | focus_range: Some( | 359 | focus_range: Some( |
@@ -378,7 +378,7 @@ fn bench() {} | |||
378 | Runnable { | 378 | Runnable { |
379 | nav: NavigationTarget { | 379 | nav: NavigationTarget { |
380 | file_id: FileId( | 380 | file_id: FileId( |
381 | 1, | 381 | 0, |
382 | ), | 382 | ), |
383 | full_range: 41..75, | 383 | full_range: 41..75, |
384 | focus_range: Some( | 384 | focus_range: Some( |
@@ -403,7 +403,7 @@ fn bench() {} | |||
403 | Runnable { | 403 | Runnable { |
404 | nav: NavigationTarget { | 404 | nav: NavigationTarget { |
405 | file_id: FileId( | 405 | file_id: FileId( |
406 | 1, | 406 | 0, |
407 | ), | 407 | ), |
408 | full_range: 77..99, | 408 | full_range: 77..99, |
409 | focus_range: Some( | 409 | focus_range: Some( |
@@ -494,7 +494,7 @@ fn should_have_no_runnable_6() {} | |||
494 | Runnable { | 494 | Runnable { |
495 | nav: NavigationTarget { | 495 | nav: NavigationTarget { |
496 | file_id: FileId( | 496 | file_id: FileId( |
497 | 1, | 497 | 0, |
498 | ), | 498 | ), |
499 | full_range: 1..13, | 499 | full_range: 1..13, |
500 | focus_range: Some( | 500 | focus_range: Some( |
@@ -512,7 +512,7 @@ fn should_have_no_runnable_6() {} | |||
512 | Runnable { | 512 | Runnable { |
513 | nav: NavigationTarget { | 513 | nav: NavigationTarget { |
514 | file_id: FileId( | 514 | file_id: FileId( |
515 | 1, | 515 | 0, |
516 | ), | 516 | ), |
517 | full_range: 15..74, | 517 | full_range: 15..74, |
518 | focus_range: None, | 518 | focus_range: None, |
@@ -532,7 +532,7 @@ fn should_have_no_runnable_6() {} | |||
532 | Runnable { | 532 | Runnable { |
533 | nav: NavigationTarget { | 533 | nav: NavigationTarget { |
534 | file_id: FileId( | 534 | file_id: FileId( |
535 | 1, | 535 | 0, |
536 | ), | 536 | ), |
537 | full_range: 76..148, | 537 | full_range: 76..148, |
538 | focus_range: None, | 538 | focus_range: None, |
@@ -552,7 +552,7 @@ fn should_have_no_runnable_6() {} | |||
552 | Runnable { | 552 | Runnable { |
553 | nav: NavigationTarget { | 553 | nav: NavigationTarget { |
554 | file_id: FileId( | 554 | file_id: FileId( |
555 | 1, | 555 | 0, |
556 | ), | 556 | ), |
557 | full_range: 150..254, | 557 | full_range: 150..254, |
558 | focus_range: None, | 558 | focus_range: None, |
@@ -596,7 +596,7 @@ impl Data { | |||
596 | Runnable { | 596 | Runnable { |
597 | nav: NavigationTarget { | 597 | nav: NavigationTarget { |
598 | file_id: FileId( | 598 | file_id: FileId( |
599 | 1, | 599 | 0, |
600 | ), | 600 | ), |
601 | full_range: 1..13, | 601 | full_range: 1..13, |
602 | focus_range: Some( | 602 | focus_range: Some( |
@@ -614,7 +614,7 @@ impl Data { | |||
614 | Runnable { | 614 | Runnable { |
615 | nav: NavigationTarget { | 615 | nav: NavigationTarget { |
616 | file_id: FileId( | 616 | file_id: FileId( |
617 | 1, | 617 | 0, |
618 | ), | 618 | ), |
619 | full_range: 44..98, | 619 | full_range: 44..98, |
620 | focus_range: None, | 620 | focus_range: None, |
@@ -653,7 +653,7 @@ mod test_mod { | |||
653 | Runnable { | 653 | Runnable { |
654 | nav: NavigationTarget { | 654 | nav: NavigationTarget { |
655 | file_id: FileId( | 655 | file_id: FileId( |
656 | 1, | 656 | 0, |
657 | ), | 657 | ), |
658 | full_range: 1..51, | 658 | full_range: 1..51, |
659 | focus_range: Some( | 659 | focus_range: Some( |
@@ -673,7 +673,7 @@ mod test_mod { | |||
673 | Runnable { | 673 | Runnable { |
674 | nav: NavigationTarget { | 674 | nav: NavigationTarget { |
675 | file_id: FileId( | 675 | file_id: FileId( |
676 | 1, | 676 | 0, |
677 | ), | 677 | ), |
678 | full_range: 20..49, | 678 | full_range: 20..49, |
679 | focus_range: Some( | 679 | focus_range: Some( |
@@ -733,7 +733,7 @@ mod root_tests { | |||
733 | Runnable { | 733 | Runnable { |
734 | nav: NavigationTarget { | 734 | nav: NavigationTarget { |
735 | file_id: FileId( | 735 | file_id: FileId( |
736 | 1, | 736 | 0, |
737 | ), | 737 | ), |
738 | full_range: 22..323, | 738 | full_range: 22..323, |
739 | focus_range: Some( | 739 | focus_range: Some( |
@@ -753,7 +753,7 @@ mod root_tests { | |||
753 | Runnable { | 753 | Runnable { |
754 | nav: NavigationTarget { | 754 | nav: NavigationTarget { |
755 | file_id: FileId( | 755 | file_id: FileId( |
756 | 1, | 756 | 0, |
757 | ), | 757 | ), |
758 | full_range: 51..192, | 758 | full_range: 51..192, |
759 | focus_range: Some( | 759 | focus_range: Some( |
@@ -773,7 +773,7 @@ mod root_tests { | |||
773 | Runnable { | 773 | Runnable { |
774 | nav: NavigationTarget { | 774 | nav: NavigationTarget { |
775 | file_id: FileId( | 775 | file_id: FileId( |
776 | 1, | 776 | 0, |
777 | ), | 777 | ), |
778 | full_range: 84..126, | 778 | full_range: 84..126, |
779 | focus_range: Some( | 779 | focus_range: Some( |
@@ -798,7 +798,7 @@ mod root_tests { | |||
798 | Runnable { | 798 | Runnable { |
799 | nav: NavigationTarget { | 799 | nav: NavigationTarget { |
800 | file_id: FileId( | 800 | file_id: FileId( |
801 | 1, | 801 | 0, |
802 | ), | 802 | ), |
803 | full_range: 140..182, | 803 | full_range: 140..182, |
804 | focus_range: Some( | 804 | focus_range: Some( |
@@ -823,7 +823,7 @@ mod root_tests { | |||
823 | Runnable { | 823 | Runnable { |
824 | nav: NavigationTarget { | 824 | nav: NavigationTarget { |
825 | file_id: FileId( | 825 | file_id: FileId( |
826 | 1, | 826 | 0, |
827 | ), | 827 | ), |
828 | full_range: 202..286, | 828 | full_range: 202..286, |
829 | focus_range: Some( | 829 | focus_range: Some( |
@@ -843,7 +843,7 @@ mod root_tests { | |||
843 | Runnable { | 843 | Runnable { |
844 | nav: NavigationTarget { | 844 | nav: NavigationTarget { |
845 | file_id: FileId( | 845 | file_id: FileId( |
846 | 1, | 846 | 0, |
847 | ), | 847 | ), |
848 | full_range: 235..276, | 848 | full_range: 235..276, |
849 | focus_range: Some( | 849 | focus_range: Some( |
@@ -886,7 +886,7 @@ fn test_foo1() {} | |||
886 | Runnable { | 886 | Runnable { |
887 | nav: NavigationTarget { | 887 | nav: NavigationTarget { |
888 | file_id: FileId( | 888 | file_id: FileId( |
889 | 1, | 889 | 0, |
890 | ), | 890 | ), |
891 | full_range: 1..50, | 891 | full_range: 1..50, |
892 | focus_range: Some( | 892 | focus_range: Some( |
@@ -934,7 +934,7 @@ fn test_foo1() {} | |||
934 | Runnable { | 934 | Runnable { |
935 | nav: NavigationTarget { | 935 | nav: NavigationTarget { |
936 | file_id: FileId( | 936 | file_id: FileId( |
937 | 1, | 937 | 0, |
938 | ), | 938 | ), |
939 | full_range: 1..72, | 939 | full_range: 1..72, |
940 | focus_range: Some( | 940 | focus_range: Some( |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 211e62ea1..eaa4e163e 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -462,12 +462,12 @@ macro_rules! noop { | |||
462 | fn test_extern_crate() { | 462 | fn test_extern_crate() { |
463 | check_highlighting( | 463 | check_highlighting( |
464 | r#" | 464 | r#" |
465 | //- /main.rs | 465 | //- /main.rs crate:main deps:std,alloc |
466 | extern crate std; | 466 | extern crate std; |
467 | extern crate alloc as abc; | 467 | extern crate alloc as abc; |
468 | //- /std/lib.rs | 468 | //- /std/lib.rs crate:std |
469 | pub struct S; | 469 | pub struct S; |
470 | //- /alloc/lib.rs | 470 | //- /alloc/lib.rs crate:alloc |
471 | pub struct A | 471 | pub struct A |
472 | "#, | 472 | "#, |
473 | expect_file!["./test_data/highlight_extern_crate.html"], | 473 | expect_file!["./test_data/highlight_extern_crate.html"], |