redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 440 forks source link

vscode-java reports "cannot be resolved" errors in Gradle plugin project with mix of Groovy and Java #1417

Open a01fe opened 4 years ago

a01fe commented 4 years ago

In Gradle plugins implemented with a mix of Java and Groovy, vscode-java reports "cannot be resolved" errors in .java files that reference classes defined in .groovy files. Gradle can compile and build the plugin successfully.

Environment
Steps To Reproduce
  1. Clone https://github.com/a01fe/gradle-groovy-java-plugin
  2. cd gradle-groovy-java-plugin/test; ./gradlew javaTask This builds the plugin and runs a task in the plugin to verify it compiles and builds successfully
  3. Open the project in vscode and open src/main/groovy/foo/task/JavaTask.java, vscode-java reports errors on all the references to JavaTaskSpec.
fbricon commented 4 years ago

Unfortunately, it's a known limitation of the JDT compiler. It only knows about Java classes, not from other languages. Getting a working groovy support would require loading the Groovy Eclipse plugin and its patched JDT compiler instead of JDT, in the Java Language server. It might or might not be doable, but this is definitely a task that will require some contributions from the community. cc @martinlippert, in case he's interested.

fbricon commented 4 years ago

I realized this has already been discussed with @martinlippert in #205

martinlippert commented 4 years ago

Yepp, discussed back then and I don't think anything has really changed since then. However, feel free to get in contact with the people working on groovy-eclipse (https://github.com/groovy/groovy-eclipse) to further discuss this with them (I think @eric-milles is the one).

eric-milles commented 4 years ago

Joint compilation for Groovy and Java for LSP has been discussed. Also, there may be Groovy LSP implementations already, but I am unsure about their support for joint compilation (inter-dependency) of Groovy and Java sources.

a01fe commented 4 years ago

Thanks for your comments! After reading through the linked issues it appears that separate Groovy and Java language servers would be the cleanest way to go. The downside is that crossed Groovy/Java references likely wouldn't work. Is this because language servers would need to know the others contributions to classpath and the there's no established protocol for them to share this?

martinlippert commented 4 years ago

@a01fe I think it depends on the structure of your project. If you have one-way references only (always from Java to Groovy code or vice versa), you should be able to set this up with separate language servers. But having real cross-references in both directions, you would need a compiler that can compile both, I think.

tekleayele commented 3 years ago

Has there been any updates since the last convo on this issue/blocker ?

AaaCabbage commented 2 years ago

I have the same problem. So, Has there been any updates?

GKilm commented 2 months ago

Hope this issue to be attention.😊