-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
Description
Starting from the code
struct Foo {
x: &'static str,
y: &'static str,
}
fn foo() -> Foo {
Foo {
x: "abcdef",
y: "ghi",
}
}it is currently possible to transform foo() into
fn foo() -> Foo {
let x = "abcdef";
let y = "ghi";
Foo { x, y }
}by putting the cursor on each of the two field values and invoking the “Extract into variable” assist twice. I think it would be useful to offer this same transformation in a way which
- does not require the cursor to be placed exactly on the value expression (I frequently try to invoke it starting from the field name, before remembering that that doesn’t work), and
- is able to operate on multiple struct fields at once.
In particular, I propose that it should be possible to extract multiple field value expressions into correspondingly named variables when the cursor is
- in the struct name, in which case it should act on all fields,
- in a single field name, or
- a selection of multiple fields within the struct literal, in which case it should act on all fields whose names or value expressions are within the selection.
In these cases, the rename prompt should possibly be skipped, since it is likely that the user wants the variable(s) to be named the same as the field(s).
@rustbot label +A-assists
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackNo fields configured for issues without a type.