mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +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::{
|
use syntax::{
|
||||||
ast::{self, edit::AstNodeEdit, make},
|
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
|
||||||
AstNode,
|
AstNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,12 +39,16 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
||||||
},
|
},
|
||||||
expr.syntax().text_range(),
|
expr.syntax().text_range(),
|
||||||
|builder| {
|
|builder| {
|
||||||
let block_expr = AstNodeEdit::indent(
|
let make = SyntaxFactory::new();
|
||||||
&make::block_expr(None, Some(expr.clone())),
|
let mut editor = builder.make_editor(expr.syntax());
|
||||||
AstNodeEdit::indent_level(&expr),
|
|
||||||
);
|
|
||||||
|
|
||||||
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