aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast/edit_in_place.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast/edit_in_place.rs')
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index abab0269a..14624c682 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -368,6 +368,46 @@ impl ast::MatchArmList {
368 } 368 }
369} 369}
370 370
371impl ast::RecordExprFieldList {
372 pub fn add_field(&self, field: ast::RecordExprField) {
373 let is_multiline = self.syntax().text().contains_char('\n');
374 let whitespace = if is_multiline {
375 let indent = IndentLevel::from_node(self.syntax()) + 1;
376 make::tokens::whitespace(&format!("\n{}", indent))
377 } else {
378 make::tokens::single_space()
379 };
380
381 let position = match self.fields().last() {
382 Some(last_field) => {
383 let comma = match last_field
384 .syntax()
385 .siblings_with_tokens(Direction::Next)
386 .filter_map(|it| it.into_token())
387 .find(|it| it.kind() == T![,])
388 {
389 Some(it) => it,
390 None => {
391 let comma = ast::make::token(T![,]);
392 ted::insert(Position::after(last_field.syntax()), &comma);
393 comma
394 }
395 };
396 Position::after(comma)
397 }
398 None => match self.l_curly_token() {
399 Some(it) => Position::after(it),
400 None => Position::last_child_of(self.syntax()),
401 },
402 };
403
404 ted::insert_all(position, vec![whitespace.into(), field.syntax().clone().into()]);
405 if is_multiline {
406 ted::insert(Position::after(field.syntax()), ast::make::token(T![,]));
407 }
408 }
409}
410
371fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> { 411fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
372 let l = node 412 let l = node
373 .children_with_tokens() 413 .children_with_tokens()