Skip to content
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

[java] Inconsistent results of goto def depending on the code style #6357

Open
ghostbuster91 opened this issue Apr 26, 2024 · 0 comments
Open
Labels
improvement Not a bug or a feature, but something general we can improve java support Java support related tickets

Comments

@ghostbuster91
Copy link
Collaborator

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

@tgodzik tgodzik added improvement Not a bug or a feature, but something general we can improve java support Java support related tickets labels Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Not a bug or a feature, but something general we can improve java support Java support related tickets
Projects
None yet
Development

No branches or pull requests

2 participants