Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/promote_local_to_const.rs')
-rw-r--r--crates/ide-assists/src/handlers/promote_local_to_const.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ide-assists/src/handlers/promote_local_to_const.rs b/crates/ide-assists/src/handlers/promote_local_to_const.rs
index 483c90d103..5b6251e3db 100644
--- a/crates/ide-assists/src/handlers/promote_local_to_const.rs
+++ b/crates/ide-assists/src/handlers/promote_local_to_const.rs
@@ -3,7 +3,7 @@ use ide_db::{assists::AssistId, defs::Definition};
use stdx::to_upper_snake_case;
use syntax::{
AstNode,
- ast::{self, HasName, syntax_factory::SyntaxFactory},
+ ast::{self, HasName},
};
use crate::{
@@ -68,18 +68,17 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>)
"Promote local to constant",
let_stmt.syntax().text_range(),
|edit| {
- let make = SyntaxFactory::with_mappings();
let mut editor = edit.make_editor(let_stmt.syntax());
let name = to_upper_snake_case(&name.to_string());
let usages = Definition::Local(local).usages(&ctx.sema).all();
if let Some(usages) = usages.references.get(&ctx.file_id()) {
- let name_ref = make.name_ref(&name);
+ let name_ref = editor.make().name_ref(&name);
for usage in usages {
let Some(usage_name) = usage.name.as_name_ref().cloned() else { continue };
if let Some(record_field) = ast::RecordExprField::for_name_ref(&usage_name) {
- let path = make.ident_path(&name);
- let name_expr = make.expr_path(path);
+ let path = editor.make().ident_path(&name);
+ let name_expr = editor.make().expr_path(path);
utils::replace_record_field_expr(ctx, edit, record_field, name_expr);
} else {
let usage_range = usage.range;
@@ -88,7 +87,13 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>)
}
}
- let item = make.item_const(None, None, make.name(&name), make.ty(&ty), initializer);
+ let item = editor.make().item_const(
+ None,
+ None,
+ editor.make().name(&name),
+ editor.make().ty(&ty),
+ initializer,
+ );
if let Some((cap, name)) = ctx.config.snippet_cap.zip(item.name()) {
let tabstop = edit.make_tabstop_before(cap);
@@ -97,7 +102,6 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>)
editor.replace(let_stmt.syntax(), item.syntax());
- editor.add_mappings(make.finish_with_mappings());
edit.add_file_edits(ctx.vfs_file_id(), editor);
},
)