"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extractor_exports = {};
__export(extractor_exports, {
  extractFile: () => extractFile,
  makeNodeId: () => makeNodeId
});
module.exports = __toCommonJS(extractor_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var crypto = __toESM(require("crypto"));
var import_languages = require("./languages");
var import_grammars = require("./grammars");
function makeNodeId(filePath, kind, name, line) {
  const hash = crypto.createHash("sha256").update(`${filePath}:${kind}:${name}:${line}`).digest("hex").slice(0, 32);
  return `${kind}:${hash}`;
}
function validatePath(filePath, projectRoot) {
  try {
    const real = fs.realpathSync(filePath);
    const realRoot = fs.realpathSync(projectRoot);
    return real.startsWith(realRoot + path.sep) || real === realRoot;
  } catch {
    const normalized = path.resolve(filePath);
    return normalized.startsWith(path.resolve(projectRoot));
  }
}
async function extractFile(filePath, projectRoot, content) {
  const language = (0, import_languages.detectLanguage)(filePath);
  if (!(0, import_languages.isSupportedLanguage)(language)) return null;
  if (!validatePath(filePath, projectRoot)) return null;
  let source;
  try {
    if (content !== void 0) {
      source = typeof content === "string" ? content : content.toString("utf8");
    } else {
      source = fs.readFileSync(filePath, "utf8");
    }
  } catch {
    return null;
  }
  const contentHash = crypto.createHash("sha256").update(source).digest("hex");
  const fileSize = Buffer.byteLength(source, "utf8");
  const relPath = path.relative(projectRoot, filePath).replace(/\\/g, "/");
  await (0, import_grammars.initGrammars)();
  const parser = await (0, import_grammars.getParser)(language);
  if (!parser) {
    if (!(0, import_grammars.hasWasmGrammar)(language)) {
      return {
        filePath: relPath,
        language,
        contentHash,
        fileSize,
        nodes: [],
        edges: [],
        unresolvedRefs: []
      };
    }
    throw new Error(`Parser unavailable for ${language} (WASM grammar exists but failed to load)`);
  }
  const tree = parser.parse(source);
  const nodes = [];
  const edges = [];
  const unresolvedRefs = [];
  const now = Date.now();
  walkTree(tree.rootNode, source, relPath, language, nodes, edges, unresolvedRefs, now);
  return { filePath: relPath, language, contentHash, fileSize, nodes, edges, unresolvedRefs };
}
const ELIXIR_DEF_KINDS = {
  defmodule: "module",
  def: "function",
  defp: "function",
  defmacro: "function",
  defmacrop: "function",
  defprotocol: "interface",
  defimpl: "class",
  defstruct: "struct"
};
const ELIXIR_IMPORT_TARGETS = /* @__PURE__ */ new Set(["alias", "import", "require", "use"]);
function elixirCallTarget(node, source) {
  const target = node.childForFieldName?.("target") ?? node.child(0);
  if (!target) return null;
  return source.slice(target.startIndex, target.endIndex).trim() || null;
}
function elixirFirstArg(node) {
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (child.type === "arguments") {
      return child.namedChild(0) ?? child.child(0) ?? null;
    }
  }
  return null;
}
function extractElixirName(node, source, kind) {
  const firstArg = elixirFirstArg(node);
  if (!firstArg) return null;
  if (kind === "module" || kind === "interface" || kind === "class") {
    return source.slice(firstArg.startIndex, firstArg.endIndex).trim();
  }
  if (kind === "function") {
    if (firstArg.type === "call") {
      const nameNode = firstArg.childForFieldName?.("target") ?? firstArg.child(0);
      if (nameNode) return source.slice(nameNode.startIndex, nameNode.endIndex).trim();
    }
    return source.slice(firstArg.startIndex, firstArg.endIndex).trim();
  }
  return null;
}
function extractElixirImportSource(node, source) {
  const firstArg = elixirFirstArg(node);
  if (!firstArg) return null;
  return source.slice(firstArg.startIndex, firstArg.endIndex).trim() || null;
}
function walkElixirCall(node, source, filePath, language, nodes, edges, unresolvedRefs, now, parentId) {
  const targetText = elixirCallTarget(node, source);
  if (!targetText) {
    for (let i = 0; i < node.childCount; i++) {
      walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, parentId);
    }
    return;
  }
  if (ELIXIR_IMPORT_TARGETS.has(targetText)) {
    const modPath = extractElixirImportSource(node, source);
    if (modPath) {
      const id = makeNodeId(filePath, "import", modPath, node.startPosition.row + 1);
      nodes.push({
        id,
        kind: "import",
        name: modPath,
        qualifiedName: `${filePath}::import:${modPath}`,
        filePath,
        language,
        startLine: node.startPosition.row + 1,
        endLine: node.endPosition.row + 1,
        startColumn: node.startPosition.column,
        endColumn: node.endPosition.column,
        updatedAt: now
      });
      unresolvedRefs.push({ sourceId: id, refName: modPath, refKind: "import", line: node.startPosition.row + 1, column: node.startPosition.column });
    }
    return;
  }
  const defKind = ELIXIR_DEF_KINDS[targetText];
  if (defKind) {
    const name = extractElixirName(node, source, defKind);
    if (name) {
      const id = makeNodeId(filePath, defKind, name, node.startPosition.row + 1);
      const isPrivate = targetText === "defp" || targetText === "defmacrop";
      nodes.push({
        id,
        kind: defKind,
        name,
        qualifiedName: `${filePath}::${name}`,
        filePath,
        language,
        startLine: node.startPosition.row + 1,
        endLine: node.endPosition.row + 1,
        startColumn: node.startPosition.column,
        endColumn: node.endPosition.column,
        docstring: extractDocstring(node, source),
        signature: extractSignature(node, source, defKind),
        visibility: isPrivate ? "private" : "public",
        isExported: !isPrivate,
        updatedAt: now
      });
      if (parentId) edges.push({ source: parentId, target: id, kind: "contains" });
      collectCallRefs(node, source, id, unresolvedRefs);
      for (let i = 0; i < node.childCount; i++) {
        walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, id);
      }
      return;
    }
  }
  for (let i = 0; i < node.childCount; i++) {
    walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, parentId);
  }
}
const TRANSPARENT_TYPES = /* @__PURE__ */ new Set([
  "export_statement",
  "program",
  "source_file",
  "module",
  "translation_unit"
]);
const KIND_MAP = {
  // Functions
  function_declaration: "function",
  function_expression: "function",
  arrow_function: "function",
  function_definition: "function",
  // Python, Scala
  function_item: "function",
  // Rust
  function_declaration_go: "function",
  // Methods
  method_definition: "method",
  method_declaration: "method",
  // Go, Java, C#
  constructor_declaration: "method",
  // Java, C#
  // Classes / structs
  class_declaration: "class",
  class_expression: "class",
  class_definition: "class",
  // Python, Scala
  impl_item: "class",
  // Rust (impl blocks)
  struct_item: "struct",
  // Rust
  struct_definition: "struct",
  // Zig
  // Interfaces / traits
  interface_declaration: "interface",
  trait_item: "trait",
  // Rust
  trait_definition: "trait",
  // Scala
  protocol_declaration: "interface",
  // Swift
  // Enums
  enum_declaration: "enum",
  enum_item: "enum",
  // Rust
  // Type aliases
  type_alias_declaration: "type_alias",
  type_declaration: "type_alias",
  // Go
  typealias_declaration: "type_alias",
  // Swift
  type_item: "type_alias",
  // Rust
  type_alias: "type_alias",
  // Kotlin
  // Namespaces / modules
  namespace_declaration: "namespace",
  module_definition: "namespace",
  // OCaml
  // Variables / constants (language-specific, see extractVariableKind)
  lexical_declaration: "variable",
  // TS/JS (const/let/var) — refined below
  variable_declaration: "variable"
  // TS/JS (var)
  // Import statements (all handled via extractImport)
};
function extractVariableKind(node) {
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (child.type === "const") return "constant";
  }
  return "variable";
}
const IMPORT_NODE_TYPES = /* @__PURE__ */ new Set([
  "import_statement",
  // TS/JS
  "import_from_statement",
  // Python
  "import_declaration",
  // Go, Java
  "use_declaration",
  // Rust
  "using_directive",
  // C#
  "namespace_use_declaration",
  // PHP
  "import_header",
  // Kotlin
  "import_or_export",
  // Dart
  "include_statement",
  // Pascal
  "preproc_include"
  // C/C++
]);
function walkTree(node, source, filePath, language, nodes, edges, unresolvedRefs, now, parentId) {
  if (TRANSPARENT_TYPES.has(node.type)) {
    for (let i = 0; i < node.childCount; i++) {
      walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, parentId);
    }
    return;
  }
  if (language === "elixir" && node.type === "call") {
    walkElixirCall(node, source, filePath, language, nodes, edges, unresolvedRefs, now, parentId);
    return;
  }
  if (IMPORT_NODE_TYPES.has(node.type)) {
    const importNode = extractImport(node, source, filePath, language, unresolvedRefs, now, parentId);
    if (importNode) nodes.push(importNode);
    return;
  }
  let kind = KIND_MAP[node.type] ?? null;
  if (node.type === "lexical_declaration" || node.type === "variable_declaration") {
    kind = extractVariableKind(node);
  }
  if (!kind) kind = getLanguageSpecificKind(node.type, language);
  if (kind) {
    const name = extractName(node, source, language, kind);
    if (name) {
      const id = makeNodeId(filePath, kind, name, node.startPosition.row + 1);
      const visibility = extractVisibility(node, source, language);
      const graphNode = {
        id,
        kind,
        name,
        qualifiedName: `${filePath}::${name}`,
        filePath,
        language,
        startLine: node.startPosition.row + 1,
        endLine: node.endPosition.row + 1,
        startColumn: node.startPosition.column,
        endColumn: node.endPosition.column,
        docstring: extractDocstring(node, source),
        signature: extractSignature(node, source, kind),
        visibility,
        isExported: isExported(node),
        isAsync: isAsync(node),
        isStatic: isStatic(node),
        updatedAt: now
      };
      nodes.push(graphNode);
      if (parentId) {
        edges.push({ source: parentId, target: id, kind: "contains" });
      }
      collectCallRefs(node, source, id, unresolvedRefs);
      if ((kind === "class" || kind === "interface") && (language === "csharp" || language === "java")) {
        extractInheritance(node, source, language, id, unresolvedRefs);
      }
      for (let i = 0; i < node.childCount; i++) {
        walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, id);
      }
      return;
    }
  }
  for (let i = 0; i < node.childCount; i++) {
    walkTree(node.child(i), source, filePath, language, nodes, edges, unresolvedRefs, now, parentId);
  }
}
function getLanguageSpecificKind(type, lang) {
  switch (lang) {
    case "python":
      if (type === "assignment") return "variable";
      break;
    case "go":
      if (type === "var_declaration" || type === "short_var_declaration") return "variable";
      if (type === "const_declaration") return "constant";
      if (type === "type_spec") return "type_alias";
      break;
    case "rust":
      if (type === "let_declaration") return "variable";
      if (type === "const_item") return "constant";
      if (type === "static_item") return "variable";
      break;
    case "java":
      if (type === "field_declaration") return "property";
      if (type === "local_variable_declaration") return "variable";
      break;
    case "csharp":
      if (type === "field_declaration") return "property";
      break;
    case "php":
      if (type === "property_declaration") return "property";
      if (type === "const_declaration") return "constant";
      break;
    case "kotlin":
      if (type === "property_declaration") return "variable";
      break;
    case "swift":
      if (type === "property_declaration") return "property";
      if (type === "constant_declaration") return "constant";
      break;
    case "dart":
      if (type === "function_signature") return "function";
      if (type === "method_signature") return "method";
      break;
    case "ruby":
      if (type === "singleton_method") return "method";
      break;
    case "scala":
      if (type === "object_definition") return "class";
      if (type === "val_definition") return "variable";
      if (type === "var_definition") return "variable";
      if (type === "type_definition") return "type_alias";
      break;
    case "lua":
      if (type === "local_function") return "function";
      if (type === "local_variable_declaration") return "variable";
      if (type === "variable_assignment") return "variable";
      break;
    case "zig":
      if (type === "VarDecl") return "variable";
      if (type === "ContainerDecl") return "struct";
      break;
    case "bash":
      if (type === "variable_assignment") return "variable";
      break;
    case "ocaml":
      if (type === "let_binding") return "variable";
      if (type === "type_binding") return "type_alias";
      if (type === "module_binding") return "namespace";
      break;
    case "elm":
      if (type === "function_declaration_left") return "function";
      if (type === "type_alias_declaration") return "type_alias";
      break;
    case "solidity":
      if (type === "contract_declaration") return "class";
      if (type === "event_definition") return "function";
      if (type === "modifier_definition") return "function";
      if (type === "state_variable_declaration") return "variable";
      break;
    case "objc":
      if (type === "class_interface") return "class";
      if (type === "class_implementation") return "class";
      if (type === "protocol_declaration") return "interface";
      if (type === "method_declaration") return "method";
      if (type === "property_declaration") return "property";
      break;
    case "hcl":
      if (type === "block") return "namespace";
      if (type === "attribute") return "variable";
      break;
    case "scss":
      if (type === "mixin_statement") return "function";
      if (type === "function_statement") return "function";
      if (type === "variable_declaration") return "variable";
      if (type === "include_statement") return "import";
      if (type === "use_statement") return "import";
      if (type === "forward_statement") return "import";
      if (type === "placeholder") return "class";
      break;
    case "css":
      if (type === "rule_set") return "class";
      if (type === "declaration") return "variable";
      break;
  }
  return null;
}
function extractImport(node, source, filePath, language, unresolvedRefs, now, parentId) {
  const modulePath = extractImportSource(node, source, language);
  if (!modulePath) return null;
  const id = makeNodeId(filePath, "import", modulePath, node.startPosition.row + 1);
  const importNode = {
    id,
    kind: "import",
    name: modulePath,
    qualifiedName: `${filePath}::import:${modulePath}`,
    filePath,
    language,
    startLine: node.startPosition.row + 1,
    endLine: node.endPosition.row + 1,
    startColumn: node.startPosition.column,
    endColumn: node.endPosition.column,
    updatedAt: now
  };
  unresolvedRefs.push({
    sourceId: id,
    refName: modulePath,
    refKind: "import",
    line: node.startPosition.row + 1,
    column: node.startPosition.column
  });
  return importNode;
}
function extractImportSource(node, source, language) {
  if (node.type === "import_statement" || language === "svelte" && node.type === "import_statement") {
    for (let i = node.childCount - 1; i >= 0; i--) {
      const child = node.child(i);
      if (child.type === "string") {
        return stripQuotes(source.slice(child.startIndex, child.endIndex));
      }
    }
  }
  if (node.type === "import_from_statement") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "dotted_name" || child.type === "relative_import") {
        return source.slice(child.startIndex, child.endIndex);
      }
    }
  }
  if (node.type === "import_statement" && language === "python") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "dotted_name") {
        return source.slice(child.startIndex, child.endIndex);
      }
    }
  }
  if (node.type === "import_declaration") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "string") {
        return stripQuotes(source.slice(child.startIndex, child.endIndex));
      }
      if (child.type === "import_spec_list") {
        for (let j = 0; j < child.childCount; j++) {
          const spec = child.child(j);
          if (spec.type === "import_spec") {
            for (let k = 0; k < spec.childCount; k++) {
              const s = spec.child(k);
              if (s.type === "string") return stripQuotes(source.slice(s.startIndex, s.endIndex));
            }
          }
        }
      }
    }
  }
  if (node.type === "use_declaration") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type !== "use" && child.type !== ";") {
        return source.slice(child.startIndex, child.endIndex);
      }
    }
  }
  if (node.type === "using_directive") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "qualified_name" || child.type === "identifier") {
        return source.slice(child.startIndex, child.endIndex);
      }
    }
  }
  if (node.type === "import_declaration" || node.type === "import_header") {
    const text = source.slice(node.startIndex, node.endIndex).trim();
    const m = text.match(/^import\s+(.+?)[;\s*]*$/);
    if (m) return m[1].trim();
  }
  if (node.type === "namespace_use_declaration") {
    const text = source.slice(node.startIndex, node.endIndex).trim();
    const m = text.match(/^use\s+(.+?)[;\s]*$/);
    if (m) return m[1].trim();
  }
  if (node.type === "import_declaration" || node.type === "import_or_export") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "identifier" || child.type === "string") {
        return source.slice(child.startIndex, child.endIndex);
      }
    }
  }
  if (node.type === "preproc_include") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "string_literal" || child.type === "system_lib_string") {
        return source.slice(child.startIndex, child.endIndex).replace(/[<>"]/g, "");
      }
    }
  }
  return null;
}
function stripQuotes(s) {
  return s.replace(/^['"`]|['"`]$/g, "");
}
function extractName(node, source, _lang, kind) {
  if (kind === "variable" || kind === "constant") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "variable_declarator") {
        for (let j = 0; j < child.childCount; j++) {
          const gc = child.child(j);
          if (gc.type === "identifier") return source.slice(gc.startIndex, gc.endIndex);
        }
      }
    }
  }
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (child.type === "var_spec" || child.type === "const_spec") {
      for (let j = 0; j < child.childCount; j++) {
        const gc = child.child(j);
        if (gc.type === "identifier") return source.slice(gc.startIndex, gc.endIndex);
      }
    }
  }
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (child.type === "identifier" || child.type === "property_identifier" || child.type === "type_identifier") {
      return source.slice(child.startIndex, child.endIndex);
    }
  }
  if (node.type === "assignment") {
    const left = node.child(0);
    if (left && left.type === "identifier") {
      return source.slice(left.startIndex, left.endIndex);
    }
  }
  return null;
}
function extractSignature(node, source, kind) {
  if (kind === "function" || kind === "method") {
    const text2 = source.slice(node.startIndex, node.endIndex);
    const bodyStart = text2.search(/\s*[\{:]\s*\n|=>|{/);
    const header = bodyStart > 0 ? text2.slice(0, bodyStart).trim() : text2.split("\n")[0].trim();
    return header.length > 150 ? header.slice(0, 150) + "\u2026" : header || void 0;
  }
  const text = source.slice(node.startIndex, node.endIndex);
  const firstLine = text.split("\n")[0].trim();
  return firstLine.length > 120 ? firstLine.slice(0, 120) + "\u2026" : firstLine || void 0;
}
function extractVisibility(node, source, language) {
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (child.type === "accessibility_modifier") {
      const mod = source.slice(child.startIndex, child.endIndex);
      if (mod === "public") return "public";
      if (mod === "private") return "private";
      if (mod === "protected") return "protected";
    }
    if (child.type === "public") return "public";
    if (child.type === "private") return "private";
    if (child.type === "protected") return "protected";
    if (child.type === "internal") return "internal";
  }
  if (language === "rust") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      if (child.type === "visibility_modifier") {
        const v = source.slice(child.startIndex, child.endIndex);
        return v.startsWith("pub") ? "public" : "private";
      }
    }
    return "private";
  }
  if (language === "csharp") return "private";
  if (language === "php") return "public";
  if (language === "swift") {
    for (let i = 0; i < node.childCount; i++) {
      const child = node.child(i);
      const t = child.type;
      if (t === "fileprivate") return "private";
    }
    return "internal";
  }
  if (language === "python") {
    const name = extractName(node, source, language, "function");
    if (name?.startsWith("_") && !name.startsWith("__")) return "protected";
    if (name?.startsWith("__")) return "private";
    return "public";
  }
  return void 0;
}
function extractDocstring(node, source) {
  const commentTypes = /* @__PURE__ */ new Set(["comment", "block_comment", "line_comment", "documentation_comment"]);
  const commentLines = [];
  let sibling = node.previousNamedSibling;
  while (sibling && commentTypes.has(sibling.type)) {
    commentLines.unshift(source.slice(sibling.startIndex, sibling.endIndex));
    sibling = sibling.previousNamedSibling;
  }
  if (commentLines.length === 0) return void 0;
  const cleaned = commentLines.join("\n").replace(/^\/\*+\s*/gm, "").replace(/\s*\*+\/\s*$/gm, "").replace(/^\s*\*\s?/gm, "").replace(/^\/\/\s?/gm, "").trim();
  return cleaned.length > 0 ? cleaned : void 0;
}
function isExported(node) {
  let current = node.parent;
  while (current) {
    if (current.type === "export_statement") return true;
    if (current.type === "function_body" || current.type === "class_body" || current.type === "statement_block") break;
    current = current.parent;
  }
  return false;
}
function isAsync(node) {
  for (let i = 0; i < node.childCount; i++) {
    if (node.child(i).type === "async") return true;
  }
  return false;
}
function isStatic(node) {
  for (let i = 0; i < node.childCount; i++) {
    if (node.child(i).type === "static") return true;
  }
  return false;
}
const CALL_NODE_TYPES = /* @__PURE__ */ new Set([
  "call_expression",
  // JS/TS/Go/Rust/Swift/Kotlin/Dart/C/C++
  "invocation_expression",
  // C#
  "method_invocation",
  // Java
  "call",
  // Python/Ruby/Elixir (function calls in bodies)
  "function_call_expression"
  // PHP
]);
function extractCallName(node, source) {
  for (const field of ["name", "method", "function", "target"]) {
    const f = node.childForFieldName?.(field);
    if (f) {
      const t = f.type;
      if (t === "identifier" || t === "name" || t === "property_identifier" || t === "type_identifier") {
        const text = source.slice(f.startIndex, f.endIndex).trim();
        if (text && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(text)) return text;
      }
    }
  }
  const funcNode = node.child(0);
  if (funcNode) {
    const rawName = source.slice(funcNode.startIndex, funcNode.endIndex).split("(")[0].trim();
    if (rawName && rawName.length < 100) {
      const calleeName = rawName.split(".").pop().trim();
      if (calleeName && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(calleeName)) return calleeName;
    }
  }
  return null;
}
function collectCallRefs(node, source, sourceId, unresolvedRefs) {
  walkForCalls(node, source, sourceId, unresolvedRefs);
}
function walkForCalls(node, source, sourceId, unresolvedRefs) {
  if (CALL_NODE_TYPES.has(node.type)) {
    const calleeName = extractCallName(node, source);
    if (calleeName) {
      unresolvedRefs.push({
        sourceId,
        refName: calleeName,
        refKind: "function",
        line: node.startPosition.row + 1,
        column: node.startPosition.column
      });
    }
  }
  for (let i = 0; i < node.childCount; i++) {
    walkForCalls(node.child(i), source, sourceId, unresolvedRefs);
  }
}
function extractTypeName(node, source) {
  const t = node.type;
  if (t === "identifier" || t === "type_identifier" || t === "name") {
    return source.slice(node.startIndex, node.endIndex).trim() || null;
  }
  if (t === "qualified_name" || t === "generic_name" || t === "scoped_type_identifier") {
    for (let i = node.childCount - 1; i >= 0; i--) {
      const child = node.child(i);
      if (child.type === "identifier" || child.type === "type_identifier" || child.type === "name") {
        return source.slice(child.startIndex, child.endIndex).trim() || null;
      }
    }
  }
  return null;
}
function extractInheritance(node, source, language, classNodeId, unresolvedRefs) {
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i);
    if (language === "csharp" && child.type === "base_list") {
      for (let j = 0; j < child.childCount; j++) {
        const item = child.child(j);
        const name = extractTypeName(item, source);
        if (name) {
          unresolvedRefs.push({
            sourceId: classNodeId,
            refName: name,
            // In C# both classes and interfaces appear in the same base_list;
            // we emit 'extends' for all — the resolver maps it to the extends edge
            // which covers both parent classes and parent interfaces structurally.
            refKind: "extends",
            line: item.startPosition.row + 1,
            column: item.startPosition.column
          });
        }
      }
    }
    if (language === "java") {
      if (child.type === "superclass") {
        const typeNode = child.namedChild?.(0);
        if (typeNode) {
          const name = extractTypeName(typeNode, source);
          if (name) unresolvedRefs.push({ sourceId: classNodeId, refName: name, refKind: "extends", line: child.startPosition.row + 1, column: child.startPosition.column });
        }
      }
      if (child.type === "super_interfaces" || child.type === "extends_interfaces") {
        const typeList = child.namedChild?.(0);
        if (typeList) {
          const count = typeList.namedChildCount ?? 0;
          for (let j = 0; j < count; j++) {
            const typeNode = typeList.namedChild(j);
            if (typeNode) {
              const name = extractTypeName(typeNode, source);
              if (name) {
                unresolvedRefs.push({
                  sourceId: classNodeId,
                  refName: name,
                  refKind: child.type === "extends_interfaces" ? "extends" : "implements",
                  line: typeNode.startPosition.row + 1,
                  column: typeNode.startPosition.column
                });
              }
            }
          }
        }
      }
    }
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  extractFile,
  makeNodeId
});
//# sourceMappingURL=extractor.js.map
