Skip to content

Migrate assists to SyntaxEditor #18285

Open
@darichey

Description

@darichey

We want to migrate all assists to use the new SyntaxEditor/SyntaxFactory abstraction. This will unblock moving to immutable syntax trees (#15710). In doing so, we can choose a flat, contiguous representation that should yield significant performance wins (#17491).

@DropDemBits has outlined the process for migrating most assists:

  • Create a SyntaxFactory, optionally named make to ease migration
  • Create a SyntaxEditor using builder.make_editor with a node from the file
  • Replace all make:: with make
    • Add any missing methods to syntax::ast::syntax_factory::constructors as needed
  • Replace all ted:: with editor.
  • After all changes are complete:
    • editor.add_mappings(make.finish_with_mappings()) to add the generated mappings
    • builder.add_file_edits(ctx.file_id(), editor) to add the edits
      For assists that use snippets, check the snippet capability, and then use editor.add_annotation to associate the snippets with the elements.

They have also already migrated the extract_variable assist in #18196 which should be a useful reference.

The assists are located in crates/ide-assists/src/handlers. They should all have tests which you can use to verify that your change works properly by running:

cargo test --package ide-assists -- handlers::<ASSIST>::tests  

replacing <ASSIST> with the assist name, e.g., add_braces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions