Skip to content

Better Type Hints for Enum Structs/Tuples #2947

Closed
@sanbox-irl

Description

@sanbox-irl

Hello!

This is relatively small, but it might not be something the RA can do yet.

If I have an enum like this:

pub enum PlayerInputType {
    Start,
    PlayStaffCard(String),
    PickIssue(String),
    BooleanDecision(bool),
    PickPlayer(PlayerName),
    StubbedAction,
    Inaction,
    AdvanceAnIssue {
        issue_name: String,
        staff_card_name: String,
    },

Rust-analyzer can be a little strange with autocompletion here for the non-tuple variant (AdvanceAnIssue).

Here is what autocompletion/help looks like for PlayStaffCard:
image

That's very clear. I know that i should, after hitting tab, type a ( and then a String, like in the type inlay.

Here's the struct variant on the other hand:
image

It shows something similar, representing its data as a tuple! That's fine from a memory standpoint, but it means:

  1. I can't trust any tuple autocomplete anymore, since they might be a struct, so I'll have to click in and check
  2. I can't know which struct enum variants there are, so I'll need to go to reference for them as well.

I'm not sure what a better enum variant hint here would look like, but i suspect merely changing the type hint to just {String, String} as opposed to (String, String) would be good enough. Perhaps a real:

    AdvanceAnIssue {
        issue_name: String,
        staff_card_name: String,
    }

popping up would be the best long term solution, along with perhaps an assist in making all the fields if desired, but just the small change would be good enough I think.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions