import { getDocument as a } from "../utils/ast-utils.js";
import { isJSDoc as m, parseJSDoc as s } from "./jsdoc.js";
class f {
  constructor(e) {
    this.indexManager = e.shared.workspace.IndexManager, this.commentProvider = e.documentation.CommentProvider;
  }
  getDocumentation(e) {
    const r = this.commentProvider.getComment(e);
    if (r && m(r))
      return s(r).toMarkdown({
        renderLink: (n, t) => this.documentationLinkRenderer(e, n, t),
        renderTag: (n) => this.documentationTagRenderer(e, n)
      });
  }
  documentationLinkRenderer(e, r, o) {
    var n;
    const t = (n = this.findNameInPrecomputedScopes(e, r)) !== null && n !== void 0 ? n : this.findNameInGlobalScope(e, r);
    if (t && t.nameSegment) {
      const d = t.nameSegment.range.start.line + 1, i = t.nameSegment.range.start.character + 1, c = t.documentUri.with({ fragment: `L${d},${i}` });
      return `[${o}](${c.toString()})`;
    } else
      return;
  }
  documentationTagRenderer(e, r) {
  }
  findNameInPrecomputedScopes(e, r) {
    const n = a(e).precomputedScopes;
    if (!n)
      return;
    let t = e;
    do {
      const i = n.get(t).find((c) => c.name === r);
      if (i)
        return i;
      t = t.$container;
    } while (t);
  }
  findNameInGlobalScope(e, r) {
    return this.indexManager.allElements().find((n) => n.name === r);
  }
}
export {
  f as JSDocDocumentationProvider
};
