Skip to content

feat: Allow “Extract variable” to be invoked on field names in record expressions. - #23213

Open
kpreid wants to merge 1 commit into
rust-lang:masterfrom
kpreid:extract
Open

feat: Allow “Extract variable” to be invoked on field names in record expressions.#23213
kpreid wants to merge 1 commit into
rust-lang:masterfrom
kpreid:extract

Conversation

@kpreid

@kpreid kpreid commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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 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 test dont_extract_in_pattern are 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.

… 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.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 21, 2026
// expression.
let kind = node.kind();
ast::Expr::can_cast(kind) || kind == SyntaxKind::RECORD_EXPR_FIELD
})

@A4-Tacks A4-Tacks Aug 23, 2026

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.

Why add this? I noticed without this, dont_extract_in_pattern would still pass through
Try not to break

View changes since the review

)
}

/// Selecting an entire field of a record expression will extract that field’s value expression.

@A4-Tacks A4-Tacks Aug 23, 2026

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.

Redundant (doc)comments

View changes since the review

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