import { isMultiReference as e, isReference as t } from "../syntax-tree.js";
import { getDocument as n, streamAst as r, streamReferences as i } from "../utils/ast-utils.js";
import { toDocumentSegment as a } from "../utils/cst-utils.js";
import { cancellation_exports as o } from "../utils/cancellation.js";
import { interruptAndCheck as s } from "../utils/promise-utils.js";
import { UriUtils as c } from "../utils/uri-utils.js";
//#region ../../node_modules/langium/lib/workspace/ast-descriptions.js
var l = class {
	constructor(e) {
		this.astNodeLocator = e.workspace.AstNodeLocator, this.nameProvider = e.references.NameProvider;
	}
	createDescription(e, t, r) {
		let i = r ?? n(e);
		t ??= this.nameProvider.getName(e);
		let o = this.astNodeLocator.getAstNodePath(e);
		if (!t) throw Error(`Node at path ${o} has no name.`);
		let s, c = () => s ??= a(this.nameProvider.getNameNode(e) ?? e.$cstNode);
		return {
			node: e,
			name: t,
			get nameSegment() {
				return c();
			},
			selectionSegment: a(e.$cstNode),
			type: e.$type,
			documentUri: i.uri,
			path: o
		};
	}
}, u = class {
	constructor(e) {
		this.nodeLocator = e.workspace.AstNodeLocator;
	}
	async createDescriptions(e, t = o.CancellationToken.None) {
		let n = [], a = e.parseResult.value;
		for (let e of r(a)) await s(t), i(e).forEach((e) => {
			e.reference.error || n.push(...this.createInfoDescriptions(e));
		});
		return n;
	}
	createInfoDescriptions(r) {
		let i = r.reference;
		if (i.error || !i.$refNode) return [];
		let o = [];
		t(i) && i.$nodeDescription ? o = [i.$nodeDescription] : e(i) && (o = i.items.map((e) => e.$nodeDescription).filter((e) => e !== void 0));
		let s = n(r.container).uri, l = this.nodeLocator.getAstNodePath(r.container), u = [], d = a(i.$refNode);
		for (let e of o) u.push({
			sourceUri: s,
			sourcePath: l,
			targetUri: e.documentUri,
			targetPath: e.path,
			segment: d,
			local: c.equals(e.documentUri, s)
		});
		return u;
	}
};
//#endregion
export { l as DefaultAstNodeDescriptionProvider, u as DefaultReferenceDescriptionProvider };
