Skip to content

Commit c43d565

Browse files
committed
refactor: change target parameter to a reference in add_rewrite method
Signed-off-by: Tarek <[email protected]>
1 parent 7149c4d commit c43d565

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

crates/ide-assists/src/handlers/sort_items.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ trait AddRewrite {
114114
label: &str,
115115
old: Vec<T>,
116116
new: Vec<T>,
117-
target: SyntaxNode,
117+
target: &SyntaxNode,
118118
) -> Option<()>;
119119
}
120120

@@ -124,15 +124,14 @@ impl AddRewrite for Assists {
124124
label: &str,
125125
old: Vec<T>,
126126
new: Vec<T>,
127-
target: SyntaxNode,
127+
target: &SyntaxNode,
128128
) -> Option<()> {
129-
let node = old.first().unwrap().syntax().parent().unwrap();
130129
self.add(
131130
AssistId("sort_items", AssistKind::RefactorRewrite),
132131
label,
133132
target.text_range(),
134133
|builder| {
135-
let mut editor = builder.make_editor(&node);
134+
let mut editor = builder.make_editor(target);
136135

137136
old.into_iter().zip(new).for_each(|(old, new)| {
138137
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
@@ -176,7 +175,7 @@ fn add_sort_methods_assist(
176175
return None;
177176
}
178177

179-
acc.add_rewrite("Sort methods alphabetically", methods, sorted, item_list.syntax().clone())
178+
acc.add_rewrite("Sort methods alphabetically", methods, sorted, item_list.syntax())
180179
}
181180

182181
fn add_sort_fields_assist(
@@ -191,12 +190,7 @@ fn add_sort_fields_assist(
191190
return None;
192191
}
193192

194-
acc.add_rewrite(
195-
"Sort fields alphabetically",
196-
fields,
197-
sorted,
198-
record_field_list.syntax().clone(),
199-
)
193+
acc.add_rewrite("Sort fields alphabetically", fields, sorted, record_field_list.syntax())
200194
}
201195

202196
fn add_sort_variants_assist(acc: &mut Assists, variant_list: ast::VariantList) -> Option<()> {
@@ -208,7 +202,7 @@ fn add_sort_variants_assist(acc: &mut Assists, variant_list: ast::VariantList) -
208202
return None;
209203
}
210204

211-
acc.add_rewrite("Sort variants alphabetically", variants, sorted, variant_list.syntax().clone())
205+
acc.add_rewrite("Sort variants alphabetically", variants, sorted, variant_list.syntax())
212206
}
213207

214208
fn sort_by_name<T: HasName + Clone>(initial: &[T]) -> Vec<T> {

0 commit comments

Comments
 (0)