[java] Inconsistent results of goto def depending on the code style
ghostbuster91 opened this issue · comments
Describe the bug
Given a following scala code:
package hello
class Foo {
def bar(): String = "bar"
}
object Foo {
def baz = "SSSS"
}
and the java code in the same module:
package com.example;
import hello.*;
import java.util.List;
public class Service {
void create(List<Object> args, Foo foo) {
System.out.println(foo.bar()); // 1
System.out.println(Foo$.MODULE$.baz()); // 2
System.out.println(Foo.baz()); // 3
}
}
Calling goto definiton on foo
and bar
in the // 1
case works for both of them.
Calling goto definition in the // 2
case works only on the method baz
. For Foo$
and MODULE$
nothing happens. I think that both of them could navigate to the Foo
object.
Calling goto definition in the // 3
case works for Foo
but for baz
it only works partially as editor navigates to the Foo
class definition.
Below I include snippets from calling goto def. on the baz
method from case 2 and 3.
For the 2nd case:
[Trace - 01:23:03 PM] Received request 'textDocument/definition - (435)'
Params: {
"textDocument": {
"uri": "file:///home/kghost/workspace/demos/moduleB/src/main/java/com/example/Service.java"
},
"position": {
"line": 10,
"character": 34
}
}
[Trace - 01:23:03 PM] Sending response 'textDocument/definition - (435)'. Processing request took 5ms
Result: [
{
"uri": "file:///home/kghost/workspace/demos/moduleB/src/main/scala/hello/Foo.scala",
"range": {
"start": {
"line": 8,
"character": 6
},
"end": {
"line": 8,
"character": 9
}
}
}
]
For the 3rd case:
[Trace - 01:21:03 PM] Received request 'textDocument/definition - (427)'
Params: {
"textDocument": {
"uri": "file:///home/kghost/workspace/demos/moduleB/src/main/java/com/example/Service.java"
},
"position": {
"line": 11,
"character": 31
}
}
[Trace - 01:21:03 PM] Sending response 'textDocument/definition - (427)'. Processing request took 3ms
Result: [
{
"uri": "file:///home/kghost/workspace/demos/moduleB/src/main/scala/hello/Foo.scala",
"range": {
"start": {
"line": 2,
"character": 6
},
"end": {
"line": 2,
"character": 9
}
}
}
]
Expected behavior
First, I would expect that calling goto def on method baz
should navigate to baz
method from Foo
object in both of the cases.
Second, it would be great if Foo$
and MODULE$
could also navigate to the Foo
object.
Operating system
Linux
Editor/Extension
Nvim (nvim-metals)
Version of Metals
1.3.0
Extra context or search terms
Project to reproduce: https://github.com/ghostbuster91/demos/tree/goto-def-java