Skip to content

Commit 7053018

Browse files
committed
Use SyntaxEditor instead of ted
1 parent fe8643b commit 7053018

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use syntax::ast::edit_in_place::Indent;
2-
use syntax::ast::make;
3-
use syntax::ast::{self, AstNode, HasName};
4-
use syntax::ted;
1+
use syntax::{
2+
ast::{self, AstNode, HasName, edit_in_place::Indent, make},
3+
syntax_editor::Position,
4+
};
55

66
use crate::{AssistContext, AssistId, Assists};
77

@@ -68,7 +68,7 @@ pub(crate) fn generate_asref_impl_from_borrow(
6868
ctx: &AssistContext<'_>,
6969
) -> Option<()> {
7070
let ty = ctx.find_node_at_offset::<ast::Type>()?;
71-
let impl_ = ast::Impl::cast(ty.syntax().parent()?)?.clone_for_update();
71+
let impl_ = ast::Impl::cast(ty.syntax().parent()?)?;
7272
let path = ast::PathType::cast(impl_.trait_()?.syntax().clone())?;
7373
let indent = impl_.indent_level();
7474

@@ -91,16 +91,29 @@ pub(crate) fn generate_asref_impl_from_borrow(
9191
format!("Generate `{target_name}` implement from `{name}`"),
9292
target,
9393
|edit| {
94-
ted::replace(name.syntax(), make::name_ref(target_name).syntax().clone_for_update());
94+
let mut editor = edit.make_editor(impl_.syntax());
95+
editor.replace(name.syntax(), make::name_ref(target_name).syntax().clone_for_update());
9596

9697
if let Some(name) = method.name() {
97-
ted::replace(
98+
editor.replace(
9899
name.syntax(),
99100
make::name(target_method_name).syntax().clone_for_update(),
100101
);
101102
}
102103

103-
edit.insert(target.start(), format!("$0{impl_}\n\n{indent}"));
104+
editor.insert_all(
105+
Position::after(impl_.syntax()),
106+
vec![
107+
make::tokens::whitespace(&format!("\n\n{indent}")).into(),
108+
impl_.syntax().clone_for_update().into(),
109+
],
110+
);
111+
112+
if let Some(cap) = ctx.config.snippet_cap {
113+
edit.add_tabstop_before(cap, impl_);
114+
}
115+
116+
edit.add_file_edits(ctx.vfs_file_id(), editor);
104117
},
105118
)
106119
}

0 commit comments

Comments
 (0)