LSP Server
lash provides a Language Server Protocol implementation as a separate lash-lsp binary. It imports only lang/ and runtime/ — it does not connect to the backend daemon.
Namespace Model
Section titled “Namespace Model”lash uses a Lisp-2 namespace model, separating Scope into two maps:
vars— variable namespace (let/mutbindings)fns— function namespace (fndeclarations)
declareFn/lookupFn helpers walk the scope chain for the function namespace, parallel to declareVar/lookupVar for variables.
Semantic Analyzer
Section titled “Semantic Analyzer”Pre-execution AST validation, located in lang/semantic/, depends only on runtime/.
| Check | Description |
|---|---|
| Undeclared variable use | Reference not in any enclosing scope. |
| Undeclared function call | Not in function namespace and not a builtin. |
| Immutable assignment | Assignment targets let binding. |
| Redeclaration | let in same scope where name exists. |
| Drop undeclared | drop on name not in scope. |
| Break/continue outside loop | Not inside for/while. |
Integration points:
- Backend may call
analyze()on scripts before execution. - LSP uses
analyze()on partial ASTs for diagnostics. - Interactive mode skips analysis.
Tolerant Parser
Section titled “Tolerant Parser”Located at lang/parser/tolerant.d. Wraps the existing tokenizer with error recovery:
- On parse error: records diagnostic, skips to recovery point, continues.
- Returns: statements, diagnostics, tokens.
- Handles: incomplete expressions, unclosed braces, trailing dots, missing arguments.
Recovery points:
- Statement-level: next
;,}, or start-of-line keyword. - Expression-level: next
),],},,, or;.
LSP Capabilities
Section titled “LSP Capabilities”| Capability | Trigger |
|---|---|
textDocumentSync | Full document sync |
completionProvider | . and $ |
hoverProvider | — |
diagnosticProvider | Push on change |
definitionProvider | — |
Completion Sources
Section titled “Completion Sources”- Keywords:
let,mut,fn,if,for,while,match,break,continue,exit,true,false - Builtins:
cd,exit,jobs,fg,bg,z,set,session,audit,role - Scope variables and functions: from the current analysis context
- Type methods: based on inferred type of the expression before the
. - Environment variables: after
$
Hover Info
Section titled “Hover Info”- Variables: show type and mutability.
- Functions: show parameter list.
- Methods: show signature and description.
Document Lifecycle
Section titled “Document Lifecycle”didOpen— tokenize + tolerant parse + analyze — cache and publish diagnostics.didChange— re-parse + re-analyze — update and publish.didClose— remove from cache.