import { streamAllContents, streamContents } from "../utils/ast-utils.js";
import { cancellation_exports } from "../utils/cancellation.js";
import { interruptAndCheck } from "../utils/promise-utils.js";
import { MultiMap } from "../utils/collections.js";
var DefaultScopeComputation = class {
	constructor(e) {
		this.nameProvider = e.references.NameProvider, this.descriptions = e.workspace.AstNodeDescriptionProvider;
	}
	async collectExportedSymbols(e, t = cancellation_exports.CancellationToken.None) {
		return this.collectExportedSymbolsForNode(e.parseResult.value, e, void 0, t);
	}
	async collectExportedSymbolsForNode(e, i, a = streamContents, o = cancellation_exports.CancellationToken.None) {
		let s = [];
		this.addExportedSymbol(e, s, i);
		for (let t of a(e)) await interruptAndCheck(o), this.addExportedSymbol(t, s, i);
		return s;
	}
	addExportedSymbol(e, t, n) {
		let r = this.nameProvider.getName(e);
		r && t.push(this.descriptions.createDescription(e, r, n));
	}
	async collectLocalSymbols(t, a = cancellation_exports.CancellationToken.None) {
		let o = t.parseResult.value, s = new MultiMap();
		for (let n of streamAllContents(o)) await interruptAndCheck(a), this.addLocalSymbol(n, t, s);
		return s;
	}
	addLocalSymbol(e, t, n) {
		let r = e.$container;
		if (r) {
			let i = this.nameProvider.getName(e);
			i && n.add(r, this.descriptions.createDescription(e, i, t));
		}
	}
};
export { DefaultScopeComputation };
