From 34db4edb80ac614f5ca8d4e7bea4b6917368d6d6 Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Sun, 14 Jun 2020 22:43:16 +0100 Subject: fill_match_arms bind pattern test --- crates/ra_assists/src/handlers/fill_match_arms.rs | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index cc303285b..9905b9e9f 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -350,6 +350,40 @@ mod tests { ); } + #[test] + fn partial_fill_bind_pat() { + check_assist( + fill_match_arms, + r#" + enum A { + As, + Bs, + Cs(Option), + } + fn main() { + match A::As<|> { + A::As(_) => {} + a @ A::Bs(_) => {} + } + } + "#, + r#" + enum A { + As, + Bs, + Cs(Option), + } + fn main() { + match A::As { + A::As(_) => {} + a @ A::Bs(_) => {} + $0A::Cs(_) => {} + } + } + "#, + ); + } + #[test] fn fill_match_arms_empty_body() { check_assist( -- cgit v1.2.3 From 41f5471f3e5dab3da345361a0924391d6267373f Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Sun, 14 Jun 2020 22:44:28 +0100 Subject: fill_match_arms bind pattern implementation --- crates/ra_assists/src/handlers/fill_match_arms.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 9905b9e9f..569efb768 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -136,8 +136,20 @@ fn is_variant_missing(existing_arms: &mut Vec, var: &Pat) -> bool { } fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool { - let pat_head = pat.syntax().first_child().map(|node| node.text()); - let var_head = var.syntax().first_child().map(|node| node.text()); + let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text()); + + let pat_head = match pat { + Pat::BindPat(bind_pat) => { + if let Some(p) = bind_pat.pat() { + first_node_text(&p) + } else { + return false; + } + } + pat => first_node_text(pat), + }; + + let var_head = first_node_text(var); pat_head == var_head } -- cgit v1.2.3