10759: make `add_missing_match_arms` applicable at the end of the match r=Veykril a=rainy-me

close #10740

Co-authored-by: rainy-me <github@yue.coffee>
This commit is contained in:
bors[bot] 2021-11-14 12:05:17 +00:00 committed by GitHub
commit 4b9b714b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,6 +197,19 @@ fn cursor_at_trivial_match_arm_list(
return Some(());
}
// match x {
// bar => baz,
// $0
// }
if let Some(last_arm) = match_arm_list.arms().last() {
let last_arm_range = last_arm.syntax().text_range();
let match_expr_range = match_expr.syntax().text_range();
if last_arm_range.end() <= ctx.offset() && ctx.offset() < match_expr_range.end() {
cov_mark::hit!(add_missing_match_arms_end_of_last_arm);
return Some(());
}
}
// match { _$0 => {...} }
let wild_pat = ctx.find_node_at_offset_with_descend::<ast::WildcardPat>()?;
let arm = wild_pat.syntax().parent().and_then(ast::MatchArm::cast)?;
@ -676,6 +689,41 @@ fn main() {
);
}
#[test]
fn add_missing_match_arms_end_of_last_arm() {
cov_mark::check!(add_missing_match_arms_end_of_last_arm);
check_assist(
add_missing_match_arms,
r#"
enum A { One, Two }
enum B { One, Two }
fn main() {
let a = A::One;
let b = B::One;
match (a, b) {
(A::Two, B::One) => {},$0
}
}
"#,
r#"
enum A { One, Two }
enum B { One, Two }
fn main() {
let a = A::One;
let b = B::One;
match (a, b) {
(A::Two, B::One) => {},
$0(A::One, B::One) => todo!(),
(A::One, B::Two) => todo!(),
(A::Two, B::Two) => todo!(),
}
}
"#,
);
}
#[test]
fn add_missing_match_arms_tuple_of_enum() {
check_assist(