@@ -24,6 +24,7 @@ pub enum FoldKind {
2424 Array ,
2525 WhereClause ,
2626 ReturnType ,
27+ MatchArm ,
2728}
2829
2930#[ derive( Debug ) ]
@@ -117,6 +118,11 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
117118 res. push( Fold { range, kind: FoldKind :: WhereClause } )
118119 }
119120 } ,
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+ } ,
120126 _ => ( ) ,
121127 }
122128 }
@@ -264,6 +270,16 @@ fn fold_range_for_where_clause(where_clause: ast::WhereClause) -> Option<TextRan
264270 None
265271}
266272
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+
267283#[ cfg( test) ]
268284mod tests {
269285 use test_utils:: extract_tags;
@@ -299,6 +315,7 @@ mod tests {
299315 FoldKind :: Array => "array" ,
300316 FoldKind :: WhereClause => "whereclause" ,
301317 FoldKind :: ReturnType => "returntype" ,
318+ FoldKind :: MatchArm => "matcharm" ,
302319 } ;
303320 assert_eq ! ( kind, & attr. unwrap( ) ) ;
304321 }
@@ -456,6 +473,36 @@ fn main() <fold block>{
456473 ) ;
457474 }
458475
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+
459506 #[ test]
460507 fn fold_big_calls ( ) {
461508 check (
0 commit comments