-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Migrate reorder_fields
Assist to Use SyntaxFactory
#18495
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
davidbarsky
merged 1 commit into
rust-lang:master
from
tareknaser:syntax_factory_reorder_fields
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to eliminate this
clone_for_update
usingSyntaxFactory
. It looks like we will need to add constructors forrecord_expr_field
andrecord_pat_field
. For now, I would inline thisreplace
function so you don't need to worry about how to abstract it over the two cases. We can try to clean it up afterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined the
editor.replace()
calls, but theclone_for_update()
calls are still needed. Removing them causes the assist to fail tests with an ‘immutable tree’ errorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we do still need a mutable node, but my understanding is that we want to hide this under
SyntaxFactory
so it is abstracted away and so that we track the mappings, hence my suggestion of adding those constructors. That said, in these cases where we do just want to clone, those constructors might not be very convenient to use. @DropDemBits can you check my understanding here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@darichey Generally we'd like to hide the details of creating new nodes under
SyntaxFactory
. In this case though, we're picking nodes from the original syntax tree so we wouldn't need to go through aSyntaxFactory
.SyntaxEditor
should handle transform any node in an edit that reference the original syntax tree into their mutable equivalents, but seems like I forgot this case for the new nodes in replace edits 😅. For now it should be okay to useclone_for_update
and add a fixme, and then we can remove those fixmes onceSyntaxEditor
is fixed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thank you! Sorry about that, @tareknaser, you can revert inlining
replace
and just add a FIXME for the clone_for_update :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All set 5c41c20