@@ -24,6 +24,7 @@ pub enum FoldKind {
24
24
Array ,
25
25
WhereClause ,
26
26
ReturnType ,
27
+ MatchArm ,
27
28
}
28
29
29
30
#[ derive( Debug ) ]
@@ -117,6 +118,11 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
117
118
res. push( Fold { range, kind: FoldKind :: WhereClause } )
118
119
}
119
120
} ,
121
+ ast:: MatchArm ( match_arm) => {
122
+ if let Some ( range) = fold_range_for_multiline_match_arm( match_arm) {
123
+ res. push( Fold { range, kind: FoldKind :: MatchArm } )
124
+ }
125
+ } ,
120
126
_ => ( ) ,
121
127
}
122
128
}
@@ -264,6 +270,16 @@ fn fold_range_for_where_clause(where_clause: ast::WhereClause) -> Option<TextRan
264
270
None
265
271
}
266
272
273
+ fn fold_range_for_multiline_match_arm ( match_arm : ast:: MatchArm ) -> Option < TextRange > {
274
+ if let Some ( _) = fold_kind ( match_arm. expr ( ) ?. syntax ( ) . kind ( ) ) {
275
+ return None ;
276
+ }
277
+ if match_arm. expr ( ) ?. syntax ( ) . text ( ) . contains_char ( '\n' ) {
278
+ return Some ( match_arm. expr ( ) ?. syntax ( ) . text_range ( ) ) ;
279
+ }
280
+ None
281
+ }
282
+
267
283
#[ cfg( test) ]
268
284
mod tests {
269
285
use test_utils:: extract_tags;
@@ -299,6 +315,7 @@ mod tests {
299
315
FoldKind :: Array => "array" ,
300
316
FoldKind :: WhereClause => "whereclause" ,
301
317
FoldKind :: ReturnType => "returntype" ,
318
+ FoldKind :: MatchArm => "matcharm" ,
302
319
} ;
303
320
assert_eq ! ( kind, & attr. unwrap( ) ) ;
304
321
}
@@ -456,6 +473,36 @@ fn main() <fold block>{
456
473
) ;
457
474
}
458
475
476
+ #[ test]
477
+ fn test_fold_multiline_non_block_match_arm ( ) {
478
+ check (
479
+ r#"
480
+ fn main() <fold block>{
481
+ match foo <fold block>{
482
+ block => <fold block>{
483
+ }</fold>,
484
+ matcharm => <fold matcharm>some.
485
+ call().
486
+ chain()</fold>,
487
+ matcharm2
488
+ => 0,
489
+ match_expr => <fold matcharm>match foo2 <fold block>{
490
+ bar => (),
491
+ }</fold></fold>,
492
+ array_list => <fold array>[
493
+ 1,
494
+ 2,
495
+ 3,
496
+ ]</fold>,
497
+ strustS => <fold matcharm>StructS <fold block>{
498
+ a: 31,
499
+ }</fold></fold>,
500
+ }</fold>
501
+ }</fold>
502
+ "# ,
503
+ )
504
+ }
505
+
459
506
#[ test]
460
507
fn fold_big_calls ( ) {
461
508
check (
0 commit comments