{"id":11223,"library":"langium","title":"Langium Language Engineering Tool","description":"Langium is an open-source, TypeScript-based framework designed for language engineering, offering first-class support for the Language Server Protocol (LSP). It enables developers to create Domain-Specific Languages (DSLs) and low-code platforms with deep integration into environments like VS Code and Eclipse Theia. The current stable version is 4.2.2, with frequent minor releases occurring roughly monthly or bi-monthly, and major versions typically released annually. Key differentiators include its declarative grammar language (similar to Xtext but relying on TypeScript interfaces instead of EMF), a robust dependency injection system for extensibility, high performance powered by Chevrotain, and the ability to generate typed Abstract Syntax Trees (ASTs). Langium supports execution in both Node.js environments and web browsers, making it versatile for various language tooling needs.","status":"active","version":"4.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/eclipse-langium/langium","tags":["javascript","language","dsl","low-code","lsp","language-server","vscode","typescript"],"install":[{"cmd":"npm install langium","lang":"bash","label":"npm"},{"cmd":"yarn add langium","lang":"bash","label":"yarn"},{"cmd":"pnpm add langium","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides core Language Server Protocol (LSP) functionality for integration with IDEs.","package":"vscode-languageserver","optional":false},{"reason":"Command-line interface for processing Langium grammars and generating TypeScript code.","package":"langium-cli","optional":false},{"reason":"Yeoman generator tool used to scaffold new Langium language extension projects.","package":"yo","optional":true},{"reason":"Yeoman generator specifically for creating Langium projects.","package":"generator-langium","optional":true}],"imports":[{"note":"This function initiates the Language Server Protocol (LSP) server based on the provided shared services. Langium is ESM-first.","wrong":"const { startLanguageServer } = require('langium');","symbol":"startLanguageServer","correct":"import { startLanguageServer } from 'langium';"},{"note":"Used for file system access in Node.js environments. For browser environments, use `EmptyFileSystem` from 'langium'.","wrong":"import { NodeFileSystem } from 'langium';","symbol":"NodeFileSystem","correct":"import { NodeFileSystem } from 'langium/node';"},{"note":"These are core types for defining and configuring language-specific and shared services within Langium's dependency injection system. Renamed from `ILangiumServices` in older versions.","wrong":"import { ILangiumServices } from 'langium';","symbol":"LangiumServices","correct":"import { LangiumServices, LangiumSharedServices, Module } from 'langium';"},{"note":"This symbol represents a common pattern where `langium-cli` generates a language-specific factory function for setting up services (e.g., `createHelloWorldServices`). The actual import path and name will vary based on your project structure and language name.","symbol":"createMyLanguageServices","correct":"import { createMyLanguageServices } from './my-language-module';"}],"quickstart":{"code":"import { startLanguageServer, EmptyFileSystem, LangiumSharedServices } from 'langium';\nimport { NodeFileSystem } from 'langium/node';\nimport { createConnection, ProposedFeatures } from 'vscode-languageserver/node';\n\n// --- This part of the code is typically generated by `langium-cli` ---\n// It sets up your language's grammar, parser, validator, and other services.\n// For a runnable example, we'll mock a simple `createMyLanguageServices`.\ninterface MyLanguageServices {\n    // Define your language-specific service interfaces here\n    // e.g., validation: { MyLanguageValidator: MyLanguageValidator }\n}\n\nfunction createMyLanguageServices(context: {\n    connection?: ReturnType<typeof createConnection>;\n    fileSystem: EmptyFileSystem | NodeFileSystem;\n}): { shared: LangiumSharedServices; MyLanguage: MyLanguageServices } {\n    // In a real Langium project, this would load your grammar and hook up\n    // the generated parser, linker, scope provider, etc.\n    // For this quickstart, we're providing a basic mock.\n    const connection = context.connection ?? createConnection(ProposedFeatures.all);\n    // Mimic the creation of default shared services\n    const shared = require('langium/lib/shared/shared-module').createDefaultSharedModule(context);\n    // Mimic the creation of language-specific services\n    const MyLanguage: MyLanguageServices = {}; // Empty mock for demonstration\n    \n    connection.onInitialize(() => {\n        // In a real setup, capabilities would be dynamically provided by Langium\n        return {\n            capabilities: {\n                textDocumentSync: { openClose: true, change: 1 /* TextDocumentSyncKind.Full */ },\n                completionProvider: { resolveProvider: true, triggerCharacters: ['.'] },\n                hoverProvider: true\n            }\n        };\n    });\n    connection.onInitialized(() => {\n        connection.console.log('Mock Langium language server initialized for MyLanguage.');\n    });\n\n    return { shared, MyLanguage };\n}\n// ------------------------------------------------------------------\n\n// Establish a connection for the language server.\n// Langium typically uses Node's IPC to communicate with the VS Code client.\nconst connection = createConnection(ProposedFeatures.all);\n\n// Create the shared and language-specific services.\n// `createMyLanguageServices` would be imported from your generated module file (e.g., `./src/language-server/my-language-module.ts`).\n// The NodeFileSystem is crucial for server-side file access.\nconst { shared, MyLanguage } = createMyLanguageServices({ connection, ...NodeFileSystem });\n\n// Start the language server.\n// This function handles the lifecycle of the LSP connection and dispatches requests\n// to the services configured in `shared`.\nstartLanguageServer(shared);\n\n// Listen for incoming LSP messages.\nconnection.listen();","lang":"typescript","description":"Demonstrates a minimal Langium language server setup, showing how to establish an LSP connection and start the server using generated service factories."},"warnings":[{"fix":"Review the official v4.0.0 changelog and migration guide on langium.org. Key changes include moving code generation exports (`langium/generate`) and LSP-related services/functions (`langium/lsp`) into dedicated paths. TypeScript >= 5.8.0 is now a hard requirement.","message":"Langium v4.0.0 introduced significant breaking changes. Projects upgrading from v3.x or older will require adaptation, especially around service exports, type definitions, and reference handling.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Update all code referencing AST node types and scope/reference resolution methods to align with the new naming conventions and return types.","message":"The generated type names for AST nodes changed from `<typeName>` to `<typeName>.$type` in v4.0.0. Additionally, `PrecomputedScopes` was renamed to `LocalSymbols` and `References#findDeclaration` to `findDeclarations` (which now returns an array).","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure your Node.js environment meets the minimum requirement. Update Node.js to version 20.10.0 or newer using nvm or your preferred method.","message":"Langium requires Node.js version 20.10.0 or higher. Using older versions will lead to errors during installation or runtime.","severity":"gotcha","affected_versions":"<20.10.0"},{"fix":"Double-check the service property names in your `_module.ts` file against the default Langium service definitions. Refer to the Langium documentation on 'Configuration via Services' for correct naming.","message":"When overriding or extending default services via Langium's dependency injection (DI) modules, the property name for the custom service in your module must exactly match that of the default implementation. Mismatches will result in the default service being used or injection errors.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the package: `npm install vscode-languageserver vscode-languageserver-types vscode-languageserver-protocol`. Ensure you are importing `vscode-languageserver/node` for Node.js servers, or `vscode-languageserver/browser` for browser-based servers.","cause":"The `vscode-languageserver` package, essential for LSP functionality, is not installed or incorrectly imported for a Node.js environment.","error":"Cannot find module 'vscode-languageserver/node' or its corresponding type declarations."},{"fix":"Verify your `_module.ts` file correctly registers all necessary services (default and custom). Ensure that custom services that depend on `LangiumServices` are properly constructed, typically by accepting `services: YourLanguageServices` in their constructor.","cause":"A Langium service, or a property within a service, has not been correctly registered in the dependency injection module or accessed before its initialization.","error":"TypeError: Cannot read properties of undefined (reading 'validation') (or similar access on a service property)"},{"fix":"Upgrade your Node.js version to 20.10.0 or newer. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions.","cause":"The installed Node.js version is older than the minimum required by Langium.","error":"Error: Node.js version X.Y.Z is not supported. Langium requires >=20.10.0"},{"fix":"Run `npm run langium:generate` (or `npx langium generate`) to generate the grammar-related TypeScript files, then `npm run build` (or `tsc`) to compile them. Verify the `langium:generate` script in `package.json` points to the correct grammar file.","cause":"The `langium-cli` generation step has not been run, or the generated TypeScript files have not been compiled, meaning the grammar definition is not available at runtime.","error":"Error: The Langium grammar 'MyLanguage' cannot be loaded. Ensure the grammar has been generated and compiled."}],"ecosystem":"npm"}