Skip to content

Commit

Permalink
Merge pull request #18485 from davidkurilla/feat-migrate-add_braces-t…
Browse files Browse the repository at this point in the history
…o-use-SyntaxFactory

feat: convert add_braces to SyntaxFactory SyntaxEditor abstraction
  • Loading branch information
davidbarsky authored Nov 19, 2024
2 parents 70a098e + c627c1a commit 297db65
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use syntax::{
ast::{self, edit::AstNodeEdit, make},
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
AstNode,
};

Expand Down Expand Up @@ -39,12 +39,16 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
},
expr.syntax().text_range(),
|builder| {
let block_expr = AstNodeEdit::indent(
&make::block_expr(None, Some(expr.clone())),
AstNodeEdit::indent_level(&expr),
);
let make = SyntaxFactory::new();
let mut editor = builder.make_editor(expr.syntax());

builder.replace(expr.syntax().text_range(), block_expr.syntax().text());
let block_expr = make.block_expr(None, Some(expr.clone()));
block_expr.indent(expr.indent_level());

editor.replace(expr.syntax(), block_expr.syntax());

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.file_id(), editor);
},
)
}
Expand Down

0 comments on commit 297db65

Please sign in to comment.