aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/make.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r--crates/ra_syntax/src/ast/make.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 38c0e9a66..629503dc5 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -122,11 +122,18 @@ pub fn match_arm(pats: impl IntoIterator<Item = ast::Pat>, expr: ast::Expr) -> a
122} 122}
123 123
124pub fn match_arm_list(arms: impl IntoIterator<Item = ast::MatchArm>) -> ast::MatchArmList { 124pub fn match_arm_list(arms: impl IntoIterator<Item = ast::MatchArm>) -> ast::MatchArmList {
125 let arms_str = arms.into_iter().map(|arm| format!("\n {}", arm.syntax())).join(","); 125 let arms_str = arms
126 return from_text(&format!("{},\n", arms_str)); 126 .into_iter()
127 .map(|arm| {
128 let needs_comma = arm.expr().map_or(true, |it| !it.is_block_like());
129 let comma = if needs_comma { "," } else { "" };
130 format!(" {}{}\n", arm.syntax(), comma)
131 })
132 .collect::<String>();
133 return from_text(&format!("{}", arms_str));
127 134
128 fn from_text(text: &str) -> ast::MatchArmList { 135 fn from_text(text: &str) -> ast::MatchArmList {
129 ast_from_text(&format!("fn f() {{ match () {{{}}} }}", text)) 136 ast_from_text(&format!("fn f() {{ match () {{\n{}}} }}", text))
130 } 137 }
131} 138}
132 139