Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/expand_rest_pattern.rs')
-rw-r--r--crates/ide-assists/src/handlers/expand_rest_pattern.rs47
1 files changed, 21 insertions, 26 deletions
diff --git a/crates/ide-assists/src/handlers/expand_rest_pattern.rs b/crates/ide-assists/src/handlers/expand_rest_pattern.rs
index a7e78dfc9c..c75e4cede7 100644
--- a/crates/ide-assists/src/handlers/expand_rest_pattern.rs
+++ b/crates/ide-assists/src/handlers/expand_rest_pattern.rs
@@ -51,23 +51,25 @@ fn expand_record_rest_pattern(
"Fill struct fields",
rest_pat.syntax().text_range(),
|builder| {
- let make = SyntaxFactory::with_mappings();
- let mut editor = builder.make_editor(rest_pat.syntax());
+ let editor = builder.make_editor(rest_pat.syntax());
+ let make = editor.make();
let new_fields = old_field_list.fields().chain(matched_fields.iter().map(|(f, _)| {
make.record_pat_field_shorthand(
- make.ident_pat(
- false,
- false,
- make.name(&f.name(ctx.sema.db).display_no_db(edition).to_smolstr()),
- )
- .into(),
+ editor
+ .make()
+ .ident_pat(
+ false,
+ false,
+ editor
+ .make()
+ .name(&f.name(ctx.sema.db).display_no_db(edition).to_smolstr()),
+ )
+ .into(),
)
}));
let new_field_list = make.record_pat_field_list(new_fields, None);
editor.replace(old_field_list.syntax(), new_field_list.syntax());
-
- editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
},
)
@@ -130,8 +132,8 @@ fn expand_tuple_struct_rest_pattern(
"Fill tuple struct fields",
rest_pat.syntax().text_range(),
|builder| {
- let make = SyntaxFactory::with_mappings();
- let mut editor = builder.make_editor(rest_pat.syntax());
+ let editor = builder.make_editor(rest_pat.syntax());
+ let make = editor.make();
let mut name_gen = NameGenerator::new_from_scope_locals(ctx.sema.scope(pat.syntax()));
let new_pat = make.tuple_struct_pat(
@@ -141,7 +143,7 @@ fn expand_tuple_struct_rest_pattern(
.chain(fields[prefix_count..fields.len() - suffix_count].iter().map(|f| {
gen_unnamed_pat(
ctx,
- &make,
+ make,
&mut name_gen,
&f.ty(ctx.db()).to_type(ctx.sema.db),
f.index(),
@@ -151,8 +153,6 @@ fn expand_tuple_struct_rest_pattern(
);
editor.replace(pat.syntax(), new_pat.syntax());
-
- editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
},
)
@@ -200,24 +200,21 @@ fn expand_tuple_rest_pattern(
"Fill tuple fields",
rest_pat.syntax().text_range(),
|builder| {
- let make = SyntaxFactory::with_mappings();
- let mut editor = builder.make_editor(rest_pat.syntax());
-
+ let editor = builder.make_editor(rest_pat.syntax());
+ let make = editor.make();
let mut name_gen = NameGenerator::new_from_scope_locals(ctx.sema.scope(pat.syntax()));
let new_pat = make.tuple_pat(
pat.fields()
.take(prefix_count)
.chain(fields[prefix_count..len - suffix_count].iter().enumerate().map(
|(index, ty)| {
- gen_unnamed_pat(ctx, &make, &mut name_gen, ty, prefix_count + index)
+ gen_unnamed_pat(ctx, make, &mut name_gen, ty, prefix_count + index)
},
))
.chain(pat.fields().skip(prefix_count + 1)),
);
editor.replace(pat.syntax(), new_pat.syntax());
-
- editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
},
)
@@ -264,8 +261,8 @@ fn expand_slice_rest_pattern(
"Fill slice fields",
rest_pat.syntax().text_range(),
|builder| {
- let make = SyntaxFactory::with_mappings();
- let mut editor = builder.make_editor(rest_pat.syntax());
+ let editor = builder.make_editor(rest_pat.syntax());
+ let make = editor.make();
let mut name_gen = NameGenerator::new_from_scope_locals(ctx.sema.scope(pat.syntax()));
let new_pat = make.slice_pat(
@@ -273,14 +270,12 @@ fn expand_slice_rest_pattern(
.take(prefix_count)
.chain(
(prefix_count..len - suffix_count)
- .map(|index| gen_unnamed_pat(ctx, &make, &mut name_gen, &ty, index)),
+ .map(|index| gen_unnamed_pat(ctx, make, &mut name_gen, &ty, index)),
)
.chain(pat.pats().skip(prefix_count + 1)),
);
editor.replace(pat.syntax(), new_pat.syntax());
-
- editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
},
)