Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/extract_variable.rs')
-rw-r--r--crates/ide-assists/src/handlers/extract_variable.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/crates/ide-assists/src/handlers/extract_variable.rs b/crates/ide-assists/src/handlers/extract_variable.rs
index 732bab4cec..edf12cde5b 100644
--- a/crates/ide-assists/src/handlers/extract_variable.rs
+++ b/crates/ide-assists/src/handlers/extract_variable.rs
@@ -9,7 +9,6 @@ use syntax::{
ast::{
self, AstNode,
edit::{AstNodeEdit, IndentLevel},
- syntax_factory::SyntaxFactory,
},
syntax_editor::{Element, Position},
};
@@ -206,11 +205,10 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
to_replace.clone()
};
- let make = SyntaxFactory::with_mappings();
let mut editor = edit.make_editor(&place);
- let pat_name = make.name(&var_name);
- let name_expr = make.expr_path(make.ident_path(&var_name));
+ let pat_name = editor.make().name(&var_name);
+ let name_expr = editor.make().expr_path(editor.make().ident_path(&var_name));
if let Some(cap) = ctx.config.snippet_cap {
let tabstop = edit.make_tabstop_before(cap);
@@ -219,27 +217,33 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let initializer = match ty.as_ref().filter(|_| needs_ref) {
Some(receiver_type) if receiver_type.is_mutable_reference() => {
- make.expr_ref(to_extract_no_ref.clone(), true)
+ editor.make().expr_ref(to_extract_no_ref.clone(), true)
}
Some(receiver_type) if receiver_type.is_reference() => {
- make.expr_ref(to_extract_no_ref.clone(), false)
+ editor.make().expr_ref(to_extract_no_ref.clone(), false)
}
_ => to_extract_no_ref.clone(),
};
let new_stmt: ast::Stmt = match kind {
ExtractionKind::Variable => {
- let ident_pat = make.ident_pat(false, needs_mut, pat_name);
- make.let_stmt(ident_pat.into(), None, Some(initializer)).into()
+ let ident_pat = editor.make().ident_pat(false, needs_mut, pat_name);
+ editor.make().let_stmt(ident_pat.into(), None, Some(initializer)).into()
}
ExtractionKind::Constant => {
- let ast_ty = make.ty(&ty_string);
- ast::Item::Const(make.item_const(None, None, pat_name, ast_ty, initializer))
- .into()
+ let ast_ty = editor.make().ty(&ty_string);
+ ast::Item::Const(editor.make().item_const(
+ None,
+ None,
+ pat_name,
+ ast_ty,
+ initializer,
+ ))
+ .into()
}
ExtractionKind::Static => {
- let ast_ty = make.ty(&ty_string);
- ast::Item::Static(make.item_static(
+ let ast_ty = editor.make().ty(&ty_string);
+ ast::Item::Static(editor.make().item_static(
None,
false,
false,
@@ -267,7 +271,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
Position::before(place),
vec![
new_stmt.syntax().clone().into(),
- make.whitespace(&trailing_ws).into(),
+ editor.make().whitespace(&trailing_ws).into(),
],
);
@@ -284,21 +288,19 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let block = if to_wrap.syntax() == &expr_replace {
// Since `expr_replace` is the same that needs to be wrapped in a block,
// we can just directly replace it with a block
- make.block_expr([new_stmt], Some(name_expr))
+ editor.make().block_expr([new_stmt], Some(name_expr))
} else {
// `expr_replace` is a descendant of `to_wrap`, so we just replace it with `name_expr`.
editor
.replace_all(to_replace, vec![name_expr.syntax().syntax_element()]);
- make.block_expr([new_stmt], Some(to_wrap.clone()))
+ editor.make().block_expr([new_stmt], Some(to_wrap.clone()))
}
// fixup indentation of block
- .indent_with_mapping(indent_to, &make);
+ .indent_with_mapping(indent_to, editor.make());
editor.replace(to_wrap.syntax(), block.syntax());
}
}
-
- editor.add_mappings(make.finish_with_mappings());
edit.add_file_edits(ctx.vfs_file_id(), editor);
edit.rename();
},