basex-lsp/README.md
2025-08-24 22:54:14 +01:00

65 lines
2.8 KiB
Markdown

Work in progress.
An attempt to write a [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol) server for and in XQuery 4.0. It uses the [BaseX websocket](https://docs.basex.org/main/WebSockets) feature.
# Demo
1. Requires `Docker` or `Podman` on the local machine.
2. Clone this repo
3. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port)
4. 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](https://www.jsonrpc.org/specification) 2.0 API for data format.
## Sample html clients
A couple of 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](https://caniuse.com/?search=popovertarget)
### Using `CodeMirror6` https://codemirror.net/
* `webapp/static/codemirror` A test html page using the [CodeMirror6 editor](https://codemirror.net/) that connects to the BaseX LSP instance
#### uses
* https://codemirror.net/docs/ref/#lsp-client
#### alternatives
* https://github.com/FurqanSoftware/codemirror-languageserver
* https://hjr265.me/blog/codemirror-lsp/
### Using `Ace Editor`
* `webapp/static/ace` A test html page using the [Ace editor](https://ace.c9.io/) that connects to the BaseX LSP instance
@TODO fix
#### Uses
* https://github.com/mkslanc/ace-linters https://mkslanc.github.io/ace-linters/
Make a websocket server for lsp on port 3000
https://mkslanc.github.io/ace-linters/websocket.html
http://localhost:3000/exampleServer
https://github.com/mkslanc/ace-linters/blob/c1b317e01299016ac7da6588361228637f4eac25/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
@TODO create
https://socket.dev/npm/package/monaco-editor
### Server dev notes
State is held in [websocket attributes](https://docs.basex.org/main/WebSocket_Functions#websocket_attributes).
|Name|Use|
|----|---|
|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 with textDocument|
|parse-{uuid}|name of websocket attribute with parse tree XML|
## Related links
java -cp org.eclipse.lemminx-uber.jar org.eclipse.lemminx.XMLServerSocketLauncher`