Skip to content

Migrate three assists to SyntaxEditor editing#21833

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

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

Conversation

@Sangria-hbm
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread crates/ide-assists/src/handlers/generate_fn_type_alias.rs Outdated
Comment thread crates/ide-assists/src/handlers/extract_type_alias.rs Outdated
@Sangria-hbm
Copy link
Copy Markdown
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
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Generally please open separate PRs for each assist. Now that you've already opened a PR, I'll ignore that.

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Review for extract_type_alias.rs.

View changes since this review

let make = SyntaxFactory::without_mappings();

let resolved_ty = make.ty(&resolved_ty);
let factory = SyntaxFactory::with_mappings();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We generally call it make, it's nice to be consistent.


// Replace original type with the alias
let ty_args = generic_params.as_ref().map(|it| it.to_generic_args().generic_args());
let ty_args = generic_params.as_ref().map(|it| it.to_generic_args());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method uses editing without SyntaxFactory, when migrating we need to get rid of it. You may need to replicate it yourself in crates/syntax/src/syntax_editor/edits.rs.

ast::GenericParam::LifetimeParam(_) => 0,
ast::GenericParam::TypeParam(_) => 1,
});
let mut seen = FxHashSet::default();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please do not mix between bug fixes and migrations. This is worse than multiple migrations in one PR. Split this into a different PR.

@Sangria-hbm Sangria-hbm force-pushed the feat/tracka-syntaxeditor-3-assists branch from e783477 to a1a6117 Compare March 23, 2026 03:09
@Sangria-hbm
Copy link
Copy Markdown
Author

Thanks for the detailed review. I’ve now completed both follow-up items and pushed the updates.

1) Requested review changes (extract_type_alias)

I addressed the requested extract_type_alias follow-up changes (including the test-related portion) in:

  • 1da68ca062Address review feedback in extract_type_alias

2) Additional CI failure fix (generate_fn_type_alias)

While validating CI, I also found and fixed an additional non-flaky failure in the merged PR context:

  • Panic path: SyntaxFactory::ty_fn_ptr (constructors.rs, param_list().unwrap())
  • Affected area: generate_fn_type_alias

Fix commit:

  • 30286aa021Avoid ty_fn_ptr mapping panic in generate_fn_type_alias

Validation

To reduce review burden, I re-ran relevant tests locally after both commits:

  • handlers::extract_type_alias::tests
  • handlers::generate_fn_type_alias::tests
  • cargo test -p ide-assists --tests

So this branch now contains:

  • the requested review updates for extract_type_alias, and
  • the CI panic fix for generate_fn_type_alias with regression verification.

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Are you just forwarding my responses to AI? Are you actually reviewing its output? I don't want to talk to a LLM, I want to talk to a human that can understand (just as an example - other assists still don't call it make). Please respect maintainer time.

@Sangria-hbm
Copy link
Copy Markdown
Author

I’m very sorry for the confusion and the mechanical tone of my previous replies.

My English is limited, so I did use an LLM to polish my wording. Also, when I discussed the implementation with the LLM, it suggested that I should only modify the specific lines you pointed out to avoid unnecessary changes in other areas. I see now that this was a mistake and led to the inconsistencies you mentioned.

To make sure I’m on the right track now: are you expecting me to do a full pass over all files in this PR and clean up all similar instances of the issues you’ve raised, rather than just the specific lines with comments?

I will handle this manually from now on to ensure I actually understand the context. Thanks for your patience.

@Sangria-hbm Sangria-hbm force-pushed the feat/tracka-syntaxeditor-3-assists branch from c27063b to 8add94c Compare March 23, 2026 08:43
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

ChayimFriedman2 commented Mar 23, 2026

To make sure I’m on the right track now: are you expecting me to do a full pass over all files in this PR and clean up all similar instances of the issues you’ve raised, rather than just the specific lines with comments?

That is what I would prefer. I can't force you to that, since like me, you're a volunteer here, but:

  • This will definitely make the review rounds, and eventually the approval, quicker
  • As a non-routine contributor I review more PRs than you write them, therefore I have less time for each while you have more time for yours
  • Honestly, a one-time contribution is a net negative for the project. The time to review it is more than the time it would take for me to author it. We accept it for the ethos of open source, and for the hope of some of the contributors becoming permanent - but the goodness you do to me is less than the goodness I do to you.

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Review for generate_fn_type_alias.rs: file was already ported, no changes actually needed. Looks like the LLM thought it needs to change things for some reason :)

View changes since this review

Some(())
}

fn build_fn_ptr_type(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Already exists as SyntaxFactory::ty_fn_ptr().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated as requested.

I've switched the manual function-pointer construction in generate_fn_type_alias to use the existing SyntaxFactory::ty_fn_ptr and dropped the redundant helper.

I also did another pass over the diff to check for other spots where I might have used manual construction instead of the factory's high-level APIs, but I didn't find any other similar issues. Please let me know if I missed anything else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also said to revert the changes in generate_fn_type_alias.rs. Instead you changed it more in meaningless changes.

I have the feeling that you're using AI agents to implement my requested changes without directing them or actually verifying they do what they need to do. If that is the case, please note we require careful human review of LLM output. This is also very disrespectful for maintainers, and does not help to gain trust.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am very sorry, I completely misunderstood your feedback. I’ve been using an LLM to assist with the code, but I do review the changes. In this case, a semantic misunderstanding on my part led the LLM (and me) in the wrong direction.

I thought you were saying that since a high-level API already exists, I should refactor the file to use it instead of manual construction. I didn't realize you meant generate_fn_type_alias.rs was already correct as-is and needed to be reverted entirely.

I’m sorry for acting too hastily without fully grasping your comments—I realize this wasted your valuable time. I have now fully reverted generate_fn_type_alias.rs to its original state.

@Sangria-hbm Sangria-hbm force-pushed the feat/tracka-syntaxeditor-3-assists branch from c86f74e to 39c5847 Compare March 23, 2026 11:43
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

I'm closing this for unreviewed usage of AI tools and responding using AI. In the next time, please respect maintainers' time and use AI only according to our guidelines.

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

I’m very sorry for this. I realize now that my over-reliance on AI and lack of careful manual review caused a lot of unnecessary work for you. I truly apologize for disrespecting your time.

I will take this as a serious lesson to improve my own understanding of the project and will strictly follow the AI guidelines in the future. Thank you for the feedback and for your patience thus far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants