scalameta / metals

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

"go to definition" on an apply method call should show `apply` as one of the definitions #4484

Open kubukoz opened 2 years ago

kubukoz commented 2 years ago

Describe the bug

In an "implicit" call to an apply method, if the method isn't synthetic, it should be shown as one of the definitions. Currently "go to definition" moves you to the companion object instead of the actual method.

To reproduce:

  1. Create a Scala file with
//> using scala "2.13.8"
class A(a: Int)
object A {
  def apply(s: String): Int = ???
}

object B {
  A("a")
}
  1. Go to definition on the call to A inside object B
  2. Cursor is now at object A<here>

Expected behavior

Not sure if it should be an addition or a replacement, but it should surely be one of the options: the apply method should be one of the targets of "go to definition".

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

v0.11.8

Extra context or search terms

No response

tgodzik commented 2 years ago

Thanks for reporting! This looks related to https://github.com/scalameta/metals/issues/4255 and probably can be fixed in a similar manner.

kubukoz commented 2 years ago

Oh, maybe it's already fixed then. Let me try a snapshot...

kubukoz commented 2 years ago

It works in 0.11.8+203-5b1c34ca-SNAPSHOT:

image

Both apply and the object it's being called on are shown (even if apply comes from a third-party trait) - I'm satisfied :)

kubukoz commented 2 years ago

thanks @tgodzik for the link!

tgodzik commented 2 years ago

That's cool! These are the best issues :sweat_smile:

kubukoz commented 1 year ago

hmm I think this doesn't actually work on Scala 3.

tgodzik commented 1 year ago

hmm I think this doesn't actually work on Scala 3.

We might not have the synthetics for that. :thinking: