Open
Description
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 namedmake
to ease migration- Create a
SyntaxEditor
usingbuilder.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::
witheditor.
- After all changes are complete:
editor.add_mappings(make.finish_with_mappings())
to add the generated mappingsbuilder.add_file_edits(ctx.file_id(), editor)
to add the edits
For assists that use snippets, check the snippet capability, and then useeditor.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
Labels
No labels