Getting Started with LSP in Eclipse Orion
Eclipse Orion is made up of two different parts: a client portion that runs inside a browser and a server. There are two separate implementations of the Orion server - one written in Java and the other one written in Node.js. For the Language Server Protocol (LSP) work, we used the Node.js server.
The integration of LSP inside Orion focused on getting support for the Java Language inside the Orion editor. The Eclipse JDT Language Server (a.k.a. jdt.ls) is implementing a language server for the Java language based on the well-known JDT projects.
How to get started
To get the latest Orion LSP code, do the following steps:
git clone https://github.com/eclipse/orion.client git checkout java-lsp cd orion.client
All steps to contribute and get started are explained in the file called
There is also a docker file inside orion.client/modules/orionnode/. This can be used to create Docker image that contains the latest build for the Eclipse jdt.ls and the latest Orion node.js build that contains the lsp support. To start building the image run:
Once the build finishes, you can then start the image:
docker run -p 8083:8083 orionlsp
You can connect to it by opening a browser on
We will now examine the changes made to the Orion server and the Orion client in order to enable support for the Java language inside the Orion editor.
The chosen architecture
Before we start, we should explain how we got Orion to interact with the language server.
The LSP server and the Node.js server are both running on the same machine right now. The LSP server is installed locally in the Node.js server inside a folder called ‘server’. The purpose of this is to get one LSP server running for each Node.js server. At the moment, the LSP server cannot be shared between two Orion servers.
The Orion server
On the Orion server side, there is not much to do to get the language server communication going. We defined an extension that we register in the server code (see line 100 in server.js). That extension starts listening on a named socket that is used to start and initialize the LSP server.
The Orion client
The Language Server Protocol defines a lot of requests that can be made to a LSP server: document life cycle (open/close/change files), code formatting, hover, occurrences, search references, code completions, etc. Click here for more details.
The current implementation supports most of them. Once the server is started and initialized on your workspace contents, the user can format code, get problems and warnings, search for references, get Javadoc hovers, get errors/warnings as you type, etc.
Right now, there is no support for code actions. So, there are no quick fixes available for the reported error and warnings in the Orion editor.
The editor integration is done using an Orion plugin. The plugin defines a named socket that is used to fire up the language server. The plugin is registered to be initialized on files with the following content types: "text/x-java-source" or "application/x-jsp". These two content types are registered in the Orion plugin for files with extensions ‘.java’ and ‘.jsp’. So, when the plugin is started and initialized, it triggers the connection for the named socket and sends the ‘start’ event. This event initializes the LSP server and enables the two sockets for bidirectional communication between the LSP server and the Orion client. The Orion plugin is also used to register the syntax highlighting for the Java language by using Orion stylers.
where mJava and mJSP are defined as:
Each feature of the Orion editor like content assist, occurrences, etc. has been updated to check whether a LSP server is registered and needs to be handled.
For example, for the formatter, in the file called
org.eclipse.orion.client.ui/web/orion/formatter.js, we check whether there is a LSP server registered for the current file content type. To do that, we register all LSP servers inside a registry that is used to speed up the lookup for LSP server based on a specific content type. If we find one, we use it by invoking the corresponding handler from the protocol. In this case, it would be either a document formatting request or a document range formatting request depending on if there is a current selection inside the editor.
We invoke this by doing:
We use the same principle to implement all Orion editor features (occurrences, search references, etc.) that could take advantage of the LSP server features.
We still need to add support for the code action request defined in the LSP to be able to add quick fixes inside the Orion editor.
Right now, the LSP server works fine on Maven and Gradle projects. This is still an area where things are moving fast. So, it is possible that more projects settings will be handled in the future.
We also need to see how we can leverage the support for the JavaTM language to other languages like what is done with the generic Eclipse editor.
Feel free to contribute to either the Orion integration or directly to the Eclipse Java LSP server implementation.
This is what you get once it is running: