@@ -17,6 +17,8 @@ pub enum FoldKind {
17
17
Block ,
18
18
ArgList ,
19
19
Region ,
20
+ Consts ,
21
+ Statics ,
20
22
}
21
23
22
24
#[ derive( Debug ) ]
@@ -30,6 +32,8 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
30
32
let mut visited_comments = FxHashSet :: default ( ) ;
31
33
let mut visited_imports = FxHashSet :: default ( ) ;
32
34
let mut visited_mods = FxHashSet :: default ( ) ;
35
+ let mut visited_consts = FxHashSet :: default ( ) ;
36
+ let mut visited_statics = FxHashSet :: default ( ) ;
33
37
// regions can be nested, here is a LIFO buffer
34
38
let mut regions_starts: Vec < TextSize > = vec ! [ ] ;
35
39
@@ -91,6 +95,19 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
91
95
res. push ( Fold { range, kind : FoldKind :: Mods } )
92
96
}
93
97
}
98
+
99
+ // Fold groups of consts
100
+ if node. kind ( ) == CONST && !visited_consts. contains ( & node) {
101
+ if let Some ( range) = contiguous_range_for_group ( & node, & mut visited_consts) {
102
+ res. push ( Fold { range, kind : FoldKind :: Consts } )
103
+ }
104
+ }
105
+ // Fold groups of consts
106
+ if node. kind ( ) == STATIC && !visited_statics. contains ( & node) {
107
+ if let Some ( range) = contiguous_range_for_group ( & node, & mut visited_statics) {
108
+ res. push ( Fold { range, kind : FoldKind :: Statics } )
109
+ }
110
+ }
94
111
}
95
112
}
96
113
}
@@ -250,6 +267,8 @@ mod tests {
250
267
FoldKind :: Block => "block" ,
251
268
FoldKind :: ArgList => "arglist" ,
252
269
FoldKind :: Region => "region" ,
270
+ FoldKind :: Consts => "consts" ,
271
+ FoldKind :: Statics => "statics" ,
253
272
} ;
254
273
assert_eq ! ( kind, & attr. unwrap( ) ) ;
255
274
}
@@ -457,4 +476,24 @@ calling_function(x,y);
457
476
"# ,
458
477
)
459
478
}
479
+
480
+ #[ test]
481
+ fn fold_consecutive_const ( ) {
482
+ check (
483
+ r#"
484
+ <fold consts>const FIRST_CONST: &str = "first";
485
+ const SECOND_CONST: &str = "second";</fold>
486
+ "# ,
487
+ )
488
+ }
489
+
490
+ #[ test]
491
+ fn fold_consecutive_static ( ) {
492
+ check (
493
+ r#"
494
+ <fold statics>static FIRST_STATIC: &str = "first";
495
+ static SECOND_STATIC: &str = "second";</fold>
496
+ "# ,
497
+ )
498
+ }
460
499
}
0 commit comments