bazel-contrib / vscode-bazel

Bazel support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel
Apache License 2.0
244 stars 79 forks source link

VS Code Dependency Resolution for Java #281

Open mmatthews06 opened 2 years ago

mmatthews06 commented 2 years ago

I am able to build projects using this extension, but I have not been able to get VS Code to resolve external dependencies using anything that I can find in Bazel build artifacts, BUILD files or anything else. Is there a prescribed way to get VS Code to resolve import statements using anything in the Bazel ecosystem, and the VS Code Java extension pack?

Is there's a way to pull all JARs, I could probably add them as "Referenced Libraries" in the Java Projects extension, for example.

Basically, all of my external import statements are unresolved, and I'd like to know how to fix that. I could work on contributing code if this is something the extension could benefit from.

mmatthews06 commented 2 years ago

There's a StackOverflow question about this that has been open for over 2 years: https://stackoverflow.com/questions/62112254/finding-java-imports-invscode-with-bazel

I feel like there should be a "simple" 5-step process that could resolve this, if it's not something that's trivial to implement in this extension.

vorburger commented 1 year ago

This severly limits the usefulness of this extension for Java projects using Bazel... 😿

The topic is a bit more general than only "Dependency Resolution" (for Java import, and Syntax Completion) for the Language support for Java by Red Hat by automatically configuring Referenced Libraries in Classpath Configuration - it also includes setting the correct Sources folder/s, or Configure Java Runtime (instead of Type: Unmanaged folder) of the JDK version, etc.

I'm wondering how hard it would be to add the missing support. Not sure if belongs more into this project or the Java by Red Hat extension (which already has similar support for Maven & Gradle); but perhaps it could be on either side.

BTW https://bazel.build/install/ide#java recommends the https://github.com/georgewfraser/java-language-server#usage extension by @georgewfraser, which is an alternative Java LS for VSC to the Java by Red Hat one. (But I personally haven't tried it out, yet.)

@guw @AlexeiShmidman @LeonovecSergey how did you go about Bazel-VSC-Java integration in your (unreleased) https://github.com/salesforce/bazel-vscode?

@meteorcloudy @fweikert @jfirebaugh @sheldonneuberger-sc @dierksen @limdor FYI

guw commented 1 year ago

@vorburger https://github.com/salesforce/bazel-vscode is an extension the the RedHat Java Language Server. It uses parts of https://github.com/salesforce/bazel-eclipse (which uses aspects) to implement the classpath resolution. I'm working on a plan to get this into a releasable state in the next few months.

vorburger commented 1 year ago

haven't tried https://github.com/georgewfraser/java-language-server out

I meanwhile did, and ran into some problems.

Bazel-VSC-Java integration in your (unreleased) https://github.com/salesforce/bazel-vscode a releasable state in the next few months

ACK. I'm trying to locally build it right now, just to see if it's already "good enough" to use as-is.

I will try to make a few contribs to bazel-vscode and bazel-eclipse at least to be able to easily build it.

moehajj commented 1 year ago

haven't tried https://github.com/georgewfraser/java-language-server out

I meanwhile did, and ran into some problems.

I couldn't get that extension to work either.

Looks like there's been a issue open request Bazel support in the redhat extension since 2019 https://github.com/redhat-developer/vscode-java/issues/909

guw commented 1 year ago

@moehajj @vorburger I need some help updating our Bazel VSCode Java extension.

We have a Bazel VSCode Java Extension at https://github.com/salesforce/bazel-vscode-java. It adds Java support for Bazel projects to VS Code based on RedHat's Java extension.

The Bazel Language Server (and the Bazel Eclipse Feature) received a significant overhaul. This update needs to be brought into the VS Code extension. Any contributions are highly appreciated. The language server can be fetched from https://opensource.salesforce.com/bazel-eclipse/latest/

vorburger commented 1 year ago

@guw I don't have the bandwidth to actively contribute with code (unfortunately; I would love to, this sounds, but I just don't have time for this; sorry), but https://github.com/salesforce/bazel-vscode-java/issues/49 has new feedback as an end-user testing, which may be helpful.