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

[CodeAction] Add missing cases to a match statement #350

Closed
ghostbuster91 opened this issue Jul 14, 2023 · 2 comments
Closed

[CodeAction] Add missing cases to a match statement #350

ghostbuster91 opened this issue Jul 14, 2023 · 2 comments

Comments

@ghostbuster91
Copy link

ghostbuster91 commented Jul 14, 2023

Is your feature request related to a problem? Please describe.

Let's imagine that we have a following match statement over some ADT:

enum Tree{
  case Int
  case String
}

//... 

tree match {
  case Tree.Int => println(1)
  case Tree.String => println(2)
}

We then modify ADT by adding two more cases - Double and Float.
Now, the compiler warns/emits error (depending on the project settings) that the match might not be exhaustive.

Describe the solution you'd like

I would like to have a code action that can be invoked on the mentioned match statement, that, when accepted, would add missing cases with ??? as implementation.

tree match {
  case Tree.Int => println(1)
  case Tree.String => println(2)
  case Tree.Double => ???
  case Tree.Float =>  ???
}

Describe alternatives you've considered

Write each missing case taking advantage from completions.

Additional context

No response

Search terms

code-action match case

@ckipp01
Copy link
Member

ckipp01 commented Jul 14, 2023

Since your example is using Scala 3 I'll add in that as of this pr these types of quick fixes can actually come right from the compiler. So in theory you could make a feature request there as well, and then anything using the newer versions of the compiler irregardless of client/Metals/IntelliJ would benefit from it.

dwijnand added a commit to scala/scala3 that referenced this issue Aug 9, 2023
The purpose of this PR is to add an actionable item for non-exhaustive
pattern match diagnostic, so that people can auto insert missing cases.

Relates to
scalameta/metals-feature-requests#350
@ghostbuster91
Copy link
Author

Done via scala/scala3#18314

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

No branches or pull requests

2 participants