Code action to convert between struct types
struct S {} // Convert into unit struct
struct S; // Convert into normal struct
struct S { field: String }; // Convert into tuple struct
struct S(String); // Convert into normal struct
struct S(String, u64); // Convert into normal struct
struct S {
field_1: String, // These can be renamed easily later on
field_2: u64
}
I think that this would aid in refactoring in a big way, especially for tuple -> named structs.
It's a pain to fix them manually.
We already have named <-> tuple struct conversions
We already have this assist. Note that you need to place the cursor on the name of the struct to activate it. It would be better to expand the trigger area to allow more people to discover this feature.
See
https://github.com/rust-lang/rust-analyzer/blob/6fce68edb5078ef717256ec1df346050939a7bd0/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs#L52
and
https://github.com/rust-lang/rust-analyzer/blob/6fce68edb5078ef717256ec1df346050939a7bd0/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs#L50
I'm not sure we want to expand the area. I agree we have a discoverability problem with assists, but expanding its range will mean it more often gets in the way of people that want to invoke something else.
For me, it would be very intuitive to extend the range to the entire definition, or at least we could extend the range to struct kw, { and (?
I'd expect this assist to trigger from the struct/visibility token up to the end of the name. The entire definition is way too annoying. Stuff that affects the entire definition of something imo should be triggerable only on the "signature" of the thing.
@rustbot claim