import { stream as e } from "../utils/stream.js";
import { getDocument as t } from "../utils/ast-utils.js";
import { cancellation_exports as n } from "../utils/cancellation.js";
import { UriUtils as r } from "../utils/uri-utils.js";
import { ContextCache as i } from "../utils/caching.js";
//#region ../../node_modules/langium/lib/workspace/index-manager.js
var a = class {
	constructor(e) {
		this.symbolIndex = /* @__PURE__ */ new Map(), this.symbolByTypeIndex = new i(), this.referenceIndex = /* @__PURE__ */ new Map(), this.documents = e.workspace.LangiumDocuments, this.serviceRegistry = e.ServiceRegistry, this.astReflection = e.AstReflection;
	}
	findAllReferences(n, i) {
		let a = t(n).uri, o = [];
		return this.referenceIndex.forEach((e) => {
			e.forEach((e) => {
				r.equals(e.targetUri, a) && e.targetPath === i && o.push(e);
			});
		}), e(o);
	}
	allElements(t, n) {
		let r = e(this.symbolIndex.keys());
		return n && (r = r.filter((e) => !n || n.has(e))), r.map((e) => this.getFileDescriptions(e, t)).flat();
	}
	getFileDescriptions(e, t) {
		return t ? this.symbolByTypeIndex.get(e, t, () => (this.symbolIndex.get(e) ?? []).filter((e) => this.astReflection.isSubtype(e.type, t))) : this.symbolIndex.get(e) ?? [];
	}
	remove(e) {
		this.removeContent(e), this.removeReferences(e);
	}
	removeContent(e) {
		let t = e.toString();
		this.symbolIndex.delete(t), this.symbolByTypeIndex.clear(t);
	}
	removeReferences(e) {
		let t = e.toString();
		this.referenceIndex.delete(t);
	}
	async updateContent(e, t = n.CancellationToken.None) {
		let r = await this.serviceRegistry.getServices(e.uri).references.ScopeComputation.collectExportedSymbols(e, t), i = e.uri.toString();
		this.symbolIndex.set(i, r), this.symbolByTypeIndex.clear(i);
	}
	async updateReferences(e, t = n.CancellationToken.None) {
		let r = await this.serviceRegistry.getServices(e.uri).workspace.ReferenceDescriptionProvider.createDescriptions(e, t);
		this.referenceIndex.set(e.uri.toString(), r);
	}
	isAffected(e, t) {
		let n = this.referenceIndex.get(e.uri.toString());
		return n ? n.some((e) => !e.local && t.has(e.targetUri.toString())) : !1;
	}
};
//#endregion
export { a as DefaultIndexManager };
