mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge pull request #18485 from davidkurilla/feat-migrate-add_braces-to-use-SyntaxFactory
feat: convert add_braces to SyntaxFactory SyntaxEditor abstraction
This commit is contained in:
commit
c0bbbb3e5d
1 changed files with 10 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
use syntax::{
|
||||
ast::{self, edit::AstNodeEdit, make},
|
||||
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
|
||||
AstNode,
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue