language server protocol
Find a file
2025-10-06 10:49:43 +01:00
.vscode [mod] lsp-typedefs 2025-09-15 22:38:45 +01:00
bundles [mod] settings apply 2025-10-05 16:18:40 +01:00
data [fix] size linewrap 2025-08-05 23:02:56 +01:00
docs [add] railroad generation 2025-10-03 15:27:41 +01:00
scripts [add] railroad generation 2025-10-03 15:27:41 +01:00
test [mod] clean up tree walk 2025-10-04 16:34:02 +01:00
webapp [fix] list selection 2025-10-06 10:49:43 +01:00
.dockerignore [mod] merge lsp-web-poc 2025-07-11 15:16:28 +01:00
.gitignore [fix] #14 2025-09-13 12:44:22 +01:00
compose.yaml [mod] exclude dba logs 2025-09-11 18:33:40 +01:00
LICENSE [mod] samples 2025-08-01 23:14:52 +01:00
package-lock.json [mod] symbols install minimap 2025-09-22 15:26:45 +01:00
package.json [add] railroad generation 2025-10-03 15:27:41 +01:00
README.md [add] railroad generation 2025-10-03 15:27:41 +01:00
rollup.config.js [mod] additions 2025-07-31 15:02:27 +01:00

Work in progress.

An attempt to write a Language Server Protocol server for and in XQuery 4.0. It tracks the draft specifications at https://qt4cg.org/ It written for BaseX 12.0 and uses the BaseX websocket feature.

Demo

The demos expect Docker or Podman on the local machine. This is only a requirement for the demos.

1 Clone this repo 2. Run docker compose up -d The LSP server shall now running on port 3000 (edit compose.yaml to change port) 3. In a browser navigate to http://localhost:3000/static/clients/codemirror/ to see the CodeMirror 6 demo.

In principle, the LSP can be used in any environment that can make use of a LSP server accessed via a websocket.

LSP Server

  • webapp/lsp The LSP implementation in XQuery using WebSockets for transport and the JSON-RPC 2.0 API for data format.

Sample html clients

Samples using common browser based code editors are available. The CodeMirror 6 sample is the most functional.

These examples are self contained (no internet access required). Some make use of recent html features, for instance popovertarget

CodeMirror6 https://codemirror.net/

  • webapp/static/codemirror A test html page using the CodeMirror6 editor that connects to the BaseX LSP instance

uses

alternative LSP interfaces

Ace Editor

  • webapp/static/ace A test html page using the Ace editor that connects to the BaseX LSP instance @TODO fix

Uses

Make a websocket server for lsp on port 3000 https://mkslanc.github.io/ace-linters/websocket.html

http://localhost:3000/exampleServer

c1b317e012/packages/demo/websockets-lsp/server/server.ts I needed set NODE_OPTIONS=--max_old_space_size=8192 for build to complete

Or node --max-old-space-size=8192 node_modules/webpack-dev-serve r/bin/webpack-dev-server.js

Monaco editor

@TODO create https://socket.dev/npm/package/monaco-editor

Server dev notes

State is held in websocket attributes.

Name Use
client the client initialize message
initialized set true after client sends initialized message
files A map whose keys are open uris, values are maps (doctype-> attribute name where doctype is stored
file-{uuid} name of websocket attribute containing the textDocument
parse-{uuid} name of websocket attribute containing parse tree XML
sequenceDiagram
    WS->>lsp-ws: message
    lsp-ws->>rpc: reply
    rpc->>+John: John, can you hear me?
   

XQuery 4.0 parser

The ebnf is taken from Gunther Rademacher's rex-parser-generator XQuery-40.ebnf

The script scripts/rex.xq can generate XQuery or Java parser code from this. The npm package.json script javac can create a jar file from the Java source.

java -cp org.eclipse.lemminx-uber.jar org.eclipse.lemminx.XMLServerSocketLauncher`