scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.04k stars 319 forks source link

Case extractor hover and go to definition are wrong #5508

Open nicolasstucki opened 11 months ago

nicolasstucki commented 11 months ago

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`

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

tgodzik commented 11 months ago

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

jkciesluk commented 11 months ago

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.

tgodzik commented 11 months ago

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

kasiaMarek commented 2 months ago

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.