metals icon indicating copy to clipboard operation
metals copied to clipboard

Case extractor hover and go to definition are wrong

Open nicolasstucki opened this issue 1 year ago • 4 comments

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 the object Foo
  • If we go to the definition of Foo we see the definition of the object 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

nicolasstucki avatar Aug 03 '23 08:08 nicolasstucki

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

tgodzik avatar Aug 03 '23 10:08 tgodzik

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.

jkciesluk avatar Aug 07 '23 10:08 jkciesluk

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

tgodzik avatar Aug 08 '23 12:08 tgodzik

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.

kasiaMarek avatar Apr 30 '24 14:04 kasiaMarek