import { hasAtLeast, invariant } from "@likec4/core";
import { DefaultWorkspaceManager } from "langium";
import { URI } from "vscode-uri";
import * as BuiltIn from "../likec4lib.js";
export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
  documentFactory;
  constructor(services) {
    super(services);
    this.documentFactory = services.workspace.LangiumDocumentFactory;
  }
  /**
   * Load all additional documents that shall be visible in the context of the given workspace
   * folders and add them to the collector. This can be used to include built-in libraries of
   * your language, which can be either loaded from provided files or constructed in memory.
   */
  async loadAdditionalDocuments(folders, collector) {
    collector(this.documentFactory.fromString(BuiltIn.Content, URI.parse(BuiltIn.Uri)));
    await super.loadAdditionalDocuments(folders, collector);
  }
  workspace() {
    if (this.folders && hasAtLeast(this.folders, 1)) {
      return this.folders[0];
    }
    return null;
  }
  get workspaceUri() {
    const workspace = this.workspace();
    invariant(workspace, "Workspace not initialized");
    return URI.parse(workspace.uri);
  }
  get workspaceURL() {
    const workspace = this.workspace();
    invariant(workspace, "Workspace not initialized");
    return new URL(workspace.uri);
  }
}
