| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .. | ||
| src | ||
| tests | ||
| build.cjs | ||
| CHANGELOG.md | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
@gram-lang/language-server
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
@useimport paths. - Navigation & Refactoring: Go to Definition, Find All References, Rename Symbol (
F2across 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
▶ PreviewCodeLens. - Document Formatting: Automatic formatting of
.gramfiles 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 withgram/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 theinitializeresult (capabilities.experimental.gramViews), so a client shows a new view without an update of its own. Legacy clients continue receivinggram/previewUpdatedandgram/ganttUpdated(both deprecated) until 2.0.0. - Sessions:
gram/setSessionsets 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'stimezoneand within itsavailability), the scale, the imports already in stock and the baker's reference.gram/sessionChoicessays what these controls offer for a recipe as written (its ingredients, its@useimports, whether baker's math is on), andgram/serveTimesproposes the serving times that work over the next days, at the project'smealTimes, 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.