aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-27 21:35:57 +0000
committerGitHub <[email protected]>2021-01-27 21:35:57 +0000
commitad3cb2125dee4379c11f447216f510d6544c10c5 (patch)
treede2d601517dbf98b5d007ea8ac7c6634a4ec89a8 /crates/assists/src/handlers
parent671757a5de0bbbdd8f42cd3c2d859a75288e3880 (diff)
parentb883a52712fe9eccf8e5120b7a965ac3c9699d6f (diff)
Merge #7468
7468: Enable fill_match_arms in macros r=Veykril a=Veykril Fixes #3936 The indentation is a bit off, but I don't think it's worth trying to fix that up until we have a proper formatting thing set up, as this most likely requires some hand picked specializing making the implementation worse to read(Assuming this can even be fixed for all cases by hardcoding indentation fixes). bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r--crates/assists/src/handlers/fill_match_arms.rs38
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// ```
39pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 39pub(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#"
761macro_rules! m { ($expr:expr) => {$expr}}
762enum Test {
763 A,
764 B,
765 C,
766}
767
768fn foo(t: Test) {
769 m!(match t$0 {});
770}"#,
771 r#"macro_rules! m { ($expr:expr) => {$expr}}
772enum Test {
773 A,
774 B,
775 C,
776}
777
778fn foo(t: Test) {
779 m!(match t {
780 $0Test::A => {}
781 Test::B => {}
782 Test::C => {}
783});
784}"#,
785 );
786 }
755} 787}