import { DefaultWorkspaceManager, type FileSystemNode, type LangiumDocument, type LangiumSharedCoreServices, type WorkspaceFolder } from 'langium'; import type { CancellationToken } from 'vscode-languageserver-protocol'; import type { DomainLangServices } from '../domain-lang-module.js'; /** * Langium WorkspaceManager override implementing manifest-centric import loading per PRS-010. * * **Three Operational Modes:** * * **Mode A (Pure Workspace with model.yaml):** * - model.yaml exists at workspace root * - Loads entry file (default: index.dlang, or custom via model.entry) * - Pre-builds entry and follows import graph * - All imported documents built to Validated state before workspace ready * - LSP features have immediate access to complete reference information * * **Mode B (Pure Standalone files):** * - No model.yaml anywhere in workspace * - No pre-loading of .dlang files during workspace scan * - Documents loaded on-demand when user opens them * - Imports resolved lazily via ImportResolver * - Each document built individually when opened * - Works with relative imports only (no path aliases or external deps) * * **Mode C (Mixed - Standalone + Module folders):** * - Workspace contains both standalone .dlang files AND folders with model.yaml * - Each model.yaml folder treated as a module/package: * - Module entry + import graph pre-loaded * - Path aliases and external deps work within module * - Standalone files outside modules loaded on-demand * - Example structure: * ``` * workspace/ * ├── standalone.dlang ← Mode B (on-demand) * ├── core/ * │ ├── model.yaml ← Module root * │ ├── index.dlang ← Pre-loaded * │ └── domains/ * │ └── sales.dlang ← Pre-loaded via imports * └── util.dlang ← Mode B (on-demand) * ``` * * **Performance Characteristics:** * - Mode A/C modules: Slower initial load, instant LSP features afterward * - Mode B/C standalone: Instant workspace init, per-file build on open * - All modes cache import resolution for subsequent access * * **Never performs network fetches** - relies on cached dependencies/lock files. * Missing cache produces diagnostics upstream via ImportValidator. */ export declare class DomainLangWorkspaceManager extends DefaultWorkspaceManager { private readonly sharedServices; /** * LSP connection for progress reporting (PRS-017 R7). * Optional because the workspace manager can run in non-LSP contexts. */ private readonly connection; /** * DI-injected import resolver. Set via late-binding because * WorkspaceManager (shared module) is created before ImportResolver (language module). * Always set before any workspace loading begins via `setLanguageServices()`. */ private importResolver; constructor(services: LangiumSharedCoreServices); /** * Late-binds the language-specific services after DI initialization. * Called from `createDomainLangServices()` after the language module is created. */ setLanguageServices(services: DomainLangServices): void; shouldIncludeEntry(entry: FileSystemNode): boolean; initializeWorkspace(folders: WorkspaceFolder[], cancelToken?: CancellationToken): Promise; protected loadAdditionalDocuments(folders: WorkspaceFolder[], collector: (document: LangiumDocument) => void): Promise; /** * Loads standalone .dlang files from workspace folders recursively. * * Skips: * - Module directories (directories with model.yaml) - loaded via import graph * - `.dlang/packages` directory - package cache managed by CLI * * @param folders - Workspace folders to scan * @param moduleDirectories - Set of directories containing model.yaml (to skip) * @param collector - Document collector callback */ private loadStandaloneFiles; /** * Recursively loads .dlang files from a directory. * Skips module directories and the .dlang/packages cache. */ private loadDlangFilesRecursively; /** * Attempts to load a document, returning undefined on failure. */ private tryLoadDocument; /** * Creates an LSP work-done progress reporter. * Returns undefined in non-LSP contexts (no connection). */ private createProgress; }