diff options
author | Lukas Wirth <[email protected]> | 2021-01-27 21:32:40 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-01-27 21:32:40 +0000 |
commit | b883a52712fe9eccf8e5120b7a965ac3c9699d6f (patch) | |
tree | de2d601517dbf98b5d007ea8ac7c6634a4ec89a8 /crates/assists/src/handlers | |
parent | 671757a5de0bbbdd8f42cd3c2d859a75288e3880 (diff) |
Enable fill_match_arms in macros
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r-- | crates/assists/src/handlers/fill_match_arms.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/crates/assists/src/handlers/fill_match_arms.rs b/crates/assists/src/handlers/fill_match_arms.rs index 4964ddc7d..7086e47d2 100644 --- a/crates/assists/src/handlers/fill_match_arms.rs +++ b/crates/assists/src/handlers/fill_match_arms.rs | |||
@@ -37,7 +37,7 @@ use crate::{ | |||
37 | // } | 37 | // } |
38 | // ``` | 38 | // ``` |
39 | pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 39 | pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
40 | let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?; | 40 | let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?; |
41 | let match_arm_list = match_expr.match_arm_list()?; | 41 | let match_arm_list = match_expr.match_arm_list()?; |
42 | 42 | ||
43 | let expr = match_expr.expr()?; | 43 | let expr = match_expr.expr()?; |
@@ -103,7 +103,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
103 | return None; | 103 | return None; |
104 | } | 104 | } |
105 | 105 | ||
106 | let target = match_expr.syntax().text_range(); | 106 | let target = ctx.sema.original_range(match_expr.syntax()).range; |
107 | acc.add( | 107 | acc.add( |
108 | AssistId("fill_match_arms", AssistKind::QuickFix), | 108 | AssistId("fill_match_arms", AssistKind::QuickFix), |
109 | "Fill match arms", | 109 | "Fill match arms", |
@@ -113,7 +113,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
113 | let n_old_arms = new_arm_list.arms().count(); | 113 | let n_old_arms = new_arm_list.arms().count(); |
114 | let new_arm_list = new_arm_list.append_arms(missing_arms); | 114 | let new_arm_list = new_arm_list.append_arms(missing_arms); |
115 | let first_new_arm = new_arm_list.arms().nth(n_old_arms); | 115 | let first_new_arm = new_arm_list.arms().nth(n_old_arms); |
116 | let old_range = match_arm_list.syntax().text_range(); | 116 | let old_range = ctx.sema.original_range(match_arm_list.syntax()).range; |
117 | match (first_new_arm, ctx.config.snippet_cap) { | 117 | match (first_new_arm, ctx.config.snippet_cap) { |
118 | (Some(first_new_arm), Some(cap)) => { | 118 | (Some(first_new_arm), Some(cap)) => { |
119 | let extend_lifetime; | 119 | let extend_lifetime; |
@@ -752,4 +752,36 @@ fn foo(opt: Option<i32>) { | |||
752 | "#, | 752 | "#, |
753 | ); | 753 | ); |
754 | } | 754 | } |
755 | |||
756 | #[test] | ||
757 | fn works_inside_macro_call() { | ||
758 | check_assist( | ||
759 | fill_match_arms, | ||
760 | r#" | ||
761 | macro_rules! m { ($expr:expr) => {$expr}} | ||
762 | enum Test { | ||
763 | A, | ||
764 | B, | ||
765 | C, | ||
766 | } | ||
767 | |||
768 | fn foo(t: Test) { | ||
769 | m!(match t$0 {}); | ||
770 | }"#, | ||
771 | r#"macro_rules! m { ($expr:expr) => {$expr}} | ||
772 | enum Test { | ||
773 | A, | ||
774 | B, | ||
775 | C, | ||
776 | } | ||
777 | |||
778 | fn foo(t: Test) { | ||
779 | m!(match t { | ||
780 | $0Test::A => {} | ||
781 | Test::B => {} | ||
782 | Test::C => {} | ||
783 | }); | ||
784 | }"#, | ||
785 | ); | ||
786 | } | ||
755 | } | 787 | } |