import { stream as e } from "../utils/stream.js";
import { getDocument as t } from "../utils/ast-utils.js";
import { MultiMapScope as n, StreamScope as r } from "./scope.js";
import { WorkspaceCache as i } from "../utils/caching.js";
//#region ../../node_modules/langium/lib/references/scope-provider.js
var a = class {
	constructor(e) {
		this.reflection = e.shared.AstReflection, this.nameProvider = e.references.NameProvider, this.descriptions = e.workspace.AstNodeDescriptionProvider, this.indexManager = e.shared.workspace.IndexManager, this.globalScopeCache = new i(e.shared);
	}
	getScope(e) {
		let n = [], r = this.reflection.getReferenceType(e), i = t(e.container).localSymbols;
		if (i) {
			let t = e.container;
			do
				i.has(t) && n.push(i.getStream(t).filter((e) => this.reflection.isSubtype(e.type, r))), t = t.$container;
			while (t);
		}
		let a = this.getGlobalScope(r, e);
		for (let e = n.length - 1; e >= 0; e--) a = this.createScope(n[e], a);
		return a;
	}
	createScope(t, n, i) {
		return new r(e(t), n, i);
	}
	createScopeForNodes(t, n, i) {
		return new r(e(t).map((e) => {
			let t = this.nameProvider.getName(e);
			if (t) return this.descriptions.createDescription(e, t);
		}).nonNullable(), n, i);
	}
	getGlobalScope(e, t) {
		return this.globalScopeCache.get(e, () => new n(this.indexManager.allElements(e)));
	}
};
//#endregion
export { a as DefaultScopeProvider };
