Skip to content

rune-langium / core/src / createRuneDslServices

Function: createRuneDslServices()

ts
function createRuneDslServices(context?): {
  RuneDsl: LangiumCoreServices;
  shared: LangiumSharedCoreServices;
};

Defined in: packages/core/src/services/rune-dsl-module.ts:125

Create the full set of services required for the Rune DSL language.

Parameters

ParameterTypeDefault valueDescription
contextDefaultSharedCoreModuleContextEmptyFileSystemOptional Langium file-system context. Defaults to EmptyFileSystem (in-memory only). Pass a NodeFileSystem context when resolving imports from disk.

Returns

ts
{
  RuneDsl: LangiumCoreServices;
  shared: LangiumSharedCoreServices;
}

An object with shared (shared core services) and RuneDsl (language-specific services).

NameTypeDefined in
RuneDslLangiumCoreServicespackages/core/src/services/rune-dsl-module.ts:127
sharedLangiumSharedCoreServicespackages/core/src/services/rune-dsl-module.ts:126

Remarks

This is the primary entry point for any non-LSP usage (scripts, tests, build tools). It wires together:

  • The generated Langium modules (RuneDslGeneratedModule, RuneDslGeneratedSharedModule)
  • The hand-written overrides in RuneDslModule
  • RuneDslValidator checks registered into the ValidationRegistry

Services are initialized synchronously. The ConfigurationProvider.initialized({}) call stubs out LSP configuration so that non-LSP code paths do not hang waiting for a client workspace/configuration response.

Use When

  • Building a Node.js script that parses or validates .rosetta files
  • Writing unit tests for grammar rules or validators
  • Constructing a parseWorkspace() pipeline outside of the LSP server

Avoid When

  • Inside the LSP server — use createRuneLspServer() which provides the full LangiumServices (LSP providers) instead of core-only services.
  • When you need to share a service instance across multiple requests in a long-running server — the returned instance is not thread-safe for concurrent DocumentBuilder.build() calls; serialize builds with a queue.

Pitfalls

  • NEVER call DocumentBuilder.build() before createRuneDslServices() returns — the Langium index is not populated until services are fully constructed.
  • NEVER reuse the same services instance across unrelated workspace contexts (e.g., two different CDM versions) — the index will conflate type names from both contexts and produce incorrect cross-reference resolution.
  • The returned shared and RuneDsl services share an internal ServiceRegistry; do NOT register additional languages into the same shared for production use unless you understand Langium's multi-language scoping rules.

Example

ts
import { createRuneDslServices } from '@rune-langium/core';
import { NodeFileSystem } from 'langium/node';

// In-memory (for tests / scripts):
const { RuneDsl } = createRuneDslServices();

// Disk-backed (for resolving imports from the file system):
const { RuneDsl: diskServices } = createRuneDslServices(NodeFileSystem);

Core packages released under MIT. Studio app released under FSL-1.1-ALv2.