Skip to content

Commit

Permalink
feat: convert add_braces to SyntaxFactory SyntaxEditor abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkurilla committed Nov 6, 2024
1 parent 20864ef commit c588849
Showing 1 changed file with 10 additions and 3 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::AstNodeEdit, make, syntax_factory::SyntaxFactory}, syntax_editor::SyntaxEditor,
AstNode,
};

Expand Down Expand Up @@ -39,12 +39,19 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
},
expr.syntax().text_range(),
|builder| {

let make = SyntaxFactory::new();
let mut editor = builder.make_editor(&expr.syntax());

let block_expr = AstNodeEdit::indent(
&make::block_expr(None, Some(expr.clone())),
&make.block_expr(None, Some(expr.clone())),
AstNodeEdit::indent_level(&expr),
);

builder.replace(expr.syntax().text_range(), block_expr.syntax().text());
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 c588849

Please # to comment.