Expand description
Editor language services for the Lemon DSL — pure, I/O-free, editor-agnostic.
This module turns the lexer + op catalog (the same single source of truth the parser and schema generator consume) into the three primitives every code editor needs:
diagnostics— parse/lex errors and the semantic lints fromcrate::lint(unusedlets; unknown series when a series list is given), as rangedDiagnostics. The linter is the single diagnostics source, so the editor squiggles matchlemon lintexactly.hover— the signature and description of the op / operator / series under the cursor, rendered as Markdown.completions— op names, keyword-argument names for the enclosing call,let-bound names in scope, known series, and keyword literals.
Everything here is a pure function of (source, position). The same core
backs both the WASM boundary (lemon-wasm, for the in-browser editor) and
the native language server (lemon-lsp, over tower-lsp), so hover text and
completions can never drift between the two surfaces.
§Positions
All positions are 1-based (line, col), matching crate::ParseError
and the lexer: col is the column of a character, and a cursor “after” the
last typed character sits at len + 1. Ranges are half-open — end_col is
one past the last covered column. Editors that speak 0-based positions (LSP)
convert at their boundary.
Structs§
- Completion
Item - One completion candidate.
insert_textis the text to insert (equal tolabelfor everything except keyword args, which insertname=). - Diagnostic
- A ranged diagnostic:
[ (line, col) .. (end_line, end_col) ), 1-based, withend_colexclusive. - Hover
Info - The hover card for the token under the cursor: a range to highlight plus the Markdown body.
- Semantic
Token - A classified source span,
[ (line, col) .. (end_line, end_col) ), 1-based withend_colexclusive — same convention asDiagnostic.
Enums§
- Completion
Kind - What a
CompletionItemrefers to — lets the editor pick an icon. - Severity
- Diagnostic severity. Parse/lex errors are
Severity::Error; semantic lints fromcrate::lintareSeverity::Warning. - Token
Type - A syntax-highlight classification for a run of source. This is the single
source of truth for lemon highlighting: every editor surface (the in-browser
CodeMirror playground,
citrus-fund, an LSP semantic-tokens provider) colours fromtokens, so highlighting can never drift from the lexer.
Constants§
- COMMON_
FUNDAMENTALS - A curated set of common fundamental series, offered as completions purely as a convenience. Not exhaustive and not authoritative — the engine’s data context is the source of truth.
- PRICE_
SERIES - Input series the engine always provides from price data. Fundamentals are open-ended (any identifier is accepted), so this list drives completion only.
Functions§
- completions
- Completion candidates for the cursor at 1-based
(line, col). - diagnostics
- Compute diagnostics for
src: the (single) parse or lex error if the source is invalid, otherwise the semantic lints fromcrate::lintas ranged warnings. - hover
- Markdown hover for the token at 1-based
(line, col), orNonewhen there is nothing documented there (whitespace, punctuation, numbers, unknown series). - tokens
- Classify every token in
srcfor syntax highlighting.