Skip to content

Language Server

The Gram Language Server (@gram/language-server) is the intelligence engine behind editor integrations. It implements the standard Language Server Protocol (LSP), making it possible to provide advanced IDE features for Gram files across multiple editors, not just VS Code.

Architecture

The server acts as a persistent background process that analyzes your .gram files using the @gram/parser and @gram/kitchen packages.

The real-time workflow:

  1. Editor ➔ Sends file changes on every keystroke.
  2. Language Server ➔ Intercepts changes and asks the Gram Compiler to re-evaluate the AST in memory.
  3. Gram Compiler ➔ Analyzes the new structure and emits warnings, macros, and dependencies.
  4. Language Server ➔ Translates these into standard LSP payloads (Diagnostics, Semantic Tokens, Inlay Hints) and pushes them back to the editor.

Supported LSP Features

The Gram Language Server implements the following standard capabilities:

LSP CapabilityGram Implementation
DiagnosticsReal-time syntax and structural error reporting (e.g., circular dependencies).
Semantic TokensAST-driven highlighting for modifiers, units, and composite ingredients.
CompletionIntelligent autocomplete for ingredients, units, and variables.
HoverShows nutritional breakdowns and volume-to-mass conversions.
Go to DefinitionNavigate from an intermediate reference directly to its declaration.
Find ReferencesLocate all usages of a specific intermediate variable.
RenameSafely and atomically rename intermediate variables.
Code ActionsQuick fixes (declaring missing variables, converting volume to mass).
Document FormattingCleans up spacing, composite syntax, and aligns headers.
Inlay HintsDisplays cumulative preparation times inline within the editor.
Code LensInjects interactive action buttons (like Macros calculation).
Document SymbolPopulates the editor's Outline view for structural navigation.
Folding RangeAllows collapsing of recipe ## Sections and YAML frontmatter.