@@ -18,7 +18,8 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
1818 format : HoverDocFormat :: Markdown ,
1919 keywords : true ,
2020 max_trait_assoc_items_count : None ,
21- max_adt_fields_or_variants_count : Some ( 5 ) ,
21+ max_struct_or_union_fields_count : Some ( 5 ) ,
22+ max_enum_variants_count : Some ( 5 ) ,
2223} ;
2324
2425fn check_hover_no_result ( ra_fixture : & str ) {
@@ -51,8 +52,8 @@ fn check(ra_fixture: &str, expect: Expect) {
5152}
5253
5354#[ track_caller]
54- fn check_hover_adt_fields_or_variants_limit (
55- count : Option < usize > ,
55+ fn check_hover_struct_or_union_fields_limit (
56+ fields_count : impl Into < Option < usize > > ,
5657 ra_fixture : & str ,
5758 expect : Expect ,
5859) {
@@ -61,7 +62,33 @@ fn check_hover_adt_fields_or_variants_limit(
6162 . hover (
6263 & HoverConfig {
6364 links_in_hover : true ,
64- max_adt_fields_or_variants_count : count,
65+ max_struct_or_union_fields_count : fields_count. into ( ) ,
66+ ..HOVER_BASE_CONFIG
67+ } ,
68+ FileRange { file_id : position. file_id , range : TextRange :: empty ( position. offset ) } ,
69+ )
70+ . unwrap ( )
71+ . unwrap ( ) ;
72+
73+ let content = analysis. db . file_text ( position. file_id ) ;
74+ let hovered_element = & content[ hover. range ] ;
75+
76+ let actual = format ! ( "*{hovered_element}*\n {}\n " , hover. info. markup) ;
77+ expect. assert_eq ( & actual)
78+ }
79+
80+ #[ track_caller]
81+ fn check_hover_enum_variants_limit (
82+ variants_count : impl Into < Option < usize > > ,
83+ ra_fixture : & str ,
84+ expect : Expect ,
85+ ) {
86+ let ( analysis, position) = fixture:: position ( ra_fixture) ;
87+ let hover = analysis
88+ . hover (
89+ & HoverConfig {
90+ links_in_hover : true ,
91+ max_enum_variants_count : variants_count. into ( ) ,
6592 ..HOVER_BASE_CONFIG
6693 } ,
6794 FileRange { file_id : position. file_id , range : TextRange :: empty ( position. offset ) } ,
@@ -912,8 +939,8 @@ struct Foo$0 where u32: Copy { field: u32 }
912939
913940#[ test]
914941fn hover_record_struct_limit ( ) {
915- check_hover_adt_fields_or_variants_limit (
916- Some ( 3 ) ,
942+ check_hover_struct_or_union_fields_limit (
943+ 3 ,
917944 r#"
918945 struct Foo$0 { a: u32, b: i32, c: i32 }
919946 "# ,
@@ -934,8 +961,8 @@ fn hover_record_struct_limit() {
934961 ```
935962 "# ] ] ,
936963 ) ;
937- check_hover_adt_fields_or_variants_limit (
938- Some ( 3 ) ,
964+ check_hover_struct_or_union_fields_limit (
965+ 3 ,
939966 r#"
940967 struct Foo$0 { a: u32 }
941968 "# ,
@@ -954,8 +981,8 @@ fn hover_record_struct_limit() {
954981 ```
955982 "# ] ] ,
956983 ) ;
957- check_hover_adt_fields_or_variants_limit (
958- Some ( 3 ) ,
984+ check_hover_struct_or_union_fields_limit (
985+ 3 ,
959986 r#"
960987 struct Foo$0 { a: u32, b: i32, c: i32, d: u32 }
961988 "# ,
@@ -977,7 +1004,7 @@ fn hover_record_struct_limit() {
9771004 ```
9781005 "# ] ] ,
9791006 ) ;
980- check_hover_adt_fields_or_variants_limit (
1007+ check_hover_struct_or_union_fields_limit (
9811008 None ,
9821009 r#"
9831010 struct Foo$0 { a: u32, b: i32, c: i32 }
@@ -995,8 +1022,8 @@ fn hover_record_struct_limit() {
9951022 ```
9961023 "# ] ] ,
9971024 ) ;
998- check_hover_adt_fields_or_variants_limit (
999- Some ( 0 ) ,
1025+ check_hover_struct_or_union_fields_limit (
1026+ 0 ,
10001027 r#"
10011028 struct Foo$0 { a: u32, b: i32, c: i32 }
10021029 "# ,
@@ -1017,8 +1044,8 @@ fn hover_record_struct_limit() {
10171044
10181045#[ test]
10191046fn hover_enum_limit ( ) {
1020- check_hover_adt_fields_or_variants_limit (
1021- Some ( 5 ) ,
1047+ check_hover_enum_variants_limit (
1048+ 5 ,
10221049 r#"enum Foo$0 { A, B }"# ,
10231050 expect ! [ [ r#"
10241051 *Foo*
@@ -1036,8 +1063,8 @@ fn hover_enum_limit() {
10361063 ```
10371064 "# ] ] ,
10381065 ) ;
1039- check_hover_adt_fields_or_variants_limit (
1040- Some ( 1 ) ,
1066+ check_hover_enum_variants_limit (
1067+ 1 ,
10411068 r#"enum Foo$0 { A, B }"# ,
10421069 expect ! [ [ r#"
10431070 *Foo*
@@ -1055,8 +1082,8 @@ fn hover_enum_limit() {
10551082 ```
10561083 "# ] ] ,
10571084 ) ;
1058- check_hover_adt_fields_or_variants_limit (
1059- Some ( 0 ) ,
1085+ check_hover_enum_variants_limit (
1086+ 0 ,
10601087 r#"enum Foo$0 { A, B }"# ,
10611088 expect ! [ [ r#"
10621089 *Foo*
@@ -1071,7 +1098,7 @@ fn hover_enum_limit() {
10711098 ```
10721099 "# ] ] ,
10731100 ) ;
1074- check_hover_adt_fields_or_variants_limit (
1101+ check_hover_enum_variants_limit (
10751102 None ,
10761103 r#"enum Foo$0 { A, B }"# ,
10771104 expect ! [ [ r#"
@@ -1087,12 +1114,46 @@ fn hover_enum_limit() {
10871114 ```
10881115 "# ] ] ,
10891116 ) ;
1117+ check_hover_enum_variants_limit (
1118+ 7 ,
1119+ r#"enum Enum$0 {
1120+ Variant {},
1121+ Variant2 { field: i32 },
1122+ Variant3 { field: i32, field2: i32 },
1123+ Variant4(),
1124+ Variant5(i32),
1125+ Variant6(i32, i32),
1126+ Variant7,
1127+ Variant8,
1128+ }"# ,
1129+ expect ! [ [ r#"
1130+ *Enum*
1131+
1132+ ```rust
1133+ test
1134+ ```
1135+
1136+ ```rust
1137+ // size = 12 (0xC), align = 4, niches = 4294967288
1138+ enum Enum {
1139+ Variant {},
1140+ Variant2 { /* … */ },
1141+ Variant3 { /* … */ },
1142+ Variant4(),
1143+ Variant5( /* … */ ),
1144+ Variant6( /* … */ ),
1145+ Variant7,
1146+ /* … */
1147+ }
1148+ ```
1149+ "# ] ] ,
1150+ ) ;
10901151}
10911152
10921153#[ test]
10931154fn hover_union_limit ( ) {
1094- check_hover_adt_fields_or_variants_limit (
1095- Some ( 5 ) ,
1155+ check_hover_struct_or_union_fields_limit (
1156+ 5 ,
10961157 r#"union Foo$0 { a: u32, b: i32 }"# ,
10971158 expect ! [ [ r#"
10981159 *Foo*
@@ -1110,8 +1171,8 @@ fn hover_union_limit() {
11101171 ```
11111172 "# ] ] ,
11121173 ) ;
1113- check_hover_adt_fields_or_variants_limit (
1114- Some ( 1 ) ,
1174+ check_hover_struct_or_union_fields_limit (
1175+ 1 ,
11151176 r#"union Foo$0 { a: u32, b: i32 }"# ,
11161177 expect ! [ [ r#"
11171178 *Foo*
@@ -1129,8 +1190,8 @@ fn hover_union_limit() {
11291190 ```
11301191 "# ] ] ,
11311192 ) ;
1132- check_hover_adt_fields_or_variants_limit (
1133- Some ( 0 ) ,
1193+ check_hover_struct_or_union_fields_limit (
1194+ 0 ,
11341195 r#"union Foo$0 { a: u32, b: i32 }"# ,
11351196 expect ! [ [ r#"
11361197 *Foo*
@@ -1145,7 +1206,7 @@ fn hover_union_limit() {
11451206 ```
11461207 "# ] ] ,
11471208 ) ;
1148- check_hover_adt_fields_or_variants_limit (
1209+ check_hover_struct_or_union_fields_limit (
11491210 None ,
11501211 r#"union Foo$0 { a: u32, b: i32 }"# ,
11511212 expect ! [ [ r#"
@@ -1630,12 +1691,12 @@ impl Thing {
16301691 ```
16311692 "# ] ] ,
16321693 ) ;
1633- check_hover_adt_fields_or_variants_limit (
1694+ check_hover_struct_or_union_fields_limit (
16341695 None ,
16351696 r#"
16361697struct Thing { x: u32 }
16371698impl Thing {
1638- fn new() -> Self { Self$0 { x: 0 } }
1699+ fn new() -> Self$0 { Self { x: 0 } }
16391700}
16401701"# ,
16411702 expect ! [ [ r#"
@@ -2599,8 +2660,8 @@ fn test_hover_layout_of_enum() {
25992660 ```rust
26002661 // size = 16 (0x10), align = 8, niches = 254
26012662 enum Foo {
2602- Variant1(u8, u16 ),
2603- Variant2(i32, u8, i64 ),
2663+ Variant1( /* … */ ),
2664+ Variant2( /* … */ ),
26042665 }
26052666 ```
26062667 "# ] ] ,
0 commit comments