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