about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShoyu Vanilla (Flint) <modulo641@gmail.com>2025-07-10 11:45:25 +0000
committerGitHub <noreply@github.com>2025-07-10 11:45:25 +0000
commit649ec27cedcf4cb1519b5d78978712a66ee270c0 (patch)
tree85f86431c56278ad6913b87a2bbb34df467e3b73
parent7625ed93945961d742bcaf406eff6f5b9b494b61 (diff)
parentb6920519e32fee78a19e281ce3a3f84744c6527a (diff)
downloadrust-649ec27cedcf4cb1519b5d78978712a66ee270c0.tar.gz
rust-649ec27cedcf4cb1519b5d78978712a66ee270c0.zip
Merge pull request #20223 from Hmikihiro/migrate_generate_impl
Migrate `generate_impl` assist to use `SyntaxEditor`
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
index 2862e6d5afb..14601ca0207 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
@@ -1,14 +1,14 @@
 use syntax::{
     ast::{self, AstNode, HasName, edit_in_place::Indent, make},
-    ted,
+    syntax_editor::{Position, SyntaxEditor},
 };
 
 use crate::{AssistContext, AssistId, Assists, utils};
 
-fn insert_impl(impl_: ast::Impl, nominal: &ast::Adt) {
+fn insert_impl(editor: &mut SyntaxEditor, impl_: &ast::Impl, nominal: &ast::Adt) {
     let indent = nominal.indent_level();
-    ted::insert_all_raw(
-        ted::Position::after(nominal.syntax()),
+    editor.insert_all(
+        Position::after(nominal.syntax()),
         vec![
             // Add a blank line after the ADT, and indentation for the impl to match the ADT
             make::tokens::whitespace(&format!("\n\n{indent}")).into(),
@@ -51,14 +51,17 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
             // Generate the impl
             let impl_ = utils::generate_impl(&nominal);
 
+            let mut editor = edit.make_editor(nominal.syntax());
             // Add a tabstop after the left curly brace
             if let Some(cap) = ctx.config.snippet_cap {
                 if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) {
-                    edit.add_tabstop_after_token(cap, l_curly);
+                    let tabstop = edit.make_tabstop_after(cap);
+                    editor.add_annotation(l_curly, tabstop);
                 }
             }
 
-            insert_impl(impl_, &edit.make_mut(nominal));
+            insert_impl(&mut editor, &impl_, &nominal);
+            edit.add_file_edits(ctx.vfs_file_id(), editor);
         },
     )
 }
@@ -97,18 +100,22 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
             // Generate the impl
             let impl_ = utils::generate_trait_impl_intransitive(&nominal, make::ty_placeholder());
 
+            let mut editor = edit.make_editor(nominal.syntax());
             // Make the trait type a placeholder snippet
             if let Some(cap) = ctx.config.snippet_cap {
                 if let Some(trait_) = impl_.trait_() {
-                    edit.add_placeholder_snippet(cap, trait_);
+                    let placeholder = edit.make_placeholder_snippet(cap);
+                    editor.add_annotation(trait_.syntax(), placeholder);
                 }
 
                 if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) {
-                    edit.add_tabstop_after_token(cap, l_curly);
+                    let tabstop = edit.make_tabstop_after(cap);
+                    editor.add_annotation(l_curly, tabstop);
                 }
             }
 
-            insert_impl(impl_, &edit.make_mut(nominal));
+            insert_impl(&mut editor, &impl_, &nominal);
+            edit.add_file_edits(ctx.vfs_file_id(), editor);
         },
     )
 }