Conversation
|
Sorry for being nitpicky, but can you add some spaces next to the braces? It bugs me a little. |
No problem - it's done. |
| let struct_data = db.struct_data(def.into()); | ||
| if struct_data.variant_data.is_unit() { | ||
| return type_for_adt(db, def.into()); // Unit struct | ||
| match struct_data.variant_data.kind() { |
There was a problem hiding this comment.
this could be an if let or if ... == StructKind::Unit
There was a problem hiding this comment.
Just changed it. Out of curiosity - what makes if let preferable? Just that it's more concise? I would think it a lot of situations match without a default is better because you'll get a compiler error if a new variant is added which forces you to explicitly decide how to handle the new variant. Of course, that doesn't really apply here because StructKind isn't likely to change.
There was a problem hiding this comment.
I think in this case, as you said, StructKind isn't likely to change, and we just want to handle the unit case as a special case here.
| let var_data = &enum_data.variants[def.local_id].variant_data; | ||
| if var_data.is_unit() { | ||
| return type_for_adt(db, def.parent.into()); // Unit variant | ||
| match var_data.kind() { |
|
bors r=flodiebold Thanks @adamrk ! |
3169: Show record field names in Enum completion r=flodiebold a=adamrk Adresses #2947. Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record:  This change will show the names of the fields for a record and use curly braces instead of parentheses:  This required exposing the type `adt::StructKind` from `ra_hir` and adding a function ``` kind(self, db: &impl HirDatabase) -> StructKind ``` in the `impl` of `EnumVariant`. There was also a previously existing function `is_unit(self, db: &impl HirDatabase) -> bool` for `EnumVariant` which I removed because it seemed redundant after adding `kind`. Co-authored-by: adamrk <ark.email@gmail.com>
Build succeeded
|
|
wow, thanks man! thanks for noticing my issue :) |
Adresses #2947.

Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record:
This change will show the names of the fields for a record and use curly braces instead of parentheses:

This required exposing the type
adt::StructKindfromra_hirand adding a functionin the
implofEnumVariant.There was also a previously existing function
is_unit(self, db: &impl HirDatabase) -> boolforEnumVariantwhich I removed because it seemed redundant after addingkind.