refactor: change target parameter to a reference in add_rewrite method

Signed-off-by: Tarek <tareknaser360@gmail.com>
This commit is contained in:
Tarek 2024-12-04 12:42:07 +02:00
parent 7149c4dab9
commit c43d565def

View file

@ -114,7 +114,7 @@ trait AddRewrite {
label: &str,
old: Vec<T>,
new: Vec<T>,
target: SyntaxNode,
target: &SyntaxNode,
) -> Option<()>;
}
@ -124,15 +124,14 @@ impl AddRewrite for Assists {
label: &str,
old: Vec<T>,
new: Vec<T>,
target: SyntaxNode,
target: &SyntaxNode,
) -> Option<()> {
let node = old.first().unwrap().syntax().parent().unwrap();
self.add(
AssistId("sort_items", AssistKind::RefactorRewrite),
label,
target.text_range(),
|builder| {
let mut editor = builder.make_editor(&node);
let mut editor = builder.make_editor(target);
old.into_iter().zip(new).for_each(|(old, new)| {
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
@ -176,7 +175,7 @@ fn add_sort_methods_assist(
return None;
}
acc.add_rewrite("Sort methods alphabetically", methods, sorted, item_list.syntax().clone())
acc.add_rewrite("Sort methods alphabetically", methods, sorted, item_list.syntax())
}
fn add_sort_fields_assist(
@ -191,12 +190,7 @@ fn add_sort_fields_assist(
return None;
}
acc.add_rewrite(
"Sort fields alphabetically",
fields,
sorted,
record_field_list.syntax().clone(),
)
acc.add_rewrite("Sort fields alphabetically", fields, sorted, record_field_list.syntax())
}
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) -
return None;
}
acc.add_rewrite("Sort variants alphabetically", variants, sorted, variant_list.syntax().clone())
acc.add_rewrite("Sort variants alphabetically", variants, sorted, variant_list.syntax())
}
fn sort_by_name<T: HasName + Clone>(initial: &[T]) -> Vec<T> {