Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement exhaustive switch completion #699

Merged
merged 2 commits into from
Jan 16, 2023
Merged

Conversation

zth
Copy link
Collaborator

@zth zth commented Jan 15, 2023

This is a proposal to solve #253.
It's also the first step of #684, moving snippets into the analysis bin and only outputting them where they make sense.

exhaustive-switch
(this GIF isn't 100% accurate, I've done some cosmetic fixes to the completion list since recording it)

This PR does the following: When completing..

  • an ident after a switch
  • and the switch has no cases
  • and the type of the ident we're completing is something we can (reasonably) generate an exhaustive switch for
  • ...add a separate completion item for the ident that, when chosen, inserts an exhaustive switch statement for that ident

Closes #253

@zth zth requested a review from cristianoc January 15, 2023 21:23
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition is pretty powerful.
Thoughts about the case where one already has a switch, with a catch-all | _ => and wants to complete the missing cases in place of _?

@zth
Copy link
Collaborator Author

zth commented Jan 16, 2023

I think that'd be a good addition. Perhaps a code action? Let's think a bit on it.

It's also related to filtering out "seen patterns" in pattern completion, which I'm going to tackle soon. As in | Some(true) | None = Some(false) is missing, rest is seen.

@zth zth merged commit 02a2c53 into master Jan 16, 2023
@zth zth deleted the exhaustive-switch-completion branch January 16, 2023 17:27
@amiralies
Copy link
Contributor

Nice job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exhaustive pattern matching for variants and poly variants.
3 participants