File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change
1
+ use either:: Either ;
1
2
use syntax:: {
2
3
AstNode ,
3
4
ast:: { self , edit_in_place:: Indent , syntax_factory:: SyntaxFactory } ,
@@ -59,15 +60,16 @@ enum ParentType {
59
60
}
60
61
61
62
fn get_replacement_node ( ctx : & AssistContext < ' _ > ) -> Option < ( ParentType , ast:: Expr ) > {
62
- if let Some ( match_arm) = ctx. find_node_at_offset :: < ast:: MatchArm > ( ) {
63
+ let node = ctx. find_node_at_offset :: < Either < ast:: MatchArm , ast:: ClosureExpr > > ( ) ?;
64
+ if let Either :: Left ( match_arm) = & node {
63
65
let match_arm_expr = match_arm. expr ( ) ?;
64
66
65
67
if matches ! ( match_arm_expr, ast:: Expr :: BlockExpr ( _) ) {
66
68
return None ;
67
69
}
68
70
69
71
return Some ( ( ParentType :: MatchArmExpr , match_arm_expr) ) ;
70
- } else if let Some ( closure_expr) = ctx . find_node_at_offset :: < ast :: ClosureExpr > ( ) {
72
+ } else if let Either :: Right ( closure_expr) = & node {
71
73
let body = closure_expr. body ( ) ?;
72
74
73
75
if matches ! ( body, ast:: Expr :: BlockExpr ( _) ) {
@@ -105,6 +107,33 @@ fn foo() {
105
107
) ;
106
108
}
107
109
110
+ #[ test]
111
+ fn suggest_add_braces_for_closure_in_match ( ) {
112
+ check_assist (
113
+ add_braces,
114
+ r#"
115
+ fn foo() {
116
+ match () {
117
+ () => {
118
+ t(|n|$0 n + 100);
119
+ }
120
+ }
121
+ }
122
+ "# ,
123
+ r#"
124
+ fn foo() {
125
+ match () {
126
+ () => {
127
+ t(|n| {
128
+ n + 100
129
+ });
130
+ }
131
+ }
132
+ }
133
+ "# ,
134
+ ) ;
135
+ }
136
+
108
137
#[ test]
109
138
fn no_assist_for_closures_with_braces ( ) {
110
139
check_assist_not_applicable (
You can’t perform that action at this time.
0 commit comments