1
1
use syntax:: {
2
2
Direction , SyntaxKind , T ,
3
- algo:: neighbor,
4
3
ast:: { self , AstNode , edit:: IndentLevel , syntax_factory:: SyntaxFactory } ,
5
4
syntax_editor:: { Element , Position } ,
6
5
} ;
@@ -88,15 +87,8 @@ pub(crate) fn unmerge_match_arm(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
88
87
// body is a block, but we don't bother to check that.
89
88
// - Missing after the arm with arms after, if the arm body is a block. In this case
90
89
// 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 ( ) {
100
92
insert_after_old_arm. push ( make. token ( T ! [ , ] ) . into ( ) ) ;
101
93
}
102
94
@@ -105,9 +97,6 @@ pub(crate) fn unmerge_match_arm(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
105
97
106
98
insert_after_old_arm. push ( new_match_arm. syntax ( ) . clone ( ) . into ( ) ) ;
107
99
108
- if has_comma_after {
109
- insert_after_old_arm. push ( make. token ( T ! [ , ] ) . into ( ) ) ;
110
- }
111
100
editor. insert_all ( Position :: after ( match_arm. syntax ( ) ) , insert_after_old_arm) ;
112
101
editor. add_mappings ( make. finish_with_mappings ( ) ) ;
113
102
edit. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
@@ -256,7 +245,7 @@ fn main() {
256
245
let x = X::A;
257
246
let y = match x {
258
247
X::A => 1i32,
259
- X::B => 1i32
248
+ X::B => 1i32,
260
249
};
261
250
}
262
251
"# ,
@@ -274,7 +263,7 @@ enum X { A, B }
274
263
fn main() {
275
264
let x = X::A;
276
265
match x {
277
- X::A $0| X::B => {},
266
+ X::A $0| X::B => {}
278
267
}
279
268
}
280
269
"# ,
@@ -285,8 +274,8 @@ enum X { A, B }
285
274
fn main() {
286
275
let x = X::A;
287
276
match x {
288
- X::A => {},
289
- X::B => {},
277
+ X::A => {}
278
+ X::B => {}
290
279
}
291
280
}
292
281
"# ,
0 commit comments