@@ -23,6 +23,7 @@ pub enum FoldKind {
23
23
WhereClause ,
24
24
ReturnType ,
25
25
MatchArm ,
26
+ Function ,
26
27
// region: item runs
27
28
Modules ,
28
29
Consts ,
@@ -60,31 +61,32 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
60
61
NodeOrToken :: Token ( token) => token. text ( ) . contains ( '\n' ) ,
61
62
} ;
62
63
if is_multiline {
63
- // for the arg list, we need to special handle
64
- if matches ! ( element. kind( ) , ARG_LIST | PARAM_LIST ) {
64
+ // for the func with multiline param list
65
+ if matches ! ( element. kind( ) , FN ) {
65
66
if let NodeOrToken :: Node ( node) = & element {
66
- if let Some ( fn_node) = node. parent ( ) . and_then ( ast:: Fn :: cast) {
67
+ if let Some ( fn_node) = ast:: Fn :: cast ( node. clone ( ) ) {
68
+ if !fn_node
69
+ . param_list ( )
70
+ . map ( |param_list| param_list. syntax ( ) . text ( ) . contains_char ( '\n' ) )
71
+ . unwrap_or ( false )
72
+ {
73
+ continue ;
74
+ }
75
+
67
76
if let Some ( body) = fn_node. body ( ) {
68
- // just add a big fold combine the params and body
69
77
res. push ( Fold {
70
78
range : TextRange :: new (
71
79
node. text_range ( ) . start ( ) ,
72
- body . syntax ( ) . text_range ( ) . end ( ) ,
80
+ node . text_range ( ) . end ( ) ,
73
81
) ,
74
- kind : FoldKind :: ArgList ,
82
+ kind : FoldKind :: Function ,
75
83
} ) ;
76
84
merged_fn_bodies. insert ( body. syntax ( ) . text_range ( ) ) ;
77
85
continue ;
78
86
}
79
87
}
80
88
}
81
89
}
82
- // skip the merged function body
83
- if matches ! ( element. kind( ) , BLOCK_EXPR )
84
- && merged_fn_bodies. contains ( & element. text_range ( ) )
85
- {
86
- continue ;
87
- }
88
90
res. push ( Fold { range : element. text_range ( ) , kind } ) ;
89
91
continue ;
90
92
}
@@ -178,6 +180,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
178
180
ARG_LIST | PARAM_LIST | GENERIC_ARG_LIST | GENERIC_PARAM_LIST => Some ( FoldKind :: ArgList ) ,
179
181
ARRAY_EXPR => Some ( FoldKind :: Array ) ,
180
182
RET_TYPE => Some ( FoldKind :: ReturnType ) ,
183
+ FN => Some ( FoldKind :: Function ) ,
181
184
WHERE_CLAUSE => Some ( FoldKind :: WhereClause ) ,
182
185
ASSOC_ITEM_LIST
183
186
| RECORD_FIELD_LIST
@@ -349,6 +352,7 @@ mod tests {
349
352
FoldKind :: WhereClause => "whereclause" ,
350
353
FoldKind :: ReturnType => "returntype" ,
351
354
FoldKind :: MatchArm => "matcharm" ,
355
+ FoldKind :: Function => "function" ,
352
356
FoldKind :: TraitAliases => "traitaliases" ,
353
357
FoldKind :: ExternCrates => "externcrates" ,
354
358
} ;
0 commit comments