11use syntax:: {
22 Direction , SyntaxKind , T ,
3- algo:: neighbor,
43 ast:: { self , AstNode , edit:: IndentLevel , syntax_factory:: SyntaxFactory } ,
54 syntax_editor:: { Element , Position } ,
65} ;
@@ -88,15 +87,8 @@ pub(crate) fn unmerge_match_arm(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
8887 // body is a block, but we don't bother to check that.
8988 // - Missing after the arm with arms after, if the arm body is a block. In this case
9089 // we don't want to insert a comma at all.
91- let has_comma_after =
92- std:: iter:: successors ( match_arm. syntax ( ) . last_child_or_token ( ) , |it| {
93- it. prev_sibling_or_token ( )
94- } )
95- . map ( |it| it. kind ( ) )
96- . find ( |it| !it. is_trivia ( ) )
97- == Some ( T ! [ , ] ) ;
98- let has_arms_after = neighbor ( & match_arm, Direction :: Next ) . is_some ( ) ;
99- if !has_comma_after && !has_arms_after {
90+ let has_comma_after = match_arm. comma_token ( ) . is_some ( ) ;
91+ if !has_comma_after && !match_arm. expr ( ) . unwrap ( ) . is_block_like ( ) {
10092 insert_after_old_arm. push ( make. token ( T ! [ , ] ) . into ( ) ) ;
10193 }
10294
@@ -105,9 +97,6 @@ pub(crate) fn unmerge_match_arm(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
10597
10698 insert_after_old_arm. push ( new_match_arm. syntax ( ) . clone ( ) . into ( ) ) ;
10799
108- if has_comma_after {
109- insert_after_old_arm. push ( make. token ( T ! [ , ] ) . into ( ) ) ;
110- }
111100 editor. insert_all ( Position :: after ( match_arm. syntax ( ) ) , insert_after_old_arm) ;
112101 editor. add_mappings ( make. finish_with_mappings ( ) ) ;
113102 edit. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
@@ -256,7 +245,7 @@ fn main() {
256245 let x = X::A;
257246 let y = match x {
258247 X::A => 1i32,
259- X::B => 1i32
248+ X::B => 1i32,
260249 };
261250}
262251"# ,
@@ -274,7 +263,7 @@ enum X { A, B }
274263fn main() {
275264 let x = X::A;
276265 match x {
277- X::A $0| X::B => {},
266+ X::A $0| X::B => {}
278267 }
279268}
280269"# ,
@@ -285,8 +274,8 @@ enum X { A, B }
285274fn main() {
286275 let x = X::A;
287276 match x {
288- X::A => {},
289- X::B => {},
277+ X::A => {}
278+ X::B => {}
290279 }
291280}
292281"# ,
0 commit comments