Skip to content

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.

lash uses a Lisp-2 namespace model, separating Scope into two maps:

  • vars — variable namespace (let/mut bindings)
  • fns — function namespace (fn declarations)

declareFn/lookupFn helpers walk the scope chain for the function namespace, parallel to declareVar/lookupVar for variables.

Pre-execution AST validation, located in lang/semantic/, depends only on runtime/.

CheckDescription
Undeclared variable useReference not in any enclosing scope.
Undeclared function callNot in function namespace and not a builtin.
Immutable assignmentAssignment targets let binding.
Redeclarationlet in same scope where name exists.
Drop undeclareddrop on name not in scope.
Break/continue outside loopNot 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.

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 ;.
CapabilityTrigger
textDocumentSyncFull document sync
completionProvider. and $
hoverProvider
diagnosticProviderPush on change
definitionProvider
  • 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 $
  • Variables: show type and mutability.
  • Functions: show parameter list.
  • Methods: show signature and description.
  1. didOpen — tokenize + tolerant parse + analyze — cache and publish diagnostics.
  2. didChange — re-parse + re-analyze — update and publish.
  3. didClose — remove from cache.