@@ -18,6 +18,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
1818 format : HoverDocFormat :: Markdown ,
1919 keywords : true ,
2020 max_trait_assoc_items_count : None ,
21+ max_struct_field_count : None ,
2122} ;
2223
2324fn check_hover_no_result ( ra_fixture : & str ) {
@@ -49,6 +50,28 @@ fn check(ra_fixture: &str, expect: Expect) {
4950 expect. assert_eq ( & actual)
5051}
5152
53+ #[ track_caller]
54+ fn check_hover_struct_limit ( count : usize , ra_fixture : & str , expect : Expect ) {
55+ let ( analysis, position) = fixture:: position ( ra_fixture) ;
56+ let hover = analysis
57+ . hover (
58+ & HoverConfig {
59+ links_in_hover : true ,
60+ max_struct_field_count : Some ( count) ,
61+ ..HOVER_BASE_CONFIG
62+ } ,
63+ FileRange { file_id : position. file_id , range : TextRange :: empty ( position. offset ) } ,
64+ )
65+ . unwrap ( )
66+ . unwrap ( ) ;
67+
68+ let content = analysis. db . file_text ( position. file_id ) ;
69+ let hovered_element = & content[ hover. range ] ;
70+
71+ let actual = format ! ( "*{hovered_element}*\n {}\n " , hover. info. markup) ;
72+ expect. assert_eq ( & actual)
73+ }
74+
5275#[ track_caller]
5376fn check_assoc_count ( count : usize , ra_fixture : & str , expect : Expect ) {
5477 let ( analysis, position) = fixture:: position ( ra_fixture) ;
@@ -853,9 +876,7 @@ struct Foo$0 { field: u32 }
853876
854877 ```rust
855878 // size = 4, align = 4
856- struct Foo {
857- field: u32,
858- }
879+ struct Foo
859880 ```
860881 "# ] ] ,
861882 ) ;
@@ -875,8 +896,74 @@ struct Foo$0 where u32: Copy { field: u32 }
875896 struct Foo
876897 where
877898 u32: Copy,
878- {
879- field: u32,
899+ ```
900+ "# ] ] ,
901+ ) ;
902+ }
903+
904+ #[ test]
905+ fn hover_record_struct_limit ( ) {
906+ check_hover_struct_limit (
907+ 3 ,
908+ r#"
909+ struct Foo$0 { a: u32, b: i32, c: i32 }
910+ "# ,
911+ expect ! [ [ r#"
912+ *Foo*
913+
914+ ```rust
915+ test
916+ ```
917+
918+ ```rust
919+ // size = 12 (0xC), align = 4
920+ struct Foo {
921+ a: u32,
922+ b: i32,
923+ c: i32,
924+ }
925+ ```
926+ "# ] ] ,
927+ ) ;
928+ check_hover_struct_limit (
929+ 3 ,
930+ r#"
931+ struct Foo$0 { a: u32 }
932+ "# ,
933+ expect ! [ [ r#"
934+ *Foo*
935+
936+ ```rust
937+ test
938+ ```
939+
940+ ```rust
941+ // size = 4, align = 4
942+ struct Foo {
943+ a: u32,
944+ }
945+ ```
946+ "# ] ] ,
947+ ) ;
948+ check_hover_struct_limit (
949+ 3 ,
950+ r#"
951+ struct Foo$0 { a: u32, b: i32, c: i32, d: u32 }
952+ "# ,
953+ expect ! [ [ r#"
954+ *Foo*
955+
956+ ```rust
957+ test
958+ ```
959+
960+ ```rust
961+ // size = 16 (0x10), align = 4
962+ struct Foo {
963+ a: u32,
964+ b: i32,
965+ c: i32,
966+ /* … */
880967 }
881968 ```
882969 "# ] ] ,
@@ -1344,9 +1431,7 @@ impl Thing {
13441431 ```
13451432
13461433 ```rust
1347- struct Thing {
1348- x: u32,
1349- }
1434+ struct Thing
13501435 ```
13511436 "# ] ] ,
13521437 ) ;
@@ -1365,9 +1450,7 @@ impl Thing {
13651450 ```
13661451
13671452 ```rust
1368- struct Thing {
1369- x: u32,
1370- }
1453+ struct Thing
13711454 ```
13721455 "# ] ] ,
13731456 ) ;
@@ -2599,7 +2682,7 @@ fn main() { let s$0t = S{ f1:0 }; }
25992682 focus_range: 7..8,
26002683 name: "S",
26012684 kind: Struct,
2602- description: "struct S {\n f1: u32,\n} ",
2685+ description: "struct S",
26032686 },
26042687 },
26052688 ],
@@ -2645,7 +2728,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
26452728 focus_range: 24..25,
26462729 name: "S",
26472730 kind: Struct,
2648- description: "struct S<T> {\n f1: T,\n} ",
2731+ description: "struct S<T>",
26492732 },
26502733 },
26512734 ],
@@ -2704,7 +2787,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
27042787 focus_range: 24..25,
27052788 name: "S",
27062789 kind: Struct,
2707- description: "struct S<T> {\n f1: T,\n} ",
2790+ description: "struct S<T>",
27082791 },
27092792 },
27102793 ],
@@ -2957,7 +3040,7 @@ fn main() { let s$0t = foo(); }
29573040 focus_range: 39..41,
29583041 name: "S1",
29593042 kind: Struct,
2960- description: "struct S1 {} ",
3043+ description: "struct S1",
29613044 },
29623045 },
29633046 HoverGotoTypeData {
@@ -2970,7 +3053,7 @@ fn main() { let s$0t = foo(); }
29703053 focus_range: 52..54,
29713054 name: "S2",
29723055 kind: Struct,
2973- description: "struct S2 {} ",
3056+ description: "struct S2",
29743057 },
29753058 },
29763059 ],
@@ -3061,7 +3144,7 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
30613144 focus_range: 36..37,
30623145 name: "S",
30633146 kind: Struct,
3064- description: "struct S {} ",
3147+ description: "struct S",
30653148 },
30663149 },
30673150 ],
@@ -3161,7 +3244,7 @@ fn foo(ar$0g: &impl Foo<S>) {}
31613244 focus_range: 23..24,
31623245 name: "S",
31633246 kind: Struct,
3164- description: "struct S {} ",
3247+ description: "struct S",
31653248 },
31663249 },
31673250 ],
@@ -3198,7 +3281,7 @@ fn main() { let s$0t = foo(); }
31983281 focus_range: 49..50,
31993282 name: "B",
32003283 kind: Struct,
3201- description: "struct B<T> {} ",
3284+ description: "struct B<T>",
32023285 },
32033286 },
32043287 HoverGotoTypeData {
@@ -3287,7 +3370,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
32873370 focus_range: 23..24,
32883371 name: "S",
32893372 kind: Struct,
3290- description: "struct S {} ",
3373+ description: "struct S",
32913374 },
32923375 },
32933376 ],
@@ -3322,7 +3405,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
33223405 focus_range: 50..51,
33233406 name: "B",
33243407 kind: Struct,
3325- description: "struct B<T> {} ",
3408+ description: "struct B<T>",
33263409 },
33273410 },
33283411 HoverGotoTypeData {
@@ -3361,7 +3444,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
33613444 focus_range: 65..66,
33623445 name: "S",
33633446 kind: Struct,
3364- description: "struct S {} ",
3447+ description: "struct S",
33653448 },
33663449 },
33673450 ],
0 commit comments