rune-langium / lsp-server/src / createRuneLspServer
Function: createRuneLspServer()
ts
function createRuneLspServer(): RuneLspServer;Defined in: packages/lsp-server/src/rune-dsl-server.ts:122
Create a fully-wired Rune DSL LSP server backed by @lspeasy/server.
Returns
A RuneLspServer ready for listen(transport).
Remarks
Initialization order (all synchronous before returning):
LSPServercreated with broad capability declarationscreateConnectionAdapter()wraps it to satisfy Langium'sConnectioninterface- Langium LSP services constructed (
createDefaultSharedModule+ Rune DSL modules) RuneDslValidatorchecks registeredstartLanguageServer(shared)wires all providers to connection handlers
The server responds to initialize requests only once per lifecycle — the connection adapter manages the Created → Initializing → Initialized state machine to avoid duplicate initialization errors.
Use When
- Embedding a Rune DSL language server in a web application via WebSocket
- Running a standalone LSP server process bridging to a VS Code / Theia client
- Integration-testing LSP features (hover, completion, diagnostics)
Avoid When
- Parsing
.rosettafiles in a script — usecreateRuneDslServices()andparse()/parseWorkspace()instead (no LSP overhead). - Creating multiple servers in the same process — each server maintains its own Langium workspace index; sharing a workspace across servers requires custom
ServiceRegistrywiring.
Pitfalls
- The workspace index is empty until the client sends
textDocument/didOpenorworkspace/didChangeWatchedFiles. Do NOT respond to semantic requests (hover, completion) before at least onedidOpenhas triggered a document build — results will be empty or stale. - Diagnostics are push-only (
textDocument/publishDiagnosticsnotifications). There is no request-response path for diagnostics — the client must handle the notification asynchronously. - Langium batches diagnostic notifications; a burst of
didChangeevents may not produce one notification per change. The final stable state is always published but intermediate states may be coalesced.
Example
ts
import { createRuneLspServer } from '@rune-langium/lsp-server';
import { WebSocketTransport } from '@lspeasy/core';
const lsp = createRuneLspServer();
const transport = new WebSocketTransport(webSocket);
await lsp.listen(transport);