java-language-server icon indicating copy to clipboard operation
java-language-server copied to clipboard

Make Bazel integration more fault tolerant with `--keep_going`

Open Silic0nS0ldier opened this issue 8 months ago • 0 comments

Currently the Bazel integration is fragile, requiring a full successful aquery pass. This means LSP results are significantly diminished in some common scenarios such as;

  • No network access with an incomplete cache (repo fetch failures).
  • Build configuration errors ("no such target", "no such package", "no matching toolchains").
  • Invalid target state (select(...) no match errors).
  • Missing pre-requisities (fail(...) in repo rules).

Adding --keep_going (and attempting to process output irrespective of the exit code) should greatly improve LSP capabilities when the latter errors (and any others not mentioned) occur.

https://github.com/georgewfraser/java-language-server/blob/ca503f1728594af4b77d68de0c04fd81d9dc10d1/src/main/java/org/javacs/InferConfig.java#L367-L373

Request Context

I am currently using the VSCode extension distribution of this language server to aid Bazel development. The core Java completion is working well (much better than https://github.com/salesforce/bazel-vscode-java) however many imports fail to resolve.

For reference, here are some samples of the errors running aquery against the Bazel repo.

Python repo failing to fetch as current user is root (default in a dev container).

ERROR: An error occurred during the fetch of repository 'rules_python~~python~python_3_8_x86_64-unknown-linux-gnu':
   Traceback (most recent call last):
        File "/root/.cache/bazel/_bazel_root/af358cfbcc0478b6bbe6e5ca9711bb0d/external/rules_python~/python/repositories.bzl", line 199, column 25, in _python_repository_impl
                fail("The current user is root, please run as non-root when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.")
Error in fail: The current user is root, please run as non-root when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.

Missing targets, usually this points to a build configuration error however in the case of the Bazel source I believe this is due to unique build requirements.

ERROR: /workspaces/bazel/tools/BUILD:75:10: no such target '//tools/android:bzl_srcs': target 'bzl_srcs' not declared in package 'tools/android' defined by /workspaces/bazel/tools/android/BUILD and referenced by '//tools:bzl_srcs'

Missing packages, similar reasoning to the latter.

ERROR: /workspaces/bazel/src/tools/one_version/BUILD:52:11: no such package 'third_party/bazel/src/tools/one_version': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /workspaces/bazel/third_party/bazel/src/tools/one_version and referenced by '//src/tools/one_version:one_version'

Android SDK is not installed on the host.

ERROR: /workspaces/bazel/src/test/shell/bazel/android/BUILD:191:16: configurable attribute "data" in //src/test/shell/bazel/android:resource_processing_integration_test_with_head_android_tools doesn't match this configuration: This test requires an android SDK, and one isn't present. Make sure to uncomment the android rules in the WORKSPACE.bzlmod.

This instance of //src/test/shell/bazel/android:resource_processing_integration_test_with_head_android_tools has configuration identifier 2ffb6a1. To inspect its configuration, run: bazel config 2ffb6a1.

For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.

Silic0nS0ldier avatar Jun 15 '24 07:06 Silic0nS0ldier