@@ -18,6 +18,7 @@ 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_struct_field_count : None ,
21
22
} ;
22
23
23
24
fn check_hover_no_result ( ra_fixture : & str ) {
@@ -49,6 +50,28 @@ fn check(ra_fixture: &str, expect: Expect) {
49
50
expect. assert_eq ( & actual)
50
51
}
51
52
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
+
52
75
#[ track_caller]
53
76
fn check_assoc_count ( count : usize , ra_fixture : & str , expect : Expect ) {
54
77
let ( analysis, position) = fixture:: position ( ra_fixture) ;
@@ -853,9 +876,7 @@ struct Foo$0 { field: u32 }
853
876
854
877
```rust
855
878
// size = 4, align = 4
856
- struct Foo {
857
- field: u32,
858
- }
879
+ struct Foo
859
880
```
860
881
"# ] ] ,
861
882
) ;
@@ -875,8 +896,74 @@ struct Foo$0 where u32: Copy { field: u32 }
875
896
struct Foo
876
897
where
877
898
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
+ /* … */
880
967
}
881
968
```
882
969
"# ] ] ,
@@ -1344,9 +1431,7 @@ impl Thing {
1344
1431
```
1345
1432
1346
1433
```rust
1347
- struct Thing {
1348
- x: u32,
1349
- }
1434
+ struct Thing
1350
1435
```
1351
1436
"# ] ] ,
1352
1437
) ;
@@ -1365,9 +1450,7 @@ impl Thing {
1365
1450
```
1366
1451
1367
1452
```rust
1368
- struct Thing {
1369
- x: u32,
1370
- }
1453
+ struct Thing
1371
1454
```
1372
1455
"# ] ] ,
1373
1456
) ;
@@ -2599,7 +2682,7 @@ fn main() { let s$0t = S{ f1:0 }; }
2599
2682
focus_range: 7..8,
2600
2683
name: "S",
2601
2684
kind: Struct,
2602
- description: "struct S {\n f1: u32,\n} ",
2685
+ description: "struct S",
2603
2686
},
2604
2687
},
2605
2688
],
@@ -2645,7 +2728,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
2645
2728
focus_range: 24..25,
2646
2729
name: "S",
2647
2730
kind: Struct,
2648
- description: "struct S<T> {\n f1: T,\n} ",
2731
+ description: "struct S<T>",
2649
2732
},
2650
2733
},
2651
2734
],
@@ -2704,7 +2787,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2704
2787
focus_range: 24..25,
2705
2788
name: "S",
2706
2789
kind: Struct,
2707
- description: "struct S<T> {\n f1: T,\n} ",
2790
+ description: "struct S<T>",
2708
2791
},
2709
2792
},
2710
2793
],
@@ -2957,7 +3040,7 @@ fn main() { let s$0t = foo(); }
2957
3040
focus_range: 39..41,
2958
3041
name: "S1",
2959
3042
kind: Struct,
2960
- description: "struct S1 {} ",
3043
+ description: "struct S1",
2961
3044
},
2962
3045
},
2963
3046
HoverGotoTypeData {
@@ -2970,7 +3053,7 @@ fn main() { let s$0t = foo(); }
2970
3053
focus_range: 52..54,
2971
3054
name: "S2",
2972
3055
kind: Struct,
2973
- description: "struct S2 {} ",
3056
+ description: "struct S2",
2974
3057
},
2975
3058
},
2976
3059
],
@@ -3061,7 +3144,7 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
3061
3144
focus_range: 36..37,
3062
3145
name: "S",
3063
3146
kind: Struct,
3064
- description: "struct S {} ",
3147
+ description: "struct S",
3065
3148
},
3066
3149
},
3067
3150
],
@@ -3161,7 +3244,7 @@ fn foo(ar$0g: &impl Foo<S>) {}
3161
3244
focus_range: 23..24,
3162
3245
name: "S",
3163
3246
kind: Struct,
3164
- description: "struct S {} ",
3247
+ description: "struct S",
3165
3248
},
3166
3249
},
3167
3250
],
@@ -3198,7 +3281,7 @@ fn main() { let s$0t = foo(); }
3198
3281
focus_range: 49..50,
3199
3282
name: "B",
3200
3283
kind: Struct,
3201
- description: "struct B<T> {} ",
3284
+ description: "struct B<T>",
3202
3285
},
3203
3286
},
3204
3287
HoverGotoTypeData {
@@ -3287,7 +3370,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
3287
3370
focus_range: 23..24,
3288
3371
name: "S",
3289
3372
kind: Struct,
3290
- description: "struct S {} ",
3373
+ description: "struct S",
3291
3374
},
3292
3375
},
3293
3376
],
@@ -3322,7 +3405,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3322
3405
focus_range: 50..51,
3323
3406
name: "B",
3324
3407
kind: Struct,
3325
- description: "struct B<T> {} ",
3408
+ description: "struct B<T>",
3326
3409
},
3327
3410
},
3328
3411
HoverGotoTypeData {
@@ -3361,7 +3444,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3361
3444
focus_range: 65..66,
3362
3445
name: "S",
3363
3446
kind: Struct,
3364
- description: "struct S {} ",
3447
+ description: "struct S",
3365
3448
},
3366
3449
},
3367
3450
],
0 commit comments