Skip to content

Commit 4b9b714

Browse files
bors[bot]yue4u
andauthored
Merge #10759
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 <[email protected]>
2 parents 212095a + 1f3da38 commit 4b9b714

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

crates/ide_assists/src/handlers/add_missing_match_arms.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ fn cursor_at_trivial_match_arm_list(
197197
return Some(());
198198
}
199199

200+
// match x {
201+
// bar => baz,
202+
// $0
203+
// }
204+
if let Some(last_arm) = match_arm_list.arms().last() {
205+
let last_arm_range = last_arm.syntax().text_range();
206+
let match_expr_range = match_expr.syntax().text_range();
207+
if last_arm_range.end() <= ctx.offset() && ctx.offset() < match_expr_range.end() {
208+
cov_mark::hit!(add_missing_match_arms_end_of_last_arm);
209+
return Some(());
210+
}
211+
}
212+
200213
// match { _$0 => {...} }
201214
let wild_pat = ctx.find_node_at_offset_with_descend::<ast::WildcardPat>()?;
202215
let arm = wild_pat.syntax().parent().and_then(ast::MatchArm::cast)?;
@@ -676,6 +689,41 @@ fn main() {
676689
);
677690
}
678691

692+
#[test]
693+
fn add_missing_match_arms_end_of_last_arm() {
694+
cov_mark::check!(add_missing_match_arms_end_of_last_arm);
695+
check_assist(
696+
add_missing_match_arms,
697+
r#"
698+
enum A { One, Two }
699+
enum B { One, Two }
700+
701+
fn main() {
702+
let a = A::One;
703+
let b = B::One;
704+
match (a, b) {
705+
(A::Two, B::One) => {},$0
706+
}
707+
}
708+
"#,
709+
r#"
710+
enum A { One, Two }
711+
enum B { One, Two }
712+
713+
fn main() {
714+
let a = A::One;
715+
let b = B::One;
716+
match (a, b) {
717+
(A::Two, B::One) => {},
718+
$0(A::One, B::One) => todo!(),
719+
(A::One, B::Two) => todo!(),
720+
(A::Two, B::Two) => todo!(),
721+
}
722+
}
723+
"#,
724+
);
725+
}
726+
679727
#[test]
680728
fn add_missing_match_arms_tuple_of_enum() {
681729
check_assist(

0 commit comments

Comments
 (0)