This is an experimental implementation of LSP based project intended to provide support for a DRL text editor.
It is composed of 2 parts: the server containing the actual LSP implementation and the client which is a VSCode extension consuming the services provided by the server.
The server is a plain Java/Maven project. Executing a mvn clean package in its folder will generate a jar file that will be automatically linked and consumed by the client when executed as a VSCode extension.
The server part is composed of three modules:
- drools-parser - responsible for actual drl-syntax parsing, eventually invoking a JAVA-LSP engine to read the
RHScontent (that is plain Java code); The antlr4 grammar files are taken from the latest drools. - drools-completion - used to provide completion suggestion using the C3 engine; it depends on
com.vmware.antlr4-c3:antlr4-c3and ondrools-parser - drools-lsp-server - the "gateway" between the client and the parsing/completion logic; by itself it should not implement any business logic, but should be concerned only with communication; it depends directly on
drools-completion
VSCode Usage
- Download the latest release of
vscode-extension-drl-editor-<version>.vsixfrom here - Install the extension in VSCode by selecting
Extensions(Ctrl+Shift+X) and then...(top-right corner) andInstall from VSIX...to install the downloaded file - Open a
.drlfile and start editing
Precompiled-server - no debug
- package server side code with
mvn clean package - goto
clientdirectory - issue
npm install - issue
code .to start VSCode in that directory - inside VSCode, select
Run and Debug(Ctrl+Shift+D) and then startRun Extension - a new
Extension Development Hostwindow will appear, withdrlextension enabled - to "debug" server-side event, add
server.getClient().showMessage(new MessageParams(MessageType.Info, {text}));in server-side code
Connected remote server - debug
- package server side code with
mvn clean package - start server with
DroolsLspTCPLauncherfrom IDE on debug mode; this will start the LSP-server listening on port9925 - goto
clientdirectory - issue
npm install - issue
code .to start VSCode in that directory - inside VSCode, select
Run and Debug(Ctrl+Shift+D) and then startDebug Extension - the extensions will establish a connection to the server running at port
9925 - a new
Extension Development Hostwindow will appear, withdrlextension enabled - to "debug" server-side event, add breakpoints in server-side code
Neovim Usage
Neovim has built-in LSP support, however client configuration is a manual process. It can be made a lot easier, though, if you leverage some of the many plugins available to do the hard parts for you, as you will see in the example below. Please note:
- Neovim will connect to the drools-lsp-server directly, bypassing the VSCode client extension.
- You are required to have a java runtime environment installed on your system, either with the
JAVA_HOMEenvironment variable set, or with thejavacommand locatable in yourPATH. - The example below only shows the relevant portions of one's nvim
init.luafile, assuming user familiarity with Neovim configuration (including working with plugins and keymappings, among other things).
Example Configuration
- Use packer.nvim (plugin installer) to install nvim-lspconfig (standard Neovim LSP configurations), mason.nvim (an excellent LSP/DAP/Linter/Formatter package manager), and mason-lspconfig.nvim (the
mason.nvimtonvim-lspconfigbridge):
use 'wbthomason/packer.nvim'
use {
'neovim/nvim-lspconfig',
requires = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
},
}- Get
masonup-and-running:
require('mason').setup {}
require('mason-lspconfig').setup {}- Initialize the
drools-lspserver (configuration options here):
require('lspconfig').drools_lsp.setup {
-- configuration options can be put here
-- when using mason, nothing is required!
}- Add automatic filetype detection of DRL files (necessary to trigger the language server startup):
vim.cmd[[ autocmd BufRead,BufNewFile *.drl set filetype=drools ]]- Startup
nvimanew, havepackerinstall the plugins, havemasoninstall the language server, and start editing DRL!
:PackerSync
:MasonInstall drools-lsp
:edit your.drl