Skip to content

Silic0nS0ldier/java-language-server

 
 

Repository files navigation

Java+Bazel Language Support

Find it on the VSCode Marketplace

See ./extension/vsix/README.md for more details.

Building

For development builds

bazel build //extension/vsix:java_bazel_language_support --stamp

For release

  1. Increment version in extension/vsix/package.json
  2. bazel build //extension/vsix:java_bazel_language_support

Design

The Java language server uses the Java compiler API to implement language features like linting, autocomplete, and smart navigation, and the language server protocol to communicate with text editors like VSCode.

Incremental updates

The Java compiler API provides incremental compilation at the level of files: you can create a long-lived instance of the Java compiler, and as the user edits, you only need to recompile files that have changed. The Java language server optimizes this further by focusing compilation on the region of interest by erasing irrelevant code. For example, suppose we want to provide autocomplete after print in the below code:

class Printer {
    void printFoo() {
        System.out.println("foo");
    }
    void printBar() {
        System.out.println("bar");
    }
    void main() {
        print // Autocomplete here
    }
}

None of the code inside printFoo() and printBar() is relevant to autocompleting print. Before servicing the autocomplete request, the Java language server erases the contents of these methods:

class Printer {
    void printFoo() {

    }
    void printBar() {

    }
    void main() {
        print // Autocomplete here
    }
}

For most requests, the vast majority of code can be erased, dramatically speeding up compilation.

Logs

The java service process will output a log file to stderr, which is visible in VSCode using View / Output, under "Java".

Contributing

To build locally you will need;

  • Bazelisk
  • JDK v21 (limitation of @rules_jvm_external//:extensions.bzl#maven.install)
  • pnpm v9

There requirements are all met by the included devcontainer.

About

Java language server using the Java compiler API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 92.7%
  • TypeScript 3.8%
  • Starlark 2.9%
  • Other 0.6%