Skip to content

Commit bef15fc

Browse files
committed
fix: inline editor.replace() calls in reorder_fields assist
Signed-off-by: Tarek <[email protected]>
1 parent b20f93f commit bef15fc

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

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

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use either::Either;
22
use ide_db::FxHashMap;
33
use itertools::Itertools;
4-
use syntax::{
5-
ast, ast::syntax_factory::SyntaxFactory, syntax_editor::SyntaxEditor, AstNode, SmolStr,
6-
SyntaxElement, ToSmolStr,
7-
};
4+
use syntax::{ast, ast::syntax_factory::SyntaxFactory, AstNode, SmolStr, SyntaxElement, ToSmolStr};
85

96
use crate::{AssistContext, AssistId, AssistKind, Assists};
107

@@ -79,10 +76,14 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
7976

8077
match fields {
8178
Either::Left((sorted, field_list)) => {
82-
replace(&mut editor, field_list.fields(), sorted)
79+
field_list.fields().zip(sorted).for_each(|(field, sorted_field)| {
80+
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update());
81+
});
8382
}
8483
Either::Right((sorted, field_list)) => {
85-
replace(&mut editor, field_list.fields(), sorted)
84+
field_list.fields().zip(sorted).for_each(|(field, sorted_field)| {
85+
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update());
86+
});
8687
}
8788
}
8889

@@ -92,16 +93,6 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
9293
)
9394
}
9495

95-
fn replace<T: AstNode + PartialEq>(
96-
editor: &mut SyntaxEditor,
97-
fields: impl Iterator<Item = T>,
98-
sorted_fields: impl IntoIterator<Item = T>,
99-
) {
100-
fields.zip(sorted_fields).for_each(|(field, sorted_field)| {
101-
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update())
102-
});
103-
}
104-
10596
fn compute_fields_ranks(
10697
path: &ast::Path,
10798
ctx: &AssistContext<'_>,

0 commit comments

Comments
 (0)