diff options
Diffstat (limited to 'crates/ide/src/references.rs')
-rw-r--r-- | crates/ide/src/references.rs | 118 |
1 files changed, 58 insertions, 60 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 1e3e944e9..e0830eb4f 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::{fixture, 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) = fixture::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(); |