Auto merge of #12576 - harpsword:fold_range_non_block_match_arm, r=Veykril
feat: add fold range for multi line match arm list fix: #11893
This commit is contained in:
commit
7a87f810ca
@ -24,6 +24,7 @@ pub enum FoldKind {
|
||||
Array,
|
||||
WhereClause,
|
||||
ReturnType,
|
||||
MatchArm,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -117,6 +118,11 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
||||
res.push(Fold { range, kind: FoldKind::WhereClause })
|
||||
}
|
||||
},
|
||||
ast::MatchArm(match_arm) => {
|
||||
if let Some(range) = fold_range_for_multiline_match_arm(match_arm) {
|
||||
res.push(Fold {range, kind: FoldKind::MatchArm})
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@ -264,6 +270,16 @@ fn fold_range_for_where_clause(where_clause: ast::WhereClause) -> Option<TextRan
|
||||
None
|
||||
}
|
||||
|
||||
fn fold_range_for_multiline_match_arm(match_arm: ast::MatchArm) -> Option<TextRange> {
|
||||
if let Some(_) = fold_kind(match_arm.expr()?.syntax().kind()) {
|
||||
return None;
|
||||
}
|
||||
if match_arm.expr()?.syntax().text().contains_char('\n') {
|
||||
return Some(match_arm.expr()?.syntax().text_range());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use test_utils::extract_tags;
|
||||
@ -299,6 +315,7 @@ mod tests {
|
||||
FoldKind::Array => "array",
|
||||
FoldKind::WhereClause => "whereclause",
|
||||
FoldKind::ReturnType => "returntype",
|
||||
FoldKind::MatchArm => "matcharm",
|
||||
};
|
||||
assert_eq!(kind, &attr.unwrap());
|
||||
}
|
||||
@ -456,6 +473,36 @@ fn main() <fold block>{
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fold_multiline_non_block_match_arm() {
|
||||
check(
|
||||
r#"
|
||||
fn main() <fold block>{
|
||||
match foo <fold block>{
|
||||
block => <fold block>{
|
||||
}</fold>,
|
||||
matcharm => <fold matcharm>some.
|
||||
call().
|
||||
chain()</fold>,
|
||||
matcharm2
|
||||
=> 0,
|
||||
match_expr => <fold matcharm>match foo2 <fold block>{
|
||||
bar => (),
|
||||
}</fold></fold>,
|
||||
array_list => <fold array>[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
]</fold>,
|
||||
strustS => <fold matcharm>StructS <fold block>{
|
||||
a: 31,
|
||||
}</fold></fold>,
|
||||
}</fold>
|
||||
}</fold>
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fold_big_calls() {
|
||||
check(
|
||||
|
@ -670,7 +670,8 @@ pub(crate) fn folding_range(
|
||||
| FoldKind::Statics
|
||||
| FoldKind::WhereClause
|
||||
| FoldKind::ReturnType
|
||||
| FoldKind::Array => None,
|
||||
| FoldKind::Array
|
||||
| FoldKind::MatchArm => None,
|
||||
};
|
||||
|
||||
let range = range(line_index, fold.range);
|
||||
|
Loading…
x
Reference in New Issue
Block a user