metals
metals copied to clipboard
Case extractor hover and go to definition are wrong
Describe the bug
object Foo:
def unapply(x: Int): Option[Int] = ???
def test =
1 match
case Foo(n) => // hover on `Foo` or go to the definition of `Foo`
- If we hover on
Foo
we see the definition of theobject Foo
- If we go to the definition of
Foo
we see the definition of theobject Foo
Expected behavior
We should see the definition of Foo.unapply
and go to that definition.
Operating system
macOS
Editor/Extension
VS Code
Version of Metals
v1.23.0
Extra context or search terms
No response
Thanks for reporting! Looks like we haven't made it work for unapplies in Scala 3 yet.
Btw. this can now also be fixed inside the compiler repository as we move that part of code to dotty. We will fix it in Metals for older versions and port to dotty. Once we stop publishing for some older versions it will only be done on dotty
Btw. this can now also be fixed inside the compiler repository as we move that part of code to dotty. We will fix it in Metals for older versions and port to dotty. Once we stop publishing for some older versions it will only be done on dotty
I think this is not the case, because we are not using presentation compiler here. It would be used if there was no definitions found, but we find definition of object Foo
. It works in Scala 2, because Foo.unapply
is a synthetic occurrence in semanticdb (DefinitionProvider.synthethicApplyOccurence
), but it's not there in Scala 3.
So it seems for hover this is expected and is working as with Scala 2. Should we even show unapply in that case? This qualifies more as a feature request to discuss.
The go to definition is blocked on https://github.com/lampepfl/dotty/issues/13135
As @tgodzik wrote, go to definition is blocked on https://github.com/scala/scala3/issues/13135. When it comes to hover, it's probably up for discussion what should be shown here, but this is what the interactive compiler returns so this would also require an upstream fix in Scala 3 compiler. Just as a side note, for Scala 2 hover also shows the object
not the unapply
.