eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

How does the goToDefinition work for a java gradle project? #1390

Open cheonhyangzhang opened 4 years ago

cheonhyangzhang commented 4 years ago

Hi folks, I am trying to setup vim + coc java workflow for my work project. The project is a large java gralde project. It has many sub modules. Folder structure is like

xxx-api/
  /build.gradle
  /settings.gradle
  /common
  /feed
  /groups
  /core

When I load vim and JDT language server is running, all classes are working fine except the classes defined inside of /core module. The /core module is a little special because it needs scala cross build. (Not very familiar what does this actually mean)

In the settings.gradle file, it shows

  scalaCrossBuild {
    defaultScalaVersion '2.11.11'
    targetScalaVersions '2.11.11'
    crossBuildEnabled true
    projectsToCrossBuild ':core'
  }
String[] modules = [
  "common",
  "feed",
  ...
  "core_2.11",
  ...
]
include modules

I feel like when gradle builds the module, it renames the /core module into /core_2.11. So I am guessing probably due to the path name mismatch somewhere in language server to cause language server not able to recognize any class in /core module.

I am looking into the java language server eclipse.jdt.ls code to understand where this mismatch could be but so far didn't find anywhere yet. Actually not very familiar with how eclipse.jdt.ls is working.

Could anyone help me with a direction where should I look at? I feel when typeDefinition in NavigateToTypeDefinitionHandler.java is called, it must look up somewhere. And this somewhere must be initialized with the location for every java class. I can't find where this initialization is.

fbricon commented 4 years ago

Normally, navigation across multimodule gradle-based Java projects is expected to work except for Android, which is not supported. Since Scala is not supported by jdt.ls, navigating to scala source is not expected to work though. We have no plans on providing scala support in core jdt.ls. However, if someone wanted to add that as an eclipse.jdt.ls extension, we could provide some help (I can't guarantee it's doable, nor that it'll be easy)