# @gram-lang/language-server [![npm](https://img.shields.io/npm/v/@gram-lang/language-server?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/language-server) [![License: GPL v3](https://img.shields.io/badge/License-GPL_v3-blue?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0) *Part of the [Gram monorepo](https://git.gram-lang.org/gram-lang/gram) ยท [Documentation](https://gram-lang.org/docs/)* Language Server Protocol (LSP) implementation for the [Gram](https://gram-lang.org) recipe DSL. Provides diagnostics, semantic tokens, autocomplete, hover information, refactoring, formatting, and live view updates for any LSP-compatible editor. ## Installation ```bash npm install @gram-lang/language-server # or bun add @gram-lang/language-server ``` ## Usage Intended for editor extensions and IDEs supporting the Language Server Protocol (VS Code, VSCodium, Neovim, Helix, Zed, Emacs, Monaco Editor). See the [editors guide](https://gram-lang.org/docs/reference/tooling/editors/) for editor-specific setup. From a VS Code / Node.js extension client: ```javascript import { LanguageClient, TransportKind } 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 - **Diagnostics**: real-time syntax and semantic validation (compound quantities, unit ratios, durations, target states, missing or unused references, circular `@use` imports). - **Semantic tokens**: highlighting for ingredients, quantities, cookware, timers, temperatures, and target states (`={...}`). - **Hover**: nutritional info, scaled quantities, duration breakdowns, and unit-ratio details. - **Completion**: suggestions for units (including ratio denominators), ingredients from the local YAML database, cookware, and `@use` import paths. - **Navigation and refactoring**: go to definition, find all references, rename symbol (`F2` across references, `%`, and unit ratios), document symbols, and folding ranges. - **Code actions, inlay hints and CodeLens**: quick fixes, volume-to-mass conversions, total-time inlay hints, and preview CodeLens. - **Document formatting**: canonical `.gram` formatting via [`@gram-lang/format`](https://www.npmjs.com/package/@gram-lang/format). - **Views protocol**: renders only outputs currently open in the client (`gram/setOpenViews`) and replies with `gram/viewUpdated` (recipe and run sheet as HTML, AST and compiled JSON as text or interactive tree). On error, open views pause under a localized banner instead of being replaced. Available outputs are advertised in `capabilities.experimental.gramViews`. Legacy `gram/previewUpdated` and `gram/ganttUpdated` notifications remain deprecated until 2.0.0. - **Sessions**: `gram/setSession` stores transient per-sitting state (serving time, scale, in-stock imports, baker's reference) without modifying the file; `gram/sessionChoices` lists available controls and `gram/serveTimes` proposes valid serving times against the project's `mealTimes` and `availability`. - **Settings and project config**: `gram.*` client settings and `.gram/config.yaml` changes (`timezone`, `availability`, `paths`) apply live to all open recipes. ## License Licensed under the [GPL-3.0](https://www.gnu.org/licenses/gpl-3.0) license.