From e8744ed9bb3e139e5d427db1f4f219f1fdeee13e Mon Sep 17 00:00:00 2001
From: Lukas Wirth <lukastw97@gmail.com>
Date: Mon, 19 Apr 2021 20:29:14 +0200
Subject: Replace SyntaxRewriter usage with ted in reorder_impl assist

---
 crates/ide_assists/src/handlers/reorder_impl.rs | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

(limited to 'crates/ide_assists')

diff --git a/crates/ide_assists/src/handlers/reorder_impl.rs b/crates/ide_assists/src/handlers/reorder_impl.rs
index f976e73ad..fd2897c4c 100644
--- a/crates/ide_assists/src/handlers/reorder_impl.rs
+++ b/crates/ide_assists/src/handlers/reorder_impl.rs
@@ -4,9 +4,8 @@ use rustc_hash::FxHashMap;
 use hir::{PathResolution, Semantics};
 use ide_db::RootDatabase;
 use syntax::{
-    algo,
     ast::{self, NameOwner},
-    AstNode,
+    ted, AstNode,
 };
 
 use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -75,13 +74,18 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
     }
 
     let target = items.syntax().text_range();
-    acc.add(AssistId("reorder_impl", AssistKind::RefactorRewrite), "Sort methods", target, |edit| {
-        let mut rewriter = algo::SyntaxRewriter::default();
-        for (old, new) in methods.iter().zip(&sorted) {
-            rewriter.replace(old.syntax(), new.syntax());
-        }
-        edit.rewrite(rewriter);
-    })
+    acc.add(
+        AssistId("reorder_impl", AssistKind::RefactorRewrite),
+        "Sort methods",
+        target,
+        |builder| {
+            for (old, new) in
+                methods.into_iter().zip(sorted).filter(|(field, sorted)| field != sorted)
+            {
+                ted::replace(builder.make_ast_mut(old).syntax(), new.clone_for_update().syntax());
+            }
+        },
+    )
 }
 
 fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> {
-- 
cgit v1.2.3