coc-java icon indicating copy to clipboard operation
coc-java copied to clipboard

[FEAT] Support Bazel

Open ddlees opened this issue 5 years ago • 10 comments

In polyglot monorepos it is a royal pain that I cannot have plugins like coc-java correctly set the classpath for the java language server since there is not a pom.xml or a gradle.build at the root of the project.

My team uses Bazel and there are a number of us that strictly use vim since there is so much context switching between languages. If possible, it would be fantastic to get first class support for Bazel.

Happy to contribute if you can provide some bootstrap pointers 😄

ddlees avatar Mar 04 '20 19:03 ddlees

Sorry, I don't have any experience with Bazel, looks like jdt.js should support that at first.

chemzqm avatar Mar 05 '20 02:03 chemzqm

I checked the jdt.ls github page and they do have an issue open, however, it looks like the Bazel core team has been able to create plugins for eclipse and intellij that also leverage the jdt.ls. I have to imagine we could do the same with this lovely extension 😉

I opened a request against vim-classpath to do something similar which coc-java could leverage or piggyback on. Normally I would just give up and just do all my Java coding (...ew) in IntelliJ but I actually have time to try and do something about this for the coc community. Let me know what I can do.

ddlees avatar Mar 06 '20 15:03 ddlees

I think the likely path forwards would be to have a coc-bazel that wraps the WIP Bazel language server: https://github.com/bazelbuild/vscode-bazel

gibfahn avatar Jan 29 '21 18:01 gibfahn

I think salesforce did most of the leg work here

https://github.com/salesforce/bazel-vscode

GregBowyer avatar Sep 17 '21 01:09 GregBowyer

So with incredible hacking I might have something that is starting to work

  1. Build that vscode project
  2. Extract the archive and take the two jars
  3. Put those jars in the jdt home where all the jars are
  4. Include the jars in the config_linux bit as classpath files
  5. Change https://github.com/neoclide/coc-java/blob/master/package.json to allow java.import.bazel.enabled

2021-09-16-193445_1752x804_scrot

There is still a lot that is broken but a bunch of things started working for me

GregBowyer avatar Sep 17 '21 02:09 GregBowyer

Hi all,

Wanted to being this back up since support for Bazel has been built into eclipse.jdt.ls eclipse/eclipse.jdt.ls#543

Is this something that can be done now?

igbanam avatar Sep 01 '22 10:09 igbanam

My team uses bazel too and this would be super helpful for me. Thanks!

adarsh-murthy avatar May 04 '23 02:05 adarsh-murthy

Hey @adarsh-murthy …and friends 🙂

Bazel is now supported. I have confirmed this from OpenJDK 17 (minimum) to the current OpenJDK 20. You can test this out as well with the project at bazelbuild/java-tutorial.

Bazel is highly configurable. So if you're using Bazel in an enterprise setting, there are most likely configurations which shift Bazel away from its vanilla setup. Nothing to worry though, you just have to learn how your company sets up Bazel and configure your setup to account for those. One recent example I solved is using java.project.referencedLibraries to inform coc.nvim about classes auto-generated from .proto schemas. There are many keys in the config which could solve your issue as well.

p.s: even if your company lags behind on the version of Java used for their products — which most enterprise companies do, by design — it's possible to have your Java version be closer to the bleeding edge for your LSP

igbanam avatar May 04 '23 07:05 igbanam

Thanks for the timely response. I see that coc-java works really well for the project you linked but it's not working for the project I have at work. I keep getting the error [coc.nvim] definition not found. It doesn't even go to definition for a variable that's defined in the same file. Here is the log:

2023-05-05T02:13:00.792 INFO (pid:2903414) [plugin] - coc.nvim initialized with node: v18.13.0 after ^[[33m207^[[39m
2023-05-05T02:13:04.427 INFO (pid:2903414) [services] - LanguageClient ciderlsp state change: stopped => starting
2023-05-05T02:13:04.660 INFO (pid:2903414) [language-client-index] - Language server "languageserver.ciderlsp" started with 2903610
2023-05-05T02:13:04.721 INFO (pid:2903414) [attach] - receive notification: highlight []
2023-05-05T02:13:05.663 INFO (pid:2903414) [services] - LanguageClient Language Support for Java state change: stopped => starting
2023-05-05T02:13:05.674 INFO (pid:2903414) [language-client-index] - Language server "java" started with 2903851
2023-05-05T02:13:05.701 INFO (pid:2903414) [attach] - receive notification: highlight []
2023-05-05T02:13:06.567 INFO (pid:2903414) [services] - LanguageClient ciderlsp state change: starting => running
2023-05-05T02:13:06.579 INFO (pid:2903414) [services] - service languageserver.ciderlsp started
2023-05-05T02:13:06.781 ERROR (pid:2903414) [provider-manager] - Provider error on provideDocumentLinks: Canceled: Canceled
      at Nd.handleFailedRequest (/.vim/plugged/coc.nvim/build/index.js:248:966)
      at /.vim/plugged/coc.nvim/build/index.js:239:19020
      at async /.vim/plugged/coc.nvim/build/index.js:215:27498
      at async Promise.allSettled (index 0)
      at async tf.provideDocumentLinks (/.vim/plugged/coc.nvim/build/index.js:215:27432)
      at async K1.getDocumentLinks (/.vim/plugged/coc.nvim/build/index.js:257:28420)
      at async gI.getLinks (/.vim/plugged/coc.nvim/build/index.js:269:4960)
2023-05-05T02:13:06.982 INFO (pid:2903414) [attach] - receive notification: highlight []

adarsh-murthy avatar May 05 '23 02:05 adarsh-murthy

I couldn't find ciderlsp anywhere mainstream. From what I read, it's a Clojure LSP. Checkout coc-clojure — I don't see coc-java in the logs; and it may not work for Clojure projects.

igbanam avatar May 10 '23 14:05 igbanam