-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect goto definition for overloaded apply
in another file
#4769
Comments
In SemanticDB the synthetic
The indexing in ScalaMtags is compatible with Scala 2, thus we see THIS BUG in Scala 3. I created a workaround in the linked PR for Scala 3 dialects, so the indexing is compatible with SemanticDB. However, this is insufficient and won't work for projects that use both Scala 2 and Scala 3. We need an upstream-fix of the SementicDB inconsistency. |
I can take a look at the SemanticDB part in Scala3 👍, but I don't have time this month, and going to check in March. |
I will take a look :) |
It looks like the problem is that Metals is looking for an apply symbol with the wrong disambiguator In Scala3. // Main.scala
object Main extends App {
List(1.toString).map(Foo.apply)
}
// Foo.scala
case class Foo(a: Int)
object Foo {
def apply(a: String): Foo = Foo(a.toInt)
} In this case, we should jump from In this setting, Scala3 generate the following SemanticDB, and it generates correct symbol (and occurrences) with right disambiguator. metals/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala Lines 262 to 276 in 784494b
outdatedThe wired thing is, when we have // Main.scala
object Main extends App {
List(1).map(Foo.apply)
}
I'll keep taking a look |
Ah, ok so the problem is indeed metals/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala Line 467 in 784494b
Indeed the mtags indexer seems the culprit 👀 Now, I think I'm on the same page as @kasiaMarek |
What we should do is making the disambiguator compatible with mtags indexer and SemanticDB as @kasiaMarek tried to do in #4914 But, is it possible? Is disambiguators are determined syntactically? (otherwise, it's not possible to align mtags indexer and SemanticDB generated by compiler because former is based on parser, and latter knows the all semantic information). https://scalameta.org/docs/semanticdb/specification.html#symbol-1
So, if we follow the specification, we should fix the SemanticDB plugin for Scala2, instead of Scala3. Of course, we should make sure Scala3 compiler, mtags indexers for all dialects properly follow the specifications around disambiguator. |
I think it's not clear for synthetic applies, since it doesn't appear in the code at all. We should make that more clear in the definition and it might be easier to change the Scala 3 compiler instead since the Scala 2 behaviour might be usedalready in a number of places. |
Works with |
Describe the bug
This might be a result of the fix for #4255 and also might be a duplicate of #4484, but in the following scenario:
When you trigger a goto definition on the explicit
apply
inMain.scala
it brings you to thecase class Foo
instead of the overloadedapply
definition inobject Foo
Expected behavior
In this scenario I'd expect it to bring you to
def apply
inobject Foo
.NOTE that if they are in the same file, it works as expected. It's only a problem when they are in a different file.
Operating system
macOS
Editor/Extension
Nvim (nvim-metals)
Version of Metals
0.11.9+234-2d64131d-SNAPSHOT
Extra context or search terms
No response
The text was updated successfully, but these errors were encountered: