Skip to main content

Module services

Module services 

Source
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 from crate::lint (unused lets; unknown series when a series list is given), as ranged Diagnostics. The linter is the single diagnostics source, so the editor squiggles match lemon lint exactly.
  • 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§

CompletionItem
One completion candidate. insert_text is the text to insert (equal to label for everything except keyword args, which insert name=).
Diagnostic
A ranged diagnostic: [ (line, col) .. (end_line, end_col) ), 1-based, with end_col exclusive.
HoverInfo
The hover card for the token under the cursor: a range to highlight plus the Markdown body.
SemanticToken
A classified source span, [ (line, col) .. (end_line, end_col) ), 1-based with end_col exclusive — same convention as Diagnostic.

Enums§

CompletionKind
What a CompletionItem refers to — lets the editor pick an icon.
Severity
Diagnostic severity. Parse/lex errors are Severity::Error; semantic lints from crate::lint are Severity::Warning.
TokenType
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 from tokens, 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 from crate::lint as ranged warnings.
hover
Markdown hover for the token at 1-based (line, col), or None when there is nothing documented there (whitespace, punctuation, numbers, unknown series).
tokens
Classify every token in src for syntax highlighting.