diff options
author | Lukas Wirth <[email protected]> | 2021-04-19 19:29:14 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-04-20 01:08:21 +0100 |
commit | e8744ed9bb3e139e5d427db1f4f219f1fdeee13e (patch) | |
tree | d9acbe9029b2a05f36ac89bfceb9f42d9c73f5db /crates/ide_assists | |
parent | 15b34667c55e894e0a4881d1544bd2e89f932c01 (diff) |
Replace SyntaxRewriter usage with ted in reorder_impl assist
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/reorder_impl.rs | 22 |
1 files changed, 13 insertions, 9 deletions
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; | |||
4 | use hir::{PathResolution, Semantics}; | 4 | use hir::{PathResolution, Semantics}; |
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | algo, | ||
8 | ast::{self, NameOwner}, | 7 | ast::{self, NameOwner}, |
9 | AstNode, | 8 | ted, AstNode, |
10 | }; | 9 | }; |
11 | 10 | ||
12 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 11 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
@@ -75,13 +74,18 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
75 | } | 74 | } |
76 | 75 | ||
77 | let target = items.syntax().text_range(); | 76 | let target = items.syntax().text_range(); |
78 | acc.add(AssistId("reorder_impl", AssistKind::RefactorRewrite), "Sort methods", target, |edit| { | 77 | acc.add( |
79 | let mut rewriter = algo::SyntaxRewriter::default(); | 78 | AssistId("reorder_impl", AssistKind::RefactorRewrite), |
80 | for (old, new) in methods.iter().zip(&sorted) { | 79 | "Sort methods", |
81 | rewriter.replace(old.syntax(), new.syntax()); | 80 | target, |
82 | } | 81 | |builder| { |
83 | edit.rewrite(rewriter); | 82 | for (old, new) in |
84 | }) | 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 | ) | ||
85 | } | 89 | } |
86 | 90 | ||
87 | fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> { | 91 | fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> { |