mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Added fixup for match statements w/ missing parts
Passes tests
This commit is contained in:
parent
4904b2bdf8
commit
5cb3e7a41b
1 changed files with 110 additions and 1 deletions
|
@ -67,7 +67,6 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
|
||||||
preorder.skip_subtree();
|
preorder.skip_subtree();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In some other situations, we can fix things by just appending some tokens.
|
// In some other situations, we can fix things by just appending some tokens.
|
||||||
let end_range = TextRange::empty(node.text_range().end());
|
let end_range = TextRange::empty(node.text_range().end());
|
||||||
match_ast! {
|
match_ast! {
|
||||||
|
@ -195,6 +194,69 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
|
||||||
},
|
},
|
||||||
// FIXME: foo::
|
// FIXME: foo::
|
||||||
// FIXME: for, match etc.
|
// FIXME: for, match etc.
|
||||||
|
ast::MatchExpr(it) => {
|
||||||
|
if it.expr().is_none() {
|
||||||
|
let match_token = match it.match_token() {
|
||||||
|
Some(t) => t,
|
||||||
|
None => continue
|
||||||
|
};
|
||||||
|
append.insert(match_token.into(), vec![
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::IDENT,
|
||||||
|
text: "__ra_fixup".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if it.match_arm_list().is_none() {
|
||||||
|
// No match arms
|
||||||
|
append.insert(node.clone().into(), vec![
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::L_CURLY,
|
||||||
|
text: "{".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID,
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::UNDERSCORE,
|
||||||
|
text: "_".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::EQ,
|
||||||
|
text: "=".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::R_ANGLE,
|
||||||
|
text: ">".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::L_CURLY,
|
||||||
|
text: "{".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID,
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::R_CURLY,
|
||||||
|
text: "}".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID,
|
||||||
|
},
|
||||||
|
SyntheticToken {
|
||||||
|
kind: SyntaxKind::R_CURLY,
|
||||||
|
text: "}".into(),
|
||||||
|
range: end_range,
|
||||||
|
id: EMPTY_ID,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,6 +349,53 @@ mod tests {
|
||||||
assert_eq!(tt.to_string(), original_as_tt.to_string());
|
assert_eq!(tt.to_string(), original_as_tt.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_no_expr_no_arms() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
match
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {match __ra_fixup {_ => {}}}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_expr_no_arms() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
match x {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {match x {}}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_no_expr() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
match {
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {match __ra_fixup {_ => {}}}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incomplete_field_expr_1() {
|
fn incomplete_field_expr_1() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue