Skip to content

Migrate pull_assignment_up assist to useSyntaxEditor #20198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025

Conversation

Hmikihiro
Copy link
Contributor

part of #15710 and #18285

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 8, 2025
ted::replace(tgt.syntax(), assign_stmt.syntax().clone_for_update());
let new_tgt_root = editor.finish().new_root().clone();
let new_target_range = TextRange::new(target.start(), new_target_end);
let new_tgt = find_node_at_range::<ast::Expr>(&new_tgt_root, new_target_range).unwrap();
Copy link
Member

@ShoyuVanilla ShoyuVanilla Jul 8, 2025

Choose a reason for hiding this comment

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

I think we can simplify this with find_node_at_offset with the offset target.start() - because we trigger this assist only on if and match exprs and due to those tokens, there won't be any other child expr with the same offsets - and then we won't need new_target_range calculation

Copy link
Member

@ShoyuVanilla ShoyuVanilla Jul 8, 2025

Choose a reason for hiding this comment

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

And we can avoid this unwrap() if we "pull up" this first half of twin-editor things outside of the closure - we can use SyntaxEditor::new without edit - though I don't think that's quite necessary 😅

Copy link
Contributor Author

@Hmikihiro Hmikihiro Jul 8, 2025

Choose a reason for hiding this comment

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

And we can avoid this unwrap() if we "pull up" this first half of twin-editor things outside of the closure - we
can use SyntaxEditor::new without edit - though I don't think that's quite necessary 😅

Hmikihiro#4
I tried refactoring as suggested, though I’m not sure if the result is much cleaner overall.

Copy link
Member

@ShoyuVanilla ShoyuVanilla Jul 8, 2025

Choose a reason for hiding this comment

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

I suggested avoiding unwrap() because unwrap makes people a little bit nervous, not because it would be much cleaner 😅 Anyway, I think both are good and it's up to your choice 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I choice to avoid unwrap()

@Hmikihiro Hmikihiro force-pushed the migrate_pull_asignment_up branch from 1b4bfba to 11fc5da Compare July 8, 2025 15:27
Copy link
Member

@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
@Hmikihiro Hmikihiro force-pushed the migrate_pull_asignment_up branch from 11fc5da to c6ce2ab Compare July 8, 2025 15:59
@ShoyuVanilla
Copy link
Member

Oh, I have merge permission now

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Jul 9, 2025
Merged via the queue into rust-lang:master with commit 66e248c Jul 9, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2025
@Hmikihiro Hmikihiro deleted the migrate_pull_asignment_up branch July 22, 2025 05:02
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.

3 participants