|
1 | 1 | use syntax::{
|
2 | 2 | ast::{self, AstNode, HasName, edit_in_place::Indent, make},
|
3 |
| - ted, |
| 3 | + syntax_editor::{Position, SyntaxEditor}, |
4 | 4 | };
|
5 | 5 |
|
6 | 6 | use crate::{AssistContext, AssistId, Assists, utils};
|
7 | 7 |
|
8 |
| -fn insert_impl(impl_: ast::Impl, nominal: &ast::Adt) { |
| 8 | +fn insert_impl(editor: &mut SyntaxEditor, impl_: &ast::Impl, nominal: &ast::Adt) { |
9 | 9 | let indent = nominal.indent_level();
|
10 |
| - ted::insert_all_raw( |
11 |
| - ted::Position::after(nominal.syntax()), |
| 10 | + editor.insert_all( |
| 11 | + Position::after(nominal.syntax()), |
12 | 12 | vec![
|
13 | 13 | // Add a blank line after the ADT, and indentation for the impl to match the ADT
|
14 | 14 | make::tokens::whitespace(&format!("\n\n{indent}")).into(),
|
@@ -51,14 +51,17 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
|
51 | 51 | // Generate the impl
|
52 | 52 | let impl_ = utils::generate_impl(&nominal);
|
53 | 53 |
|
| 54 | + let mut editor = edit.make_editor(nominal.syntax()); |
54 | 55 | // Add a tabstop after the left curly brace
|
55 | 56 | if let Some(cap) = ctx.config.snippet_cap {
|
56 | 57 | if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) {
|
57 |
| - edit.add_tabstop_after_token(cap, l_curly); |
| 58 | + let tabstop = edit.make_tabstop_after(cap); |
| 59 | + editor.add_annotation(l_curly, tabstop); |
58 | 60 | }
|
59 | 61 | }
|
60 | 62 |
|
61 |
| - insert_impl(impl_, &edit.make_mut(nominal)); |
| 63 | + insert_impl(&mut editor, &impl_, &nominal); |
| 64 | + edit.add_file_edits(ctx.vfs_file_id(), editor); |
62 | 65 | },
|
63 | 66 | )
|
64 | 67 | }
|
@@ -97,18 +100,22 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
97 | 100 | // Generate the impl
|
98 | 101 | let impl_ = utils::generate_trait_impl_intransitive(&nominal, make::ty_placeholder());
|
99 | 102 |
|
| 103 | + let mut editor = edit.make_editor(nominal.syntax()); |
100 | 104 | // Make the trait type a placeholder snippet
|
101 | 105 | if let Some(cap) = ctx.config.snippet_cap {
|
102 | 106 | if let Some(trait_) = impl_.trait_() {
|
103 |
| - edit.add_placeholder_snippet(cap, trait_); |
| 107 | + let placeholder = edit.make_placeholder_snippet(cap); |
| 108 | + editor.add_annotation(trait_.syntax(), placeholder); |
104 | 109 | }
|
105 | 110 |
|
106 | 111 | if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) {
|
107 |
| - edit.add_tabstop_after_token(cap, l_curly); |
| 112 | + let tabstop = edit.make_tabstop_after(cap); |
| 113 | + editor.add_annotation(l_curly, tabstop); |
108 | 114 | }
|
109 | 115 | }
|
110 | 116 |
|
111 |
| - insert_impl(impl_, &edit.make_mut(nominal)); |
| 117 | + insert_impl(&mut editor, &impl_, &nominal); |
| 118 | + edit.add_file_edits(ctx.vfs_file_id(), editor); |
112 | 119 | },
|
113 | 120 | )
|
114 | 121 | }
|
|
0 commit comments