Skip to content

Migrate three assists to SyntaxEditor editing#21833

Open
Sangria-hbm wants to merge 2 commits intorust-lang:masterfrom
Sangria-hbm:feat/tracka-syntaxeditor-3-assists
Open

Migrate three assists to SyntaxEditor editing#21833
Sangria-hbm wants to merge 2 commits intorust-lang:masterfrom
Sangria-hbm:feat/tracka-syntaxeditor-3-assists

Conversation

@Sangria-hbm
Copy link

@Sangria-hbm Sangria-hbm commented Mar 17, 2026

Summary

This PR migrates three ide-assists handlers away from mutable-tree editing patterns (ted::*, builder.make_mut, builder.make_syntax_mut) toward SyntaxEditor/SyntaxFactory-based edits.

Affected handlers:

  • extract_struct_from_enum_variant
  • extract_type_alias
  • generate_fn_type_alias

Motivation

This is part of the ongoing migration tracked in #18285 (and related architecture goal in #15710): reducing mutable syntax editing usage so we can continue moving toward cleaner immutable editing internals.

What Changed

extract_struct_from_enum_variant

  • Reworked edit flow to use SyntaxEditor and SyntaxFactory mappings.
  • Removed mutable-tree paths (ted::*, builder.make_mut, builder.make_syntax_mut) from this handler.
  • Migrated import insertion to insert_use_with_editor.
  • Preserved behavior around comment/attribute carry-over and visibility propagation.
  • Added regression test: extract_fix_references_with_turbofish.

extract_type_alias

  • Switched alias/type replacement construction to SyntaxFactory::with_mappings + edit.add_mappings(...).
  • Fixed duplicated generic-parameter emission when a selected type repeats the same generic (e.g. (T, T)).
  • Added regression test: dedup_repeated_generic_params.

generate_fn_type_alias

  • Migrated alias construction/insertion to SyntaxFactory + mapped SyntaxEditor edits.
  • Fixed impl-generic + self rendering for unnamed-params alias generation.
  • Added regression test: generate_fn_alias_unnamed_impl_generics_on_self.

Testing

Executed in the rust-analyzer workspace:

cargo test -p ide-assists -- handlers::extract_type_alias::tests handlers::generate_fn_type_alias::tests handlers::extract_struct_from_enum_variant::tests
cargo fmt -- --check

Result:

  • 68 passed; 0 failed

Notes

  • This PR is intentionally scoped to three handlers to keep review surface manageable.
  • No new assist was added; this is a migration + correctness fix set.

AI Disclosure

AI tooling was used during drafting/iteration, and all code/tests in this PR were manually reviewed and verified locally.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 17, 2026
@Sangria-hbm
Copy link
Author

All CI checks on this PR are now passing. When you have time, could you please take a look and review? Thanks!

AstNode,
ast::{self, HasGenericParams, HasName, edit::IndentLevel, syntax_factory::SyntaxFactory},
ast::{
self, HasGenericParams, HasName, edit::IndentLevel, make, syntax_factory::SyntaxFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SyntaxFactory instead of make. If a required method isn’t available, add it to SyntaxFactory.

Suggested change
self, HasGenericParams, HasName, edit::IndentLevel, make, syntax_factory::SyntaxFactory,
self, HasGenericParams, HasName, edit::IndentLevel, syntax_factory::SyntaxFactory,

use syntax::{
ast::{
self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel,
self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel, make,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove make

Suggested change
self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel, make,
self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel,

Comment on lines +73 to +74
// Record references in the definition file so it can be edited once together
// with variant and struct-definition updates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly don't change unrelated stuff

@Sangria-hbm
Copy link
Author

Thanks for the review — I pushed follow-up commit a1a61172ae to address your comments.

Changes made:

  • removed make imports in extract_type_alias and generate_fn_type_alias
  • switched the whitespace insertions back to factory.whitespace(...) in both files
  • reverted the unrelated comment wording change in extract_struct_from_enum_variant
  • replaced remaining constructor calls in generate_fn_type_alias with SyntaxFactory methods

Could you please take another look when convenient? Thank you!

@Sangria-hbm Sangria-hbm requested a review from Shourya742 March 18, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants