Langium CLI
raw JSON →The Langium CLI (`langium-cli`) is the command-line interface for the Eclipse Langium framework, a powerful toolset for building domain-specific languages (DSLs) with full language server protocol (LSP) support. Currently at stable version 4.2.1, it follows a regular release cadence with minor versions released every few months and major versions annually or as significant breaking changes necessitate. Its primary function is to generate the core language infrastructure—including parsers, ASTs, and language server components—from a Langium grammar definition file. It differentiates itself by deeply integrating with TypeScript and VS Code, providing a robust foundation for creating custom programming languages and their development tooling efficiently, without manual boilerplate code generation. The CLI requires a configuration file, `langium-config.json`, to specify language details, grammar paths, and output targets for various artifacts like TextMate syntax highlighting, Monarch syntax highlighting, Prism syntax highlighting, and railroad diagrams.
Common errors
error Error: langium-config.json not found in the current directory or specified path. ↓
langium-config.json file in your project root, or specify its path using langium generate -f <path/to/config.json>. error Error: 'langium' is not recognized as an internal or external command, operable program or batch file. ↓
npx langium-cli <command> to execute it without global installation, or install globally with npm install -g langium-cli. error Error: Command failed with exit code 1: langium generate ↓
.langium grammar file for syntax errors and ensure langium-config.json is correctly structured and paths are valid. Warnings
breaking Langium v4.0.0 introduced significant breaking changes in the core API, particularly for how language services are initialized. Custom language services or extensions built directly on Langium's API might require refactoring. ↓
breaking The `langium-cli` package, along with the core Langium framework, now requires Node.js version 20.10.0 or higher and npm version 10.2.3 or higher. Older Node.js or npm versions are no longer supported. ↓
gotcha Incorrect or missing `langium-config.json` file can lead to failed code generation or unexpected behavior. The CLI relies heavily on this configuration for identifying grammars, output paths, and generating various artifacts. ↓
gotcha When developing with `langium-cli generate --watch`, changes to grammar files will trigger regeneration. However, changes to other parts of your project (e.g., custom language server logic) may require a manual rebuild of your TypeScript project. ↓
Install
npm install langium-cli yarn add langium-cli pnpm add langium-cli Imports
- generateAction
import { generateAction } from 'langium-cli' - runCli
import { runCli } from 'langium-cli' - LangiumConfig
import type { LangiumConfig } from 'langium-cli'
Quickstart
npx langium-cli@latest init my-language
cd my-language
npm install
# Edit src/language-server/your-language.langium and langium-config.json
# Then generate the language infrastructure:
npx langium-cli generate --watch
# To test the generated language server:
npm run start