diff options
Diffstat (limited to 'crates/ide/src/references.rs')
-rw-r--r-- | crates/ide/src/references.rs | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index e0830eb4f..88e2f2db3 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -9,7 +9,7 @@ | |||
9 | //! at the index that the match starts at and its tree parent is | 9 | //! at the index that the match starts at and its tree parent is |
10 | //! resolved to the search element definition, we get a reference. | 10 | //! resolved to the search element definition, we get a reference. |
11 | 11 | ||
12 | mod rename; | 12 | pub(crate) mod rename; |
13 | 13 | ||
14 | use hir::Semantics; | 14 | use hir::Semantics; |
15 | use ide_db::{ | 15 | use ide_db::{ |
@@ -26,6 +26,7 @@ use syntax::{ | |||
26 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; | 26 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; |
27 | 27 | ||
28 | pub(crate) use self::rename::rename; | 28 | pub(crate) use self::rename::rename; |
29 | pub use self::rename::RenameError; | ||
29 | 30 | ||
30 | pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; | 31 | pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; |
31 | 32 | ||
@@ -406,6 +407,23 @@ enum Foo { | |||
406 | } | 407 | } |
407 | 408 | ||
408 | #[test] | 409 | #[test] |
410 | fn test_find_all_refs_enum_var_field() { | ||
411 | check( | ||
412 | r#" | ||
413 | enum Foo { | ||
414 | A, | ||
415 | B { field<|>: u8 }, | ||
416 | C, | ||
417 | } | ||
418 | "#, | ||
419 | expect![[r#" | ||
420 | field RECORD_FIELD FileId(0) 26..35 26..31 Other | ||
421 | |||
422 | "#]], | ||
423 | ); | ||
424 | } | ||
425 | |||
426 | #[test] | ||
409 | fn test_find_all_refs_two_modules() { | 427 | fn test_find_all_refs_two_modules() { |
410 | check( | 428 | check( |
411 | r#" | 429 | r#" |
@@ -669,6 +687,76 @@ fn g() { f(); } | |||
669 | ); | 687 | ); |
670 | } | 688 | } |
671 | 689 | ||
690 | #[test] | ||
691 | fn test_find_all_refs_struct_pat() { | ||
692 | check( | ||
693 | r#" | ||
694 | struct S { | ||
695 | field<|>: u8, | ||
696 | } | ||
697 | |||
698 | fn f(s: S) { | ||
699 | match s { | ||
700 | S { field } => {} | ||
701 | } | ||
702 | } | ||
703 | "#, | ||
704 | expect![[r#" | ||
705 | field RECORD_FIELD FileId(0) 15..24 15..20 Other | ||
706 | |||
707 | FileId(0) 68..73 FieldShorthandForField Read | ||
708 | "#]], | ||
709 | ); | ||
710 | } | ||
711 | |||
712 | #[test] | ||
713 | fn test_find_all_refs_enum_var_pat() { | ||
714 | check( | ||
715 | r#" | ||
716 | enum En { | ||
717 | Variant { | ||
718 | field<|>: u8, | ||
719 | } | ||
720 | } | ||
721 | |||
722 | fn f(e: En) { | ||
723 | match e { | ||
724 | En::Variant { field } => {} | ||
725 | } | ||
726 | } | ||
727 | "#, | ||
728 | expect![[r#" | ||
729 | field RECORD_FIELD FileId(0) 32..41 32..37 Other | ||
730 | |||
731 | FileId(0) 102..107 FieldShorthandForField Read | ||
732 | "#]], | ||
733 | ); | ||
734 | } | ||
735 | |||
736 | #[test] | ||
737 | fn test_find_all_refs_enum_var_privacy() { | ||
738 | check( | ||
739 | r#" | ||
740 | mod m { | ||
741 | pub enum En { | ||
742 | Variant { | ||
743 | field<|>: u8, | ||
744 | } | ||
745 | } | ||
746 | } | ||
747 | |||
748 | fn f() -> m::En { | ||
749 | m::En::Variant { field: 0 } | ||
750 | } | ||
751 | "#, | ||
752 | expect![[r#" | ||
753 | field RECORD_FIELD FileId(0) 56..65 56..61 Other | ||
754 | |||
755 | FileId(0) 125..130 Other Read | ||
756 | "#]], | ||
757 | ); | ||
758 | } | ||
759 | |||
672 | fn check(ra_fixture: &str, expect: Expect) { | 760 | fn check(ra_fixture: &str, expect: Expect) { |
673 | check_with_scope(ra_fixture, None, expect) | 761 | check_with_scope(ra_fixture, None, expect) |
674 | } | 762 | } |