Skip to content

rune-langium / core/src / parseWorkspace

Function: parseWorkspace()

ts
function parseWorkspace(entries): Promise<ParseResult[]>;

Defined in: packages/core/src/api/parse.ts:192

Parse multiple Rosetta DSL source strings as a workspace. Cross-references between documents will be resolved after all documents are built.

Parameters

ParameterTypeDescription
entries{ content: string; uri: string; }[]Array of { uri, content } objects to parse together. Each uri must be unique; duplicate URIs cause the later entry to overwrite the earlier one silently.

Returns

Promise<ParseResult[]>

An array of ParseResult objects in the same order as entries.

Remarks

DocumentBuilder.build() indexes all provided documents together, so cross-file type references (e.g., a Data type extending a type defined in another file) will resolve correctly. Documents not included in entries will produce unresolved references even if they exist on disk.

Use When

  • Generating code from a set of related .rosetta files
  • Validating a full namespace bundle where types reference each other
  • Running integration tests that span multiple Rosetta files

Avoid When

  • Parsing a single self-contained file — use the simpler parse() instead
  • Processing very large CDM workspaces incrementally — prefer the LSP server for streaming document updates

Pitfalls

  • All documents must be provided in a single parseWorkspace() call for cross-references to resolve. Documents added across separate calls will NOT see each other's types.
  • Do NOT reuse the ParseResult.value nodes after calling parseWorkspace() again with a different set — the underlying index is rebuilt and prior AST node identity becomes invalid.
  • Workspace indexing runs synchronously after build() completes; very large workspaces (e.g., full CDM) may block for several seconds in a single-threaded environment.

Example

ts
import { parseWorkspace } from '@rune-langium/core';

const results = await parseWorkspace([
  { uri: 'file:///models/base.rosetta',  content: baseSource },
  { uri: 'file:///models/trade.rosetta', content: tradeSource },
]);

const tradeModel = results[1].value;
// Type references in tradeModel now resolve into baseModel's types

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