diff options
author | Domantas Jadenkus <[email protected]> | 2021-05-24 19:53:42 +0100 |
---|---|---|
committer | Domantas Jadenkus <[email protected]> | 2021-05-24 20:17:16 +0100 |
commit | 22e5194396c2d26e870cda6e4712f1ec56efb04e (patch) | |
tree | 2d190bbdd34851f91a293a1321acebcb2fb3929b /crates/syntax/src/ast | |
parent | c139eff5b8a764fe64ec28c3028d3deb23c14adc (diff) |
generate match arms with todo!() as placeholder body
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/edit_in_place.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index ca8103668..f7ee29d14 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs | |||
@@ -356,13 +356,17 @@ impl ast::MatchArm { | |||
356 | impl ast::MatchArmList { | 356 | impl ast::MatchArmList { |
357 | pub fn add_arm(&self, arm: ast::MatchArm) { | 357 | pub fn add_arm(&self, arm: ast::MatchArm) { |
358 | normalize_ws_between_braces(self.syntax()); | 358 | normalize_ws_between_braces(self.syntax()); |
359 | let mut elements = Vec::new(); | ||
359 | let position = match self.arms().last() { | 360 | let position = match self.arms().last() { |
360 | Some(last_arm) => { | 361 | Some(last_arm) => { |
361 | let curly = last_arm | 362 | let comma = last_arm |
362 | .syntax() | 363 | .syntax() |
363 | .siblings_with_tokens(Direction::Next) | 364 | .siblings_with_tokens(Direction::Next) |
364 | .find(|it| it.kind() == T![,]); | 365 | .find(|it| it.kind() == T![,]); |
365 | Position::after(curly.unwrap_or_else(|| last_arm.syntax().clone().into())) | 366 | if needs_comma(&last_arm) && comma.is_none() { |
367 | elements.push(make::token(SyntaxKind::COMMA).into()); | ||
368 | } | ||
369 | Position::after(comma.unwrap_or_else(|| last_arm.syntax().clone().into())) | ||
366 | } | 370 | } |
367 | None => match self.l_curly_token() { | 371 | None => match self.l_curly_token() { |
368 | Some(it) => Position::after(it), | 372 | Some(it) => Position::after(it), |
@@ -370,11 +374,16 @@ impl ast::MatchArmList { | |||
370 | }, | 374 | }, |
371 | }; | 375 | }; |
372 | let indent = IndentLevel::from_node(self.syntax()) + 1; | 376 | let indent = IndentLevel::from_node(self.syntax()) + 1; |
373 | let elements = vec![ | 377 | elements.push(make::tokens::whitespace(&format!("\n{}", indent)).into()); |
374 | make::tokens::whitespace(&format!("\n{}", indent)).into(), | 378 | elements.push(arm.syntax().clone().into()); |
375 | arm.syntax().clone().into(), | 379 | if needs_comma(&arm) { |
376 | ]; | 380 | elements.push(make::token(SyntaxKind::COMMA).into()); |
381 | } | ||
377 | ted::insert_all(position, elements); | 382 | ted::insert_all(position, elements); |
383 | |||
384 | fn needs_comma(arm: &ast::MatchArm) -> bool { | ||
385 | arm.expr().map_or(false, |e| !e.is_block_like()) | ||
386 | } | ||
378 | } | 387 | } |
379 | } | 388 | } |
380 | 389 | ||