The CLS LSP server (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
clx lsp) implements the Language Server Protocol over standard JSON-RPC, providing real-time feedback as you write .clsx files. On every document open or change it runs the full Lexer → Parser → NameResolver → TypeChecker pipeline and publishes syntax errors and type diagnostics as underlined squiggles in the editor. Beyond diagnostics it offers completions for keywords, core intrinsics, standard library modules, and every symbol in scope, plus hover documentation drawn from type maps, go-to-definition for functions and variables, and a document symbol list for quick navigation.
Starting the Server
- stdin/stdout mode is the only transport currently implemented. The server reads JSON-RPC messages from stdin and writes responses to stdout. This is the standard transport used by VS Code and most LSP clients.
--silent/-ssuppresses the startup message ([clx lsp] ready) so that the log output does not interfere with clients that parse stdout.
lsp subcommand in nodos/clx/src/subcommands/lsp.rs, which calls crate::lsp::run_server(silent).
LSP Capabilities
The server announces the following capabilities during theinitialize handshake:
textDocument/definition and textDocument/documentSymbol request handlers. LSP clients that send these requests will receive valid responses, even though the capabilities are not explicitly advertised in the initialize result.
Diagnostics
On everytextDocument/didOpen and textDocument/didChange event the server runs:
- Lexer — tokenizes the document; a lex error produces an immediate error diagnostic.
- Parser — builds the AST; a parse error produces an error diagnostic with the source location.
- NameResolver — verifies that every identifier is declared before use; name errors become error diagnostics.
- TypeChecker — validates type assignments, resolves generics, and checks function call arities; type errors and warnings are published with
ERRORorWARNINGseverity.
cls.json (if present). When no manifest exists, the server defaults to check: true, strict: false.
Completions
Triggered by any character or explicitly by the., ", and / trigger characters.
General completions (no trigger character):
| Source | Kind |
|---|---|
| Functions and variables in the current document | Function / Variable |
| Symbols from other open documents | Function / Variable |
CLS keywords (var, function, if, for, return, …) | Keyword |
Core intrinsics from core.clsi (print, input, len, …) | Function |
| Standard library module names (math, json, fs, http, Lib, async) | Module |
.clsx filenames found in the workspace | File |
.):
When you type math. or obj., the server inspects the identifier before the dot, resolves it through the import map of the current file, and returns the members of the matching type module or struct. Member sources in priority order:
- Type definitions loaded from
.clsi/.type.jsonfiles (matched by import alias) - Runtime module exports (
math,json,fs,http) - Struct fields declared in the current document
Hover Documentation
OntextDocument/hover the server extracts the word under the cursor, searches the loaded type definitions, and renders a Markdown snippet:
- \name type — description`), return documentation (→ …`), and deprecation notices (Go-to-Definition
OntextDocument/definition the server parses the current document, finds the symbol under the cursor in the built symbol table (functions, variables, and parameters at the top-level scope), and returns the source location as a Location pointing to the declaration span.
Document Symbols
OntextDocument/documentSymbol (bound to Ctrl+Shift+O in VS Code) the server returns a flat list of all top-level functions, variables, and parameters with their kind and source range. This powers the Go to Symbol quick picker.
VS Code Integration
The extension connects toclx lsp automatically when lspServer is enabled in .vscode/settings.json:
client/extension.js) launches clx lsp as a child process using the stdin/stdout transport provided by vscode-languageclient ^10.1.0.
The LSP server loads type definitions from the embedded builtin
.clsi files (always available) and optionally from a clsi/ directory at the workspace root (workspace override). Run clx maptype . --watch alongside the LSP server so that .type.json files for your own source files stay up to date. The server reads these via type_defs::load_all_type_definitions during the initialize handshake.Type Definitions
On startup the server callstype_defs::load_all_type_definitions(workspace_root), which:
- Loads the seven builtin
.clsidefinitions embedded in theclxbinary:core— intrinsics (print,input,len,type,now,exit,sleep,throw, …)math— math modulejson— JSON modulefs— filesystem modulehttp— HTTP moduleLib— compiled library loaderasync— async module
- Scans
<workspace_root>/clsi/*.clsiand merges any workspace-provided definitions, allowing projects to override or extend the builtins.
HashMap<String, TypeModule> is shared across all document handlers for the lifetime of the server session.
Error Reporting
Diagnostics carry precise source locations derived from theSpan type (start_line, start_col, end_line, end_col, all 1-indexed). The server converts these to 0-indexed LSP Position values before publishing. When a raw error string contains a line:col pattern (from ClsError::extract_line_col), the server parses it to produce a point-range diagnostic even for errors that do not carry a structured span.