@@ -18,7 +18,8 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
18
18
format : HoverDocFormat :: Markdown ,
19
19
keywords : true ,
20
20
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 ) ,
22
23
} ;
23
24
24
25
fn check_hover_no_result ( ra_fixture : & str ) {
@@ -51,8 +52,8 @@ fn check(ra_fixture: &str, expect: Expect) {
51
52
}
52
53
53
54
#[ 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 > > ,
56
57
ra_fixture : & str ,
57
58
expect : Expect ,
58
59
) {
@@ -61,7 +62,33 @@ fn check_hover_adt_fields_or_variants_limit(
61
62
. hover (
62
63
& HoverConfig {
63
64
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 ( ) ,
65
92
..HOVER_BASE_CONFIG
66
93
} ,
67
94
FileRange { file_id : position. file_id , range : TextRange :: empty ( position. offset ) } ,
@@ -912,8 +939,8 @@ struct Foo$0 where u32: Copy { field: u32 }
912
939
913
940
#[ test]
914
941
fn 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 ,
917
944
r#"
918
945
struct Foo$0 { a: u32, b: i32, c: i32 }
919
946
"# ,
@@ -934,8 +961,8 @@ fn hover_record_struct_limit() {
934
961
```
935
962
"# ] ] ,
936
963
) ;
937
- check_hover_adt_fields_or_variants_limit (
938
- Some ( 3 ) ,
964
+ check_hover_struct_or_union_fields_limit (
965
+ 3 ,
939
966
r#"
940
967
struct Foo$0 { a: u32 }
941
968
"# ,
@@ -954,8 +981,8 @@ fn hover_record_struct_limit() {
954
981
```
955
982
"# ] ] ,
956
983
) ;
957
- check_hover_adt_fields_or_variants_limit (
958
- Some ( 3 ) ,
984
+ check_hover_struct_or_union_fields_limit (
985
+ 3 ,
959
986
r#"
960
987
struct Foo$0 { a: u32, b: i32, c: i32, d: u32 }
961
988
"# ,
@@ -977,7 +1004,7 @@ fn hover_record_struct_limit() {
977
1004
```
978
1005
"# ] ] ,
979
1006
) ;
980
- check_hover_adt_fields_or_variants_limit (
1007
+ check_hover_struct_or_union_fields_limit (
981
1008
None ,
982
1009
r#"
983
1010
struct Foo$0 { a: u32, b: i32, c: i32 }
@@ -995,8 +1022,8 @@ fn hover_record_struct_limit() {
995
1022
```
996
1023
"# ] ] ,
997
1024
) ;
998
- check_hover_adt_fields_or_variants_limit (
999
- Some ( 0 ) ,
1025
+ check_hover_struct_or_union_fields_limit (
1026
+ 0 ,
1000
1027
r#"
1001
1028
struct Foo$0 { a: u32, b: i32, c: i32 }
1002
1029
"# ,
@@ -1017,8 +1044,8 @@ fn hover_record_struct_limit() {
1017
1044
1018
1045
#[ test]
1019
1046
fn hover_enum_limit ( ) {
1020
- check_hover_adt_fields_or_variants_limit (
1021
- Some ( 5 ) ,
1047
+ check_hover_enum_variants_limit (
1048
+ 5 ,
1022
1049
r#"enum Foo$0 { A, B }"# ,
1023
1050
expect ! [ [ r#"
1024
1051
*Foo*
@@ -1036,8 +1063,8 @@ fn hover_enum_limit() {
1036
1063
```
1037
1064
"# ] ] ,
1038
1065
) ;
1039
- check_hover_adt_fields_or_variants_limit (
1040
- Some ( 1 ) ,
1066
+ check_hover_enum_variants_limit (
1067
+ 1 ,
1041
1068
r#"enum Foo$0 { A, B }"# ,
1042
1069
expect ! [ [ r#"
1043
1070
*Foo*
@@ -1055,8 +1082,8 @@ fn hover_enum_limit() {
1055
1082
```
1056
1083
"# ] ] ,
1057
1084
) ;
1058
- check_hover_adt_fields_or_variants_limit (
1059
- Some ( 0 ) ,
1085
+ check_hover_enum_variants_limit (
1086
+ 0 ,
1060
1087
r#"enum Foo$0 { A, B }"# ,
1061
1088
expect ! [ [ r#"
1062
1089
*Foo*
@@ -1071,7 +1098,7 @@ fn hover_enum_limit() {
1071
1098
```
1072
1099
"# ] ] ,
1073
1100
) ;
1074
- check_hover_adt_fields_or_variants_limit (
1101
+ check_hover_enum_variants_limit (
1075
1102
None ,
1076
1103
r#"enum Foo$0 { A, B }"# ,
1077
1104
expect ! [ [ r#"
@@ -1087,12 +1114,46 @@ fn hover_enum_limit() {
1087
1114
```
1088
1115
"# ] ] ,
1089
1116
) ;
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
+ ) ;
1090
1151
}
1091
1152
1092
1153
#[ test]
1093
1154
fn hover_union_limit ( ) {
1094
- check_hover_adt_fields_or_variants_limit (
1095
- Some ( 5 ) ,
1155
+ check_hover_struct_or_union_fields_limit (
1156
+ 5 ,
1096
1157
r#"union Foo$0 { a: u32, b: i32 }"# ,
1097
1158
expect ! [ [ r#"
1098
1159
*Foo*
@@ -1110,8 +1171,8 @@ fn hover_union_limit() {
1110
1171
```
1111
1172
"# ] ] ,
1112
1173
) ;
1113
- check_hover_adt_fields_or_variants_limit (
1114
- Some ( 1 ) ,
1174
+ check_hover_struct_or_union_fields_limit (
1175
+ 1 ,
1115
1176
r#"union Foo$0 { a: u32, b: i32 }"# ,
1116
1177
expect ! [ [ r#"
1117
1178
*Foo*
@@ -1129,8 +1190,8 @@ fn hover_union_limit() {
1129
1190
```
1130
1191
"# ] ] ,
1131
1192
) ;
1132
- check_hover_adt_fields_or_variants_limit (
1133
- Some ( 0 ) ,
1193
+ check_hover_struct_or_union_fields_limit (
1194
+ 0 ,
1134
1195
r#"union Foo$0 { a: u32, b: i32 }"# ,
1135
1196
expect ! [ [ r#"
1136
1197
*Foo*
@@ -1145,7 +1206,7 @@ fn hover_union_limit() {
1145
1206
```
1146
1207
"# ] ] ,
1147
1208
) ;
1148
- check_hover_adt_fields_or_variants_limit (
1209
+ check_hover_struct_or_union_fields_limit (
1149
1210
None ,
1150
1211
r#"union Foo$0 { a: u32, b: i32 }"# ,
1151
1212
expect ! [ [ r#"
@@ -1630,12 +1691,12 @@ impl Thing {
1630
1691
```
1631
1692
"# ] ] ,
1632
1693
) ;
1633
- check_hover_adt_fields_or_variants_limit (
1694
+ check_hover_struct_or_union_fields_limit (
1634
1695
None ,
1635
1696
r#"
1636
1697
struct Thing { x: u32 }
1637
1698
impl Thing {
1638
- fn new() -> Self { Self$0 { x: 0 } }
1699
+ fn new() -> Self$0 { Self { x: 0 } }
1639
1700
}
1640
1701
"# ,
1641
1702
expect ! [ [ r#"
@@ -2599,8 +2660,8 @@ fn test_hover_layout_of_enum() {
2599
2660
```rust
2600
2661
// size = 16 (0x10), align = 8, niches = 254
2601
2662
enum Foo {
2602
- Variant1(u8, u16 ),
2603
- Variant2(i32, u8, i64 ),
2663
+ Variant1( /* … */ ),
2664
+ Variant2( /* … */ ),
2604
2665
}
2605
2666
```
2606
2667
"# ] ] ,
0 commit comments