Skip to content

Commit e8744ed

Browse files
committed
Replace SyntaxRewriter usage with ted in reorder_impl assist
1 parent 15b3466 commit e8744ed

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

crates/ide_assists/src/handlers/reorder_impl.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use rustc_hash::FxHashMap;
44
use hir::{PathResolution, Semantics};
55
use ide_db::RootDatabase;
66
use syntax::{
7-
algo,
87
ast::{self, NameOwner},
9-
AstNode,
8+
ted, AstNode,
109
};
1110

1211
use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -75,13 +74,18 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
7574
}
7675

7776
let target = items.syntax().text_range();
78-
acc.add(AssistId("reorder_impl", AssistKind::RefactorRewrite), "Sort methods", target, |edit| {
79-
let mut rewriter = algo::SyntaxRewriter::default();
80-
for (old, new) in methods.iter().zip(&sorted) {
81-
rewriter.replace(old.syntax(), new.syntax());
82-
}
83-
edit.rewrite(rewriter);
84-
})
77+
acc.add(
78+
AssistId("reorder_impl", AssistKind::RefactorRewrite),
79+
"Sort methods",
80+
target,
81+
|builder| {
82+
for (old, new) in
83+
methods.into_iter().zip(sorted).filter(|(field, sorted)| field != sorted)
84+
{
85+
ted::replace(builder.make_ast_mut(old).syntax(), new.clone_for_update().syntax());
86+
}
87+
},
88+
)
8589
}
8690

8791
fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> {

0 commit comments

Comments
 (0)