import { UriUtils as o } from "./utils/uri-utils.js";
class u {
  /**
   * @deprecated Use the new `fileExtensionMap` (or `languageIdMap`) property instead.
   */
  get map() {
    return this.fileExtensionMap;
  }
  constructor(e) {
    this.languageIdMap = /* @__PURE__ */ new Map(), this.fileExtensionMap = /* @__PURE__ */ new Map(), this.textDocuments = e == null ? void 0 : e.workspace.TextDocuments;
  }
  register(e) {
    const t = e.LanguageMetaData;
    for (const s of t.fileExtensions)
      this.fileExtensionMap.has(s) && console.warn(`The file extension ${s} is used by multiple languages. It is now assigned to '${t.languageId}'.`), this.fileExtensionMap.set(s, e);
    this.languageIdMap.set(t.languageId, e), this.languageIdMap.size === 1 ? this.singleton = e : this.singleton = void 0;
  }
  getServices(e) {
    var t, s;
    if (this.singleton !== void 0)
      return this.singleton;
    if (this.languageIdMap.size === 0)
      throw new Error("The service registry is empty. Use `register` to register the services of a language.");
    const i = (s = (t = this.textDocuments) === null || t === void 0 ? void 0 : t.get(e)) === null || s === void 0 ? void 0 : s.languageId;
    if (i !== void 0) {
      const a = this.languageIdMap.get(i);
      if (a)
        return a;
    }
    const n = o.extname(e), r = this.fileExtensionMap.get(n);
    if (!r)
      throw i ? new Error(`The service registry contains no services for the extension '${n}' for language '${i}'.`) : new Error(`The service registry contains no services for the extension '${n}'.`);
    return r;
  }
  hasServices(e) {
    try {
      return this.getServices(e), !0;
    } catch {
      return !1;
    }
  }
  get all() {
    return Array.from(this.languageIdMap.values());
  }
}
export {
  u as DefaultServiceRegistry
};
