Skip to content

Running the lightweight syntax language server

Jinbo Wang edited this page Apr 1, 2020 · 5 revisions

Running the lightweight syntax language server

Background

When opening a Java folder, the standard language server first needs to parse the project files and download dependencies, then index the classes and build the workspace, finally provide the language features such as IntelliSense, refactoring and javadoc. Mostly, the import process probably takes several minutes to be ready, that will slow down the responsiveness of the language server. The goal of the lightweight syntax language server is to simplify the import process so that the server can quickly provide some basic features. The syntax server will ignore third-party dependencies (e.g. maven or gradle) and disable the indexer and builder jobs to speed up the startup process. Besides it won't load the bundles from the third-party extensions such as Java Test Runner, Java Debugger, Java Dependencies View. It only adds your sources and JDK to the classpath, providing outline, javadoc, and navigation between your sources and JDK.

Starting the syntax language server

The syntax language server shares the same bits as the standard language server. Its workflow is almost same as the standard Java LS. The only different is using different flag to control the launch mode.

Below are the key points.

  • Build the server bits via maven command.
    ./mvnw clean package
    
  • cd into the build directory of the project: /org.eclipse.jdt.ls.product/target/repository
  • Start the server from command line.
    • Choose a connection type from "Managing connection types" section below.

    • [Important] Use environment variable syntaxserver=true or system property -Dsyntaxserver=true in vmArgs to enable the syntax server.

    • Run the syntax server with the command line.

      java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1045 -Dsyntaxserver=true -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Dlog.protocol=true -Dlog.level=ALL -noverify -Xmx1G -jar ./plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar -configuration ./config_ss_linux -data /path/to/data
      

      When running with JDK9, you need to start the server with some extra parameters:

      java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1045 -Dsyntaxserver=true -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Dlog.protocol=true -Dlog.level=ALL -noverify -Xmx1G -jar ./plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar -configuration ./config_ss_linux -data /path/to/data --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED
      
    • [Important] Choosing a value for -configuration: this is the path to your platform's configuration directory. For linux, use ./config_ss_linux. For windows, use ./config_ss_win. For mac/OS X, use ./config_ss_mac.

    • Choosing a value for -data: the value for your data directory, should be the directory where your active workspace is, and you wish for the java langserver to add in its default files. Should also be the absolute path to this directory, ie., /home/username/workspace

    • Notes about debugging: the -agentlib: is for connecting a java debugger agent to the process, and if you wish to debug the server from the start of execution, set suspend=y so that the JVM will wait for your debugger prior to starting the server

Managing connection types

The Java Language server supports sockets and standard streams of the server process to communicate with the client. Client can communicate its preferred connection methods by setting up environment variables.

  • To use a plain socket, set the following environment variables before starting the server:

    • CLIENT_PORT: the port of the socket to connect to
    • CLIENT_HOST: the host name to connect to. If not set, defaults to localhost.

    The connection will be used for in and output.

  • To use standard streams(stdin, stdout) of the server process do not set any of the above environment variables and the server will fall back to standard streams.

For socket, the client is expected to create the connections and wait for the server to connect.

Make the syntax LS working with the standard LS

The client is responsible for starting the server processes, managing the lifecycle of each server.

  • Start the syntax LS and standard LS in two separated JVMs. The syntax server will provide the syntax features before the importing job of the standard server is finished.
  • Shutdown the syntax server when the standard server is fully ready. This can be implemented through listening on the notification "ServiceReady" at the language client connected to the standard server.