feat: Allow “Extract variable” to be invoked on field names in record expressions. - #23213
Open
kpreid wants to merge 1 commit into
Open
feat: Allow “Extract variable” to be invoked on field names in record expressions.#23213kpreid wants to merge 1 commit into
kpreid wants to merge 1 commit into
Conversation
… expressions.
This change allows a “mistake” I make very often to succeed: putting
the cursor on “foo” in `Struct { foo: bar() }` when I want to
extract `let foo = bar();`.
It is also groundwork for being able to extract multiple field
expressions at once.
A4-Tacks
reviewed
Aug 23, 2026
| // expression. | ||
| let kind = node.kind(); | ||
| ast::Expr::can_cast(kind) || kind == SyntaxKind::RECORD_EXPR_FIELD | ||
| }) |
Member
There was a problem hiding this comment.
Why add this? I noticed without this, dont_extract_in_pattern would still pass through
Try not to break
| ) | ||
| } | ||
|
|
||
| /// Selecting an entire field of a record expression will extract that field’s value expression. |
Member
There was a problem hiding this comment.
Redundant (doc)comments
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change allows a “mistake” I make very often to succeed: putting the cursor on “foo” in
Struct { foo: bar() }when I want to extractlet foo = bar();.It is also preparation for being able to extract multiple field expressions at once (#21863), because it generalizes the analysis of the selection to be able to work on nodes that are not themselves expressions.
Notes
The added
take_while()and the testdont_extract_in_patternare an attempt to preserve the behavior added in #18982, but that PR did not add any tests or clearly specify what effect it was intended to have, so I may have gotten it wrong.This is only my second contribution to assists, so all feedback is welcome.