Lemma LSP
Language Server Protocol implementation for Lemma. Provides inline diagnostics and editor features for .lemma files.
Features
- Diagnostics — Parse and planning (semantic) errors are published as you type. Parse errors are shown immediately; a debounced (250ms) full workspace validation adds planning errors. Errors use source spans where available; diagnostics are cleared when a file is closed.
- Workspace validation — On native, when the client provides a workspace root, the server scans for
.lemmafiles under that root at startup (skips hidden directories only) and runs full planning so cross-spec errors (missing spec/type refs, circular dependencies, etc.) are reported per file. The client keeps the server in sync via file open/change/close. On WASM, only the open file is validated (no filesystem). - Registry links —
@-prefixed Registry references (e.g.spec @user/workspace/somespec,type ... from @iso/countries/alpha2) are turned into clickable links when the Registry (LemmaBase) provides a URL. Works even when the file has parse errors (text-based scan). - Registry hover — Hovering on a registry
usesreference (qualifier or spec name) shows a popup with exactly two navigation entries: a hover-markdown link to the LemmaBase page for the repository, and theDocumentLinkCtrl+Click hint to the locally fetched bundle under<workspace>/lemma_deps/<qualifier>.lemmaat the resolvedspec ...line. - Embedded stdlib navigation —
uses lemma units(and any other reservedrepo lemmaimport) becomes a clickable link to a view-only snapshot at<workspace>/lemma_deps/lemma.std. The file is written lazily the first timedocument_linkruns on a spec that imports it, and is excluded from every.lemmadiscovery pass because of its.stdextension. The repository qualifier link opens the file; the spec name link opens it at thespec ...line. The VS Code extension registers thelemma.stdfilename so the snapshot still gets full Lemma syntax highlighting. - Text document sync — Full file sync on open, change, and close; no incremental sync.
The server uses the Lemma engine with registry support (LemmaBase) for resolving @... identifiers and communicates over stdio (native) or browser streams (WASM).
Build
From the repository root:
The LSP runs as lemma lsp (stdio).
The crate also supports a WASM build for in-browser use; the library entry point is lsp::browser::serve. The Lemma WASM playground does not use the LSP for diagnostics; it uses the engine’s getDiagnostics API directly for inline errors.
Usage
Run the server over stdio:
- VS Code / Cursor — Use the extension under editors/vscode. It runs
lemma lspautomatically and looks fortarget/release/lemmawhen the workspace root is the Lemma repo, or uses thelemma.lspServerPathsetting. Format-on-save and diagnostics only work when the LSP is running; see editors/vscode/README.md if format on save does nothing. - Other editors — Point your editor’s LSP client at
lemmawith argumentlspand stdio transport.
Layout
src/— LSP server (tower-lsp): server, diagnostics, registry links, workspace model, registry integration.editors/— Editor-specific clients and config (e.g. VS Code extension); see editors/README.md.