gram/packages/language-server
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab 2b5ae73f33
All checks were successful
CI / Build & Test (pull_request) Successful in 7m22s
chore: release v1.5.2
2026-11-27 23:06:21 +01:00
..
src fix(language-server): read the ingredient database named by database: in .gram/config.yaml 2026-11-26 23:11:29 +01:00
tests fix(language-server): read the ingredient database named by database: in .gram/config.yaml 2026-11-26 23:11:29 +01:00
build.cjs refactor: migrate project to ESM, upgrade to TS 6.0, and unify type definitions across packages 2026-06-18 13:11:36 +02:00
CHANGELOG.md chore: release v1.5.2 2026-11-27 23:06:21 +01:00
package.json chore: release v1.5.2 2026-11-27 23:06:21 +01:00
README.md docs: refresh root and package READMEs for v1.5 2026-11-19 12:01:21 +01:00
tsconfig.json chore: bump all dependencies and migrate to typescript 7 dual setup 2026-07-13 13:17:12 +02:00

@gram-lang/language-server

npm License: GPL v3

Part of the Gram monorepo.

The official Language Server Protocol (LSP) implementation for the Gram recipe language. It provides language intelligence such as diagnostics (syntax and logic errors), auto-completion, hover information, and semantic tokens.


📚 General Documentation

For full syntax specifications, command reference, and best practices, please refer to the Gram Documentation.


🛠️ Installation

npm install @gram-lang/language-server
# or
bun add @gram-lang/language-server

⚡ Usage

This package is intended to be consumed by editor extensions or IDEs that support the Language Server Protocol (e.g., VS Code, Neovim, Emacs, Zed, Monaco Editor).

If you are developing a client extension, you can launch the server process using Node.js:

import { LanguageClient } from 'vscode-languageclient/node';

const serverModule = require.resolve('@gram-lang/language-server');

const client = new LanguageClient(
  'gramLanguageServer',
  'Gram Language Server',
  {
    run: { module: serverModule, transport: TransportKind.ipc },
    debug: { module: serverModule, transport: TransportKind.ipc }
  },
  {
    documentSelector: [{ scheme: 'file', language: 'gram' }]
  }
);

client.start();

🏗️ Capabilities

The Gram Language Server currently supports:

  • Diagnostics: Real-time syntax and semantic validation (including compound quantities, unit ratios, durations, and target states).
  • Semantic Tokens: Rich semantic highlighting for ingredients, quantities, cookware, timers, temperatures, and target states (={...}).
  • Hover: Nutritional information, scaled quantities, duration breakdowns, and unit-ratio details on hover.
  • Completion: Suggestions for units (including ratio denominators), ingredients (from the user's local ingredient DB), cookware, and @use import paths.
  • Navigation & Refactoring: Go to Definition, Find All References, Rename Symbol (F2 across references, %, and unit ratios), Document Symbols (Outline), and Folding Ranges.
  • Code Actions, Inlay Hints & CodeLens: Quick fixes for common diagnostics, total time / duration inlay hints, and ▶ Preview CodeLens.
  • Document Formatting: Automatic formatting of .gram files to the standard canonical style (powered by @gram-lang/format).
  • Views protocol: Renders only the views and inspectors currently open in the client (gram/setOpenViews) and answers with gram/viewUpdated (recipe and run sheet as HTML, AST and compiled JSON as text or an interactive tree). When a recipe has errors, open outputs are paused instead of replaced by an error card, with a localized error summary beside the usual diagnostics. The outputs a client can open are listed, with their names in the editor's language, in the initialize result (capabilities.experimental.gramViews), so a client shows a new view without an update of its own. Legacy clients continue receiving gram/previewUpdated and gram/ganttUpdated (both deprecated) until 2.0.0.
  • Sessions: gram/setSession sets the transient choices of a recipe, held in memory and never written to the file: the serving time (which puts the run sheet on the calendar, in the project's timezone and within its availability), the scale, the imports already in stock and the baker's reference. gram/sessionChoices says what these controls offer for a recipe as written (its ingredients, its @use imports, whether baker's math is on), and gram/serveTimes proposes the serving times that work over the next days, at the project's mealTimes, with the reasons of the others.
  • Settings and project config: The gram.* settings of the client (miseEnPlace, rests, comments, stepQuantities, nutritionBasis, bakersMath, massStandardization, yieldCalculation, nutritionEstimation...) apply to every open recipe as soon as they change, and so does an edit of .gram/config.yaml (timezone, availability, paths). Only the latest version of a document is kept, so a quick edit never goes back to an older one.

📄 License

This project is licensed under the GPL-3.0 License.