scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

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

Closed ghostbuster91 closed 1 year ago

ghostbuster91 commented 1 year ago

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 commented 1 year ago

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.

ghostbuster91 commented 1 year ago

Done via https://github.com/lampepfl/dotty/pull/18314