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 ;
12use syntax:: {
23 AstNode ,
34 ast:: { self , edit_in_place:: Indent , syntax_factory:: SyntaxFactory } ,
@@ -59,15 +60,16 @@ enum ParentType {
5960}
6061
6162fn 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 {
6365 let match_arm_expr = match_arm. expr ( ) ?;
6466
6567 if matches ! ( match_arm_expr, ast:: Expr :: BlockExpr ( _) ) {
6668 return None ;
6769 }
6870
6971 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 {
7173 let body = closure_expr. body ( ) ?;
7274
7375 if matches ! ( body, ast:: Expr :: BlockExpr ( _) ) {
@@ -105,6 +107,33 @@ fn foo() {
105107 ) ;
106108 }
107109
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+
108137 #[ test]
109138 fn no_assist_for_closures_with_braces ( ) {
110139 check_assist_not_applicable (
You can’t perform that action at this time.
0 commit comments