@kkvcrobatz107/codegraph 0.9.6-pkm.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (501) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +595 -0
  3. package/dist/bin/codegraph.d.ts +25 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +1563 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/node-version-check.d.ts +37 -0
  8. package/dist/bin/node-version-check.d.ts.map +1 -0
  9. package/dist/bin/node-version-check.js +79 -0
  10. package/dist/bin/node-version-check.js.map +1 -0
  11. package/dist/bin/uninstall.d.ts +14 -0
  12. package/dist/bin/uninstall.d.ts.map +1 -0
  13. package/dist/bin/uninstall.js +36 -0
  14. package/dist/bin/uninstall.js.map +1 -0
  15. package/dist/context/formatter.d.ts +30 -0
  16. package/dist/context/formatter.d.ts.map +1 -0
  17. package/dist/context/formatter.js +244 -0
  18. package/dist/context/formatter.js.map +1 -0
  19. package/dist/context/index.d.ts +110 -0
  20. package/dist/context/index.d.ts.map +1 -0
  21. package/dist/context/index.js +1169 -0
  22. package/dist/context/index.js.map +1 -0
  23. package/dist/db/index.d.ts +101 -0
  24. package/dist/db/index.d.ts.map +1 -0
  25. package/dist/db/index.js +251 -0
  26. package/dist/db/index.js.map +1 -0
  27. package/dist/db/migrations.d.ts +44 -0
  28. package/dist/db/migrations.d.ts.map +1 -0
  29. package/dist/db/migrations.js +131 -0
  30. package/dist/db/migrations.js.map +1 -0
  31. package/dist/db/queries.d.ts +281 -0
  32. package/dist/db/queries.d.ts.map +1 -0
  33. package/dist/db/queries.js +1300 -0
  34. package/dist/db/queries.js.map +1 -0
  35. package/dist/db/schema.sql +151 -0
  36. package/dist/db/sqlite-adapter.d.ts +46 -0
  37. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  38. package/dist/db/sqlite-adapter.js +114 -0
  39. package/dist/db/sqlite-adapter.js.map +1 -0
  40. package/dist/directory.d.ts +57 -0
  41. package/dist/directory.d.ts.map +1 -0
  42. package/dist/directory.js +264 -0
  43. package/dist/directory.js.map +1 -0
  44. package/dist/errors.d.ts +136 -0
  45. package/dist/errors.d.ts.map +1 -0
  46. package/dist/errors.js +219 -0
  47. package/dist/errors.js.map +1 -0
  48. package/dist/extraction/dfm-extractor.d.ts +31 -0
  49. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  50. package/dist/extraction/dfm-extractor.js +151 -0
  51. package/dist/extraction/dfm-extractor.js.map +1 -0
  52. package/dist/extraction/grammars.d.ts +90 -0
  53. package/dist/extraction/grammars.d.ts.map +1 -0
  54. package/dist/extraction/grammars.js +407 -0
  55. package/dist/extraction/grammars.js.map +1 -0
  56. package/dist/extraction/index.d.ts +138 -0
  57. package/dist/extraction/index.d.ts.map +1 -0
  58. package/dist/extraction/index.js +1378 -0
  59. package/dist/extraction/index.js.map +1 -0
  60. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  61. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  62. package/dist/extraction/languages/c-cpp.js +171 -0
  63. package/dist/extraction/languages/c-cpp.js.map +1 -0
  64. package/dist/extraction/languages/csharp.d.ts +3 -0
  65. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  66. package/dist/extraction/languages/csharp.js +73 -0
  67. package/dist/extraction/languages/csharp.js.map +1 -0
  68. package/dist/extraction/languages/dart.d.ts +3 -0
  69. package/dist/extraction/languages/dart.d.ts.map +1 -0
  70. package/dist/extraction/languages/dart.js +192 -0
  71. package/dist/extraction/languages/dart.js.map +1 -0
  72. package/dist/extraction/languages/go.d.ts +3 -0
  73. package/dist/extraction/languages/go.d.ts.map +1 -0
  74. package/dist/extraction/languages/go.js +70 -0
  75. package/dist/extraction/languages/go.js.map +1 -0
  76. package/dist/extraction/languages/index.d.ts +10 -0
  77. package/dist/extraction/languages/index.d.ts.map +1 -0
  78. package/dist/extraction/languages/index.js +51 -0
  79. package/dist/extraction/languages/index.js.map +1 -0
  80. package/dist/extraction/languages/java.d.ts +3 -0
  81. package/dist/extraction/languages/java.d.ts.map +1 -0
  82. package/dist/extraction/languages/java.js +70 -0
  83. package/dist/extraction/languages/java.js.map +1 -0
  84. package/dist/extraction/languages/javascript.d.ts +3 -0
  85. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  86. package/dist/extraction/languages/javascript.js +90 -0
  87. package/dist/extraction/languages/javascript.js.map +1 -0
  88. package/dist/extraction/languages/kotlin.d.ts +3 -0
  89. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  90. package/dist/extraction/languages/kotlin.js +259 -0
  91. package/dist/extraction/languages/kotlin.js.map +1 -0
  92. package/dist/extraction/languages/lua.d.ts +3 -0
  93. package/dist/extraction/languages/lua.d.ts.map +1 -0
  94. package/dist/extraction/languages/lua.js +150 -0
  95. package/dist/extraction/languages/lua.js.map +1 -0
  96. package/dist/extraction/languages/luau.d.ts +3 -0
  97. package/dist/extraction/languages/luau.d.ts.map +1 -0
  98. package/dist/extraction/languages/luau.js +37 -0
  99. package/dist/extraction/languages/luau.js.map +1 -0
  100. package/dist/extraction/languages/objc.d.ts +3 -0
  101. package/dist/extraction/languages/objc.d.ts.map +1 -0
  102. package/dist/extraction/languages/objc.js +133 -0
  103. package/dist/extraction/languages/objc.js.map +1 -0
  104. package/dist/extraction/languages/pascal.d.ts +3 -0
  105. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  106. package/dist/extraction/languages/pascal.js +66 -0
  107. package/dist/extraction/languages/pascal.js.map +1 -0
  108. package/dist/extraction/languages/php.d.ts +3 -0
  109. package/dist/extraction/languages/php.d.ts.map +1 -0
  110. package/dist/extraction/languages/php.js +107 -0
  111. package/dist/extraction/languages/php.js.map +1 -0
  112. package/dist/extraction/languages/python.d.ts +3 -0
  113. package/dist/extraction/languages/python.d.ts.map +1 -0
  114. package/dist/extraction/languages/python.js +56 -0
  115. package/dist/extraction/languages/python.js.map +1 -0
  116. package/dist/extraction/languages/ruby.d.ts +3 -0
  117. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  118. package/dist/extraction/languages/ruby.js +114 -0
  119. package/dist/extraction/languages/ruby.js.map +1 -0
  120. package/dist/extraction/languages/rust.d.ts +3 -0
  121. package/dist/extraction/languages/rust.d.ts.map +1 -0
  122. package/dist/extraction/languages/rust.js +109 -0
  123. package/dist/extraction/languages/rust.js.map +1 -0
  124. package/dist/extraction/languages/scala.d.ts +3 -0
  125. package/dist/extraction/languages/scala.d.ts.map +1 -0
  126. package/dist/extraction/languages/scala.js +139 -0
  127. package/dist/extraction/languages/scala.js.map +1 -0
  128. package/dist/extraction/languages/swift.d.ts +3 -0
  129. package/dist/extraction/languages/swift.d.ts.map +1 -0
  130. package/dist/extraction/languages/swift.js +91 -0
  131. package/dist/extraction/languages/swift.js.map +1 -0
  132. package/dist/extraction/languages/typescript.d.ts +3 -0
  133. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  134. package/dist/extraction/languages/typescript.js +129 -0
  135. package/dist/extraction/languages/typescript.js.map +1 -0
  136. package/dist/extraction/liquid-extractor.d.ts +52 -0
  137. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  138. package/dist/extraction/liquid-extractor.js +313 -0
  139. package/dist/extraction/liquid-extractor.js.map +1 -0
  140. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  141. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  142. package/dist/extraction/mybatis-extractor.js +198 -0
  143. package/dist/extraction/mybatis-extractor.js.map +1 -0
  144. package/dist/extraction/parse-worker.d.ts +8 -0
  145. package/dist/extraction/parse-worker.d.ts.map +1 -0
  146. package/dist/extraction/parse-worker.js +94 -0
  147. package/dist/extraction/parse-worker.js.map +1 -0
  148. package/dist/extraction/svelte-extractor.d.ts +56 -0
  149. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  150. package/dist/extraction/svelte-extractor.js +272 -0
  151. package/dist/extraction/svelte-extractor.js.map +1 -0
  152. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  153. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  154. package/dist/extraction/tree-sitter-helpers.js +103 -0
  155. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  156. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  157. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  158. package/dist/extraction/tree-sitter-types.js +10 -0
  159. package/dist/extraction/tree-sitter-types.js.map +1 -0
  160. package/dist/extraction/tree-sitter.d.ts +291 -0
  161. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  162. package/dist/extraction/tree-sitter.js +2961 -0
  163. package/dist/extraction/tree-sitter.js.map +1 -0
  164. package/dist/extraction/vue-extractor.d.ts +36 -0
  165. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  166. package/dist/extraction/vue-extractor.js +163 -0
  167. package/dist/extraction/vue-extractor.js.map +1 -0
  168. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  169. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  170. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  171. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  172. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  173. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  174. package/dist/extraction/wasm-runtime-flags.js +105 -0
  175. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  176. package/dist/graph/index.d.ts +8 -0
  177. package/dist/graph/index.d.ts.map +1 -0
  178. package/dist/graph/index.js +13 -0
  179. package/dist/graph/index.js.map +1 -0
  180. package/dist/graph/queries.d.ts +106 -0
  181. package/dist/graph/queries.d.ts.map +1 -0
  182. package/dist/graph/queries.js +366 -0
  183. package/dist/graph/queries.js.map +1 -0
  184. package/dist/graph/traversal.d.ts +127 -0
  185. package/dist/graph/traversal.d.ts.map +1 -0
  186. package/dist/graph/traversal.js +528 -0
  187. package/dist/graph/traversal.js.map +1 -0
  188. package/dist/index.d.ts +460 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +863 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/installer/claude-md-template.d.ts +14 -0
  193. package/dist/installer/claude-md-template.d.ts.map +1 -0
  194. package/dist/installer/claude-md-template.js +21 -0
  195. package/dist/installer/claude-md-template.js.map +1 -0
  196. package/dist/installer/config-writer.d.ts +29 -0
  197. package/dist/installer/config-writer.d.ts.map +1 -0
  198. package/dist/installer/config-writer.js +111 -0
  199. package/dist/installer/config-writer.js.map +1 -0
  200. package/dist/installer/index.d.ts +117 -0
  201. package/dist/installer/index.d.ts.map +1 -0
  202. package/dist/installer/index.js +528 -0
  203. package/dist/installer/index.js.map +1 -0
  204. package/dist/installer/instructions-template.d.ts +28 -0
  205. package/dist/installer/instructions-template.d.ts.map +1 -0
  206. package/dist/installer/instructions-template.js +65 -0
  207. package/dist/installer/instructions-template.js.map +1 -0
  208. package/dist/installer/targets/antigravity.d.ts +57 -0
  209. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  210. package/dist/installer/targets/antigravity.js +307 -0
  211. package/dist/installer/targets/antigravity.js.map +1 -0
  212. package/dist/installer/targets/claude.d.ts +47 -0
  213. package/dist/installer/targets/claude.d.ts.map +1 -0
  214. package/dist/installer/targets/claude.js +401 -0
  215. package/dist/installer/targets/claude.js.map +1 -0
  216. package/dist/installer/targets/codex.d.ts +18 -0
  217. package/dist/installer/targets/codex.d.ts.map +1 -0
  218. package/dist/installer/targets/codex.js +185 -0
  219. package/dist/installer/targets/codex.js.map +1 -0
  220. package/dist/installer/targets/cursor.d.ts +35 -0
  221. package/dist/installer/targets/cursor.d.ts.map +1 -0
  222. package/dist/installer/targets/cursor.js +283 -0
  223. package/dist/installer/targets/cursor.js.map +1 -0
  224. package/dist/installer/targets/gemini.d.ts +26 -0
  225. package/dist/installer/targets/gemini.d.ts.map +1 -0
  226. package/dist/installer/targets/gemini.js +165 -0
  227. package/dist/installer/targets/gemini.js.map +1 -0
  228. package/dist/installer/targets/hermes.d.ts +18 -0
  229. package/dist/installer/targets/hermes.d.ts.map +1 -0
  230. package/dist/installer/targets/hermes.js +359 -0
  231. package/dist/installer/targets/hermes.js.map +1 -0
  232. package/dist/installer/targets/kiro.d.ts +27 -0
  233. package/dist/installer/targets/kiro.d.ts.map +1 -0
  234. package/dist/installer/targets/kiro.js +196 -0
  235. package/dist/installer/targets/kiro.js.map +1 -0
  236. package/dist/installer/targets/opencode.d.ts +30 -0
  237. package/dist/installer/targets/opencode.d.ts.map +1 -0
  238. package/dist/installer/targets/opencode.js +235 -0
  239. package/dist/installer/targets/opencode.js.map +1 -0
  240. package/dist/installer/targets/registry.d.ts +35 -0
  241. package/dist/installer/targets/registry.d.ts.map +1 -0
  242. package/dist/installer/targets/registry.js +91 -0
  243. package/dist/installer/targets/registry.js.map +1 -0
  244. package/dist/installer/targets/shared.d.ts +77 -0
  245. package/dist/installer/targets/shared.d.ts.map +1 -0
  246. package/dist/installer/targets/shared.js +246 -0
  247. package/dist/installer/targets/shared.js.map +1 -0
  248. package/dist/installer/targets/toml.d.ts +52 -0
  249. package/dist/installer/targets/toml.d.ts.map +1 -0
  250. package/dist/installer/targets/toml.js +147 -0
  251. package/dist/installer/targets/toml.js.map +1 -0
  252. package/dist/installer/targets/types.d.ts +116 -0
  253. package/dist/installer/targets/types.d.ts.map +1 -0
  254. package/dist/installer/targets/types.js +16 -0
  255. package/dist/installer/targets/types.js.map +1 -0
  256. package/dist/mcp/daemon-paths.d.ts +46 -0
  257. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  258. package/dist/mcp/daemon-paths.js +125 -0
  259. package/dist/mcp/daemon-paths.js.map +1 -0
  260. package/dist/mcp/daemon.d.ts +161 -0
  261. package/dist/mcp/daemon.d.ts.map +1 -0
  262. package/dist/mcp/daemon.js +403 -0
  263. package/dist/mcp/daemon.js.map +1 -0
  264. package/dist/mcp/engine.d.ts +100 -0
  265. package/dist/mcp/engine.d.ts.map +1 -0
  266. package/dist/mcp/engine.js +291 -0
  267. package/dist/mcp/engine.js.map +1 -0
  268. package/dist/mcp/index.d.ts +109 -0
  269. package/dist/mcp/index.d.ts.map +1 -0
  270. package/dist/mcp/index.js +470 -0
  271. package/dist/mcp/index.js.map +1 -0
  272. package/dist/mcp/proxy.d.ts +46 -0
  273. package/dist/mcp/proxy.d.ts.map +1 -0
  274. package/dist/mcp/proxy.js +276 -0
  275. package/dist/mcp/proxy.js.map +1 -0
  276. package/dist/mcp/server-instructions.d.ts +19 -0
  277. package/dist/mcp/server-instructions.d.ts.map +1 -0
  278. package/dist/mcp/server-instructions.js +73 -0
  279. package/dist/mcp/server-instructions.js.map +1 -0
  280. package/dist/mcp/session.d.ts +67 -0
  281. package/dist/mcp/session.d.ts.map +1 -0
  282. package/dist/mcp/session.js +276 -0
  283. package/dist/mcp/session.js.map +1 -0
  284. package/dist/mcp/tools.d.ts +385 -0
  285. package/dist/mcp/tools.d.ts.map +1 -0
  286. package/dist/mcp/tools.js +2545 -0
  287. package/dist/mcp/tools.js.map +1 -0
  288. package/dist/mcp/transport.d.ts +188 -0
  289. package/dist/mcp/transport.d.ts.map +1 -0
  290. package/dist/mcp/transport.js +343 -0
  291. package/dist/mcp/transport.js.map +1 -0
  292. package/dist/mcp/version.d.ts +19 -0
  293. package/dist/mcp/version.d.ts.map +1 -0
  294. package/dist/mcp/version.js +71 -0
  295. package/dist/mcp/version.js.map +1 -0
  296. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  297. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  298. package/dist/resolution/callback-synthesizer.js +924 -0
  299. package/dist/resolution/callback-synthesizer.js.map +1 -0
  300. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  301. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  302. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  303. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  304. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  305. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  306. package/dist/resolution/frameworks/csharp.js +241 -0
  307. package/dist/resolution/frameworks/csharp.js.map +1 -0
  308. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  309. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  310. package/dist/resolution/frameworks/drupal.js +367 -0
  311. package/dist/resolution/frameworks/drupal.js.map +1 -0
  312. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  313. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  314. package/dist/resolution/frameworks/expo-modules.js +143 -0
  315. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  316. package/dist/resolution/frameworks/express.d.ts +8 -0
  317. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  318. package/dist/resolution/frameworks/express.js +308 -0
  319. package/dist/resolution/frameworks/express.js.map +1 -0
  320. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  321. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  322. package/dist/resolution/frameworks/fabric.js +354 -0
  323. package/dist/resolution/frameworks/fabric.js.map +1 -0
  324. package/dist/resolution/frameworks/go.d.ts +8 -0
  325. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  326. package/dist/resolution/frameworks/go.js +161 -0
  327. package/dist/resolution/frameworks/go.js.map +1 -0
  328. package/dist/resolution/frameworks/index.d.ts +48 -0
  329. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  330. package/dist/resolution/frameworks/index.js +161 -0
  331. package/dist/resolution/frameworks/index.js.map +1 -0
  332. package/dist/resolution/frameworks/java.d.ts +8 -0
  333. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  334. package/dist/resolution/frameworks/java.js +504 -0
  335. package/dist/resolution/frameworks/java.js.map +1 -0
  336. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  337. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  338. package/dist/resolution/frameworks/laravel.js +257 -0
  339. package/dist/resolution/frameworks/laravel.js.map +1 -0
  340. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  341. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  342. package/dist/resolution/frameworks/nestjs.js +698 -0
  343. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  344. package/dist/resolution/frameworks/play.d.ts +19 -0
  345. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  346. package/dist/resolution/frameworks/play.js +111 -0
  347. package/dist/resolution/frameworks/play.js.map +1 -0
  348. package/dist/resolution/frameworks/python.d.ts +10 -0
  349. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  350. package/dist/resolution/frameworks/python.js +396 -0
  351. package/dist/resolution/frameworks/python.js.map +1 -0
  352. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  353. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  354. package/dist/resolution/frameworks/react-native.js +360 -0
  355. package/dist/resolution/frameworks/react-native.js.map +1 -0
  356. package/dist/resolution/frameworks/react.d.ts +8 -0
  357. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  358. package/dist/resolution/frameworks/react.js +365 -0
  359. package/dist/resolution/frameworks/react.js.map +1 -0
  360. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  361. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  362. package/dist/resolution/frameworks/ruby.js +302 -0
  363. package/dist/resolution/frameworks/ruby.js.map +1 -0
  364. package/dist/resolution/frameworks/rust.d.ts +8 -0
  365. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  366. package/dist/resolution/frameworks/rust.js +304 -0
  367. package/dist/resolution/frameworks/rust.js.map +1 -0
  368. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  369. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  370. package/dist/resolution/frameworks/svelte.js +249 -0
  371. package/dist/resolution/frameworks/svelte.js.map +1 -0
  372. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  373. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  374. package/dist/resolution/frameworks/swift-objc.js +252 -0
  375. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  376. package/dist/resolution/frameworks/swift.d.ts +10 -0
  377. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  378. package/dist/resolution/frameworks/swift.js +400 -0
  379. package/dist/resolution/frameworks/swift.js.map +1 -0
  380. package/dist/resolution/frameworks/vue.d.ts +9 -0
  381. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  382. package/dist/resolution/frameworks/vue.js +306 -0
  383. package/dist/resolution/frameworks/vue.js.map +1 -0
  384. package/dist/resolution/go-module.d.ts +26 -0
  385. package/dist/resolution/go-module.d.ts.map +1 -0
  386. package/dist/resolution/go-module.js +78 -0
  387. package/dist/resolution/go-module.js.map +1 -0
  388. package/dist/resolution/import-resolver.d.ts +68 -0
  389. package/dist/resolution/import-resolver.d.ts.map +1 -0
  390. package/dist/resolution/import-resolver.js +1231 -0
  391. package/dist/resolution/import-resolver.js.map +1 -0
  392. package/dist/resolution/index.d.ts +116 -0
  393. package/dist/resolution/index.d.ts.map +1 -0
  394. package/dist/resolution/index.js +878 -0
  395. package/dist/resolution/index.js.map +1 -0
  396. package/dist/resolution/lru-cache.d.ts +24 -0
  397. package/dist/resolution/lru-cache.d.ts.map +1 -0
  398. package/dist/resolution/lru-cache.js +62 -0
  399. package/dist/resolution/lru-cache.js.map +1 -0
  400. package/dist/resolution/name-matcher.d.ts +32 -0
  401. package/dist/resolution/name-matcher.d.ts.map +1 -0
  402. package/dist/resolution/name-matcher.js +596 -0
  403. package/dist/resolution/name-matcher.js.map +1 -0
  404. package/dist/resolution/path-aliases.d.ts +68 -0
  405. package/dist/resolution/path-aliases.d.ts.map +1 -0
  406. package/dist/resolution/path-aliases.js +238 -0
  407. package/dist/resolution/path-aliases.js.map +1 -0
  408. package/dist/resolution/strip-comments.d.ts +27 -0
  409. package/dist/resolution/strip-comments.d.ts.map +1 -0
  410. package/dist/resolution/strip-comments.js +441 -0
  411. package/dist/resolution/strip-comments.js.map +1 -0
  412. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  413. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  414. package/dist/resolution/swift-objc-bridge.js +256 -0
  415. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  416. package/dist/resolution/types.d.ts +209 -0
  417. package/dist/resolution/types.d.ts.map +1 -0
  418. package/dist/resolution/types.js +8 -0
  419. package/dist/resolution/types.js.map +1 -0
  420. package/dist/search/query-parser.d.ts +57 -0
  421. package/dist/search/query-parser.d.ts.map +1 -0
  422. package/dist/search/query-parser.js +177 -0
  423. package/dist/search/query-parser.js.map +1 -0
  424. package/dist/search/query-utils.d.ts +53 -0
  425. package/dist/search/query-utils.d.ts.map +1 -0
  426. package/dist/search/query-utils.js +350 -0
  427. package/dist/search/query-utils.js.map +1 -0
  428. package/dist/sync/git-hooks.d.ts +45 -0
  429. package/dist/sync/git-hooks.d.ts.map +1 -0
  430. package/dist/sync/git-hooks.js +223 -0
  431. package/dist/sync/git-hooks.js.map +1 -0
  432. package/dist/sync/index.d.ts +19 -0
  433. package/dist/sync/index.d.ts.map +1 -0
  434. package/dist/sync/index.js +35 -0
  435. package/dist/sync/index.js.map +1 -0
  436. package/dist/sync/watch-policy.d.ts +48 -0
  437. package/dist/sync/watch-policy.d.ts.map +1 -0
  438. package/dist/sync/watch-policy.js +124 -0
  439. package/dist/sync/watch-policy.js.map +1 -0
  440. package/dist/sync/watcher.d.ts +191 -0
  441. package/dist/sync/watcher.d.ts.map +1 -0
  442. package/dist/sync/watcher.js +398 -0
  443. package/dist/sync/watcher.js.map +1 -0
  444. package/dist/sync/worktree.d.ts +54 -0
  445. package/dist/sync/worktree.d.ts.map +1 -0
  446. package/dist/sync/worktree.js +136 -0
  447. package/dist/sync/worktree.js.map +1 -0
  448. package/dist/types.d.ts +369 -0
  449. package/dist/types.d.ts.map +1 -0
  450. package/dist/types.js +78 -0
  451. package/dist/types.js.map +1 -0
  452. package/dist/ui/glyphs.d.ts +42 -0
  453. package/dist/ui/glyphs.d.ts.map +1 -0
  454. package/dist/ui/glyphs.js +78 -0
  455. package/dist/ui/glyphs.js.map +1 -0
  456. package/dist/ui/shimmer-progress.d.ts +11 -0
  457. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  458. package/dist/ui/shimmer-progress.js +90 -0
  459. package/dist/ui/shimmer-progress.js.map +1 -0
  460. package/dist/ui/shimmer-worker.d.ts +2 -0
  461. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  462. package/dist/ui/shimmer-worker.js +118 -0
  463. package/dist/ui/shimmer-worker.js.map +1 -0
  464. package/dist/ui/types.d.ts +17 -0
  465. package/dist/ui/types.d.ts.map +1 -0
  466. package/dist/ui/types.js +3 -0
  467. package/dist/ui/types.js.map +1 -0
  468. package/dist/utils.d.ts +205 -0
  469. package/dist/utils.d.ts.map +1 -0
  470. package/dist/utils.js +549 -0
  471. package/dist/utils.js.map +1 -0
  472. package/package.json +59 -0
  473. package/scripts/add-lang/bench.sh +60 -0
  474. package/scripts/add-lang/check-grammar.mjs +75 -0
  475. package/scripts/add-lang/dump-ast.mjs +103 -0
  476. package/scripts/add-lang/verify-extraction.mjs +70 -0
  477. package/scripts/agent-eval/arms-F.sh +21 -0
  478. package/scripts/agent-eval/arms-matrix.sh +37 -0
  479. package/scripts/agent-eval/audit.sh +68 -0
  480. package/scripts/agent-eval/bench-readme.sh +28 -0
  481. package/scripts/agent-eval/block-read-hook.sh +19 -0
  482. package/scripts/agent-eval/hook-settings.json +15 -0
  483. package/scripts/agent-eval/itrun.sh +107 -0
  484. package/scripts/agent-eval/parse-arms.mjs +116 -0
  485. package/scripts/agent-eval/parse-bench-readme.mjs +67 -0
  486. package/scripts/agent-eval/parse-run.mjs +45 -0
  487. package/scripts/agent-eval/parse-session.mjs +93 -0
  488. package/scripts/agent-eval/probe-context.mjs +21 -0
  489. package/scripts/agent-eval/probe-explore.mjs +40 -0
  490. package/scripts/agent-eval/probe-node.mjs +20 -0
  491. package/scripts/agent-eval/probe-trace.mjs +20 -0
  492. package/scripts/agent-eval/run-agent.sh +34 -0
  493. package/scripts/agent-eval/run-all.sh +67 -0
  494. package/scripts/agent-eval/run-arms.sh +56 -0
  495. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  496. package/scripts/build-bundle.sh +118 -0
  497. package/scripts/extract-release-notes.mjs +130 -0
  498. package/scripts/local-install.sh +41 -0
  499. package/scripts/npm-shim.js +246 -0
  500. package/scripts/pack-npm.sh +95 -0
  501. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,2961 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-sitter Parser Wrapper
4
+ *
5
+ * Handles parsing source code and extracting structural information.
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.TreeSitterExtractor = exports.generateNodeId = void 0;
42
+ exports.extractFromSource = extractFromSource;
43
+ const path = __importStar(require("path"));
44
+ const grammars_1 = require("./grammars");
45
+ const tree_sitter_helpers_1 = require("./tree-sitter-helpers");
46
+ const languages_1 = require("./languages");
47
+ const liquid_extractor_1 = require("./liquid-extractor");
48
+ const svelte_extractor_1 = require("./svelte-extractor");
49
+ const dfm_extractor_1 = require("./dfm-extractor");
50
+ const vue_extractor_1 = require("./vue-extractor");
51
+ const mybatis_extractor_1 = require("./mybatis-extractor");
52
+ const frameworks_1 = require("../resolution/frameworks");
53
+ // Re-export for backward compatibility
54
+ var tree_sitter_helpers_2 = require("./tree-sitter-helpers");
55
+ Object.defineProperty(exports, "generateNodeId", { enumerable: true, get: function () { return tree_sitter_helpers_2.generateNodeId; } });
56
+ /**
57
+ * Extract the name from a node based on language
58
+ */
59
+ function extractName(node, source, extractor) {
60
+ const hookName = extractor.resolveName?.(node, source);
61
+ if (hookName)
62
+ return hookName;
63
+ // Try field name first
64
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, extractor.nameField);
65
+ if (nameNode) {
66
+ // Unwrap pointer_declarator(s) for C/C++ pointer return types
67
+ let resolved = nameNode;
68
+ while (resolved.type === 'pointer_declarator') {
69
+ const inner = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'declarator') || resolved.namedChild(0);
70
+ if (!inner)
71
+ break;
72
+ resolved = inner;
73
+ }
74
+ // Handle complex declarators (C/C++)
75
+ if (resolved.type === 'function_declarator' || resolved.type === 'declarator') {
76
+ const innerName = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'declarator') || resolved.namedChild(0);
77
+ return innerName ? (0, tree_sitter_helpers_1.getNodeText)(innerName, source) : (0, tree_sitter_helpers_1.getNodeText)(resolved, source);
78
+ }
79
+ // Lua: `function t.f()` / `function t:m()` — the name node is a dot/method
80
+ // index expression; the simple name is the trailing field/method (the table
81
+ // receiver is captured separately via getReceiverType).
82
+ if (resolved.type === 'dot_index_expression') {
83
+ const field = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'field');
84
+ if (field)
85
+ return (0, tree_sitter_helpers_1.getNodeText)(field, source);
86
+ }
87
+ if (resolved.type === 'method_index_expression') {
88
+ const method = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'method');
89
+ if (method)
90
+ return (0, tree_sitter_helpers_1.getNodeText)(method, source);
91
+ }
92
+ return (0, tree_sitter_helpers_1.getNodeText)(resolved, source);
93
+ }
94
+ // For Dart method_signature, look inside inner signature types
95
+ if (node.type === 'method_signature') {
96
+ for (let i = 0; i < node.namedChildCount; i++) {
97
+ const child = node.namedChild(i);
98
+ if (child && (child.type === 'function_signature' ||
99
+ child.type === 'getter_signature' ||
100
+ child.type === 'setter_signature' ||
101
+ child.type === 'constructor_signature' ||
102
+ child.type === 'factory_constructor_signature')) {
103
+ // Find identifier inside the inner signature
104
+ for (let j = 0; j < child.namedChildCount; j++) {
105
+ const inner = child.namedChild(j);
106
+ if (inner?.type === 'identifier') {
107
+ return (0, tree_sitter_helpers_1.getNodeText)(inner, source);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ // Arrow/function expressions get their name from the parent variable_declarator,
114
+ // not from identifiers in their body. Without this, single-expression arrow
115
+ // functions like `const fn = () => someIdentifier` get named "someIdentifier"
116
+ // instead of "fn", because the fallback below finds the body identifier.
117
+ if (node.type === 'arrow_function' || node.type === 'function_expression') {
118
+ return '<anonymous>';
119
+ }
120
+ // Fall back to first identifier child
121
+ for (let i = 0; i < node.namedChildCount; i++) {
122
+ const child = node.namedChild(i);
123
+ if (child &&
124
+ (child.type === 'identifier' ||
125
+ child.type === 'type_identifier' ||
126
+ child.type === 'simple_identifier' ||
127
+ child.type === 'constant')) {
128
+ return (0, tree_sitter_helpers_1.getNodeText)(child, source);
129
+ }
130
+ }
131
+ return '<anonymous>';
132
+ }
133
+ /**
134
+ * Tree-sitter node kinds that represent constructor invocations
135
+ * (`new Foo()` and friends). Used by extractInstantiation to emit
136
+ * an `instantiates` reference targeting the class name.
137
+ */
138
+ const INSTANTIATION_KINDS = new Set([
139
+ 'new_expression', // typescript / javascript / tsx / jsx
140
+ 'object_creation_expression', // java / c#
141
+ 'instance_creation_expression', // some grammars
142
+ ]);
143
+ /**
144
+ * TreeSitterExtractor - Main extraction class
145
+ */
146
+ class TreeSitterExtractor {
147
+ filePath;
148
+ language;
149
+ source;
150
+ tree = null;
151
+ nodes = [];
152
+ edges = [];
153
+ unresolvedReferences = [];
154
+ errors = [];
155
+ extractor = null;
156
+ nodeStack = []; // Stack of parent node IDs
157
+ methodIndex = null; // lookup key → node ID for Pascal defProc lookup
158
+ constructor(filePath, source, language) {
159
+ this.filePath = filePath;
160
+ this.source = source;
161
+ this.language = language || (0, grammars_1.detectLanguage)(filePath, source);
162
+ this.extractor = languages_1.EXTRACTORS[this.language] || null;
163
+ }
164
+ /**
165
+ * Parse and extract from the source code
166
+ */
167
+ extract() {
168
+ const startTime = Date.now();
169
+ if (!(0, grammars_1.isLanguageSupported)(this.language)) {
170
+ return {
171
+ nodes: [],
172
+ edges: [],
173
+ unresolvedReferences: [],
174
+ errors: [
175
+ {
176
+ message: `Unsupported language: ${this.language}`,
177
+ filePath: this.filePath,
178
+ severity: 'error',
179
+ code: 'unsupported_language',
180
+ },
181
+ ],
182
+ durationMs: Date.now() - startTime,
183
+ };
184
+ }
185
+ const parser = (0, grammars_1.getParser)(this.language);
186
+ if (!parser) {
187
+ return {
188
+ nodes: [],
189
+ edges: [],
190
+ unresolvedReferences: [],
191
+ errors: [
192
+ {
193
+ message: `Failed to get parser for language: ${this.language}`,
194
+ filePath: this.filePath,
195
+ severity: 'error',
196
+ code: 'parser_error',
197
+ },
198
+ ],
199
+ durationMs: Date.now() - startTime,
200
+ };
201
+ }
202
+ try {
203
+ this.tree = parser.parse(this.source) ?? null;
204
+ if (!this.tree) {
205
+ throw new Error('Parser returned null tree');
206
+ }
207
+ // Create file node representing the source file
208
+ const fileNode = {
209
+ id: `file:${this.filePath}`,
210
+ kind: 'file',
211
+ name: path.basename(this.filePath),
212
+ qualifiedName: this.filePath,
213
+ filePath: this.filePath,
214
+ language: this.language,
215
+ startLine: 1,
216
+ endLine: this.source.split('\n').length,
217
+ startColumn: 0,
218
+ endColumn: 0,
219
+ isExported: false,
220
+ updatedAt: Date.now(),
221
+ };
222
+ this.nodes.push(fileNode);
223
+ // Push file node onto stack so top-level declarations get contains edges
224
+ this.nodeStack.push(fileNode.id);
225
+ // File-level package declaration (Kotlin/Java). Creates an implicit
226
+ // `namespace` node wrapping every top-level declaration so their
227
+ // qualifiedName carries the FQN — required for cross-file import
228
+ // resolution on JVM languages where filename ≠ class name.
229
+ const packageNodeId = this.extractFilePackage(this.tree.rootNode);
230
+ if (packageNodeId)
231
+ this.nodeStack.push(packageNodeId);
232
+ this.visitNode(this.tree.rootNode);
233
+ if (packageNodeId)
234
+ this.nodeStack.pop();
235
+ this.nodeStack.pop();
236
+ }
237
+ catch (error) {
238
+ const msg = error instanceof Error ? error.message : String(error);
239
+ // WASM memory errors leave the module in a corrupted state — all subsequent
240
+ // parses would also fail. Re-throw so the worker can detect and crash,
241
+ // forcing a clean restart with a fresh heap.
242
+ if (msg.includes('memory access out of bounds') || msg.includes('out of memory')) {
243
+ throw error;
244
+ }
245
+ this.errors.push({
246
+ message: `Parse error: ${msg}`,
247
+ filePath: this.filePath,
248
+ severity: 'error',
249
+ code: 'parse_error',
250
+ });
251
+ }
252
+ finally {
253
+ // Free tree-sitter WASM memory immediately — trees hold native heap memory
254
+ // invisible to V8's GC that accumulates across thousands of files.
255
+ if (this.tree) {
256
+ this.tree.delete();
257
+ this.tree = null;
258
+ }
259
+ // Release source string to reduce GC pressure
260
+ this.source = '';
261
+ }
262
+ return {
263
+ nodes: this.nodes,
264
+ edges: this.edges,
265
+ unresolvedReferences: this.unresolvedReferences,
266
+ errors: this.errors,
267
+ durationMs: Date.now() - startTime,
268
+ };
269
+ }
270
+ /**
271
+ * Visit a node and extract information
272
+ */
273
+ visitNode(node) {
274
+ if (!this.extractor)
275
+ return;
276
+ const nodeType = node.type;
277
+ let skipChildren = false;
278
+ // Language-specific custom visitor hook
279
+ if (this.extractor.visitNode) {
280
+ const ctx = this.makeExtractorContext();
281
+ const handled = this.extractor.visitNode(node, ctx);
282
+ if (handled)
283
+ return;
284
+ }
285
+ // Pascal-specific AST handling
286
+ if (this.language === 'pascal') {
287
+ skipChildren = this.visitPascalNode(node);
288
+ if (skipChildren)
289
+ return;
290
+ }
291
+ // Check for function declarations
292
+ // For Python/Ruby, function_definition inside a class should be treated as method
293
+ if (this.extractor.functionTypes.includes(nodeType)) {
294
+ if (this.isInsideClassLikeNode() && this.extractor.methodTypes.includes(nodeType)) {
295
+ // Inside a class - treat as method
296
+ this.extractMethod(node);
297
+ skipChildren = true; // extractMethod visits children via visitFunctionBody
298
+ }
299
+ else {
300
+ this.extractFunction(node);
301
+ skipChildren = true; // extractFunction visits children via visitFunctionBody
302
+ }
303
+ }
304
+ // Check for class declarations
305
+ else if (this.extractor.classTypes.includes(nodeType)) {
306
+ // Some languages reuse class_declaration for structs/enums (e.g. Swift)
307
+ const classification = this.extractor.classifyClassNode?.(node) ?? 'class';
308
+ if (classification === 'struct') {
309
+ this.extractStruct(node);
310
+ }
311
+ else if (classification === 'enum') {
312
+ this.extractEnum(node);
313
+ }
314
+ else if (classification === 'interface') {
315
+ this.extractInterface(node);
316
+ }
317
+ else if (classification === 'trait') {
318
+ this.extractClass(node, 'trait');
319
+ }
320
+ else {
321
+ this.extractClass(node);
322
+ }
323
+ skipChildren = true; // extractClass visits body children
324
+ }
325
+ // Extra class node types (e.g. Dart mixin_declaration, extension_declaration)
326
+ else if (this.extractor.extraClassNodeTypes?.includes(nodeType)) {
327
+ this.extractClass(node);
328
+ skipChildren = true;
329
+ }
330
+ // Check for method declarations (only if not already handled by functionTypes)
331
+ else if (this.extractor.methodTypes.includes(nodeType)) {
332
+ this.extractMethod(node);
333
+ skipChildren = true; // extractMethod visits children via visitFunctionBody
334
+ }
335
+ // Check for interface/protocol/trait declarations
336
+ else if (this.extractor.interfaceTypes.includes(nodeType)) {
337
+ this.extractInterface(node);
338
+ skipChildren = true; // extractInterface visits body children
339
+ }
340
+ // Check for struct declarations
341
+ else if (this.extractor.structTypes.includes(nodeType)) {
342
+ this.extractStruct(node);
343
+ skipChildren = true; // extractStruct visits body children
344
+ }
345
+ // Check for enum declarations
346
+ else if (this.extractor.enumTypes.includes(nodeType)) {
347
+ this.extractEnum(node);
348
+ skipChildren = true; // extractEnum visits body children
349
+ }
350
+ // Check for type alias declarations (e.g. `type X = ...` in TypeScript)
351
+ // For Go, type_spec wraps struct/interface definitions — resolveTypeAliasKind
352
+ // detects these and extractTypeAlias creates the correct node kind.
353
+ else if (this.extractor.typeAliasTypes.includes(nodeType)) {
354
+ skipChildren = this.extractTypeAlias(node);
355
+ }
356
+ // Check for class properties (e.g. C# property_declaration)
357
+ else if (this.extractor.propertyTypes?.includes(nodeType) && this.isInsideClassLikeNode()) {
358
+ this.extractProperty(node);
359
+ skipChildren = true;
360
+ }
361
+ // Check for class fields (e.g. Java field_declaration, C# field_declaration)
362
+ else if (this.extractor.fieldTypes?.includes(nodeType) && this.isInsideClassLikeNode()) {
363
+ this.extractField(node);
364
+ skipChildren = true;
365
+ }
366
+ // Check for variable declarations (const, let, var, etc.)
367
+ // Only extract top-level variables (not inside functions/methods)
368
+ else if (this.extractor.variableTypes.includes(nodeType) && !this.isInsideClassLikeNode()) {
369
+ this.extractVariable(node);
370
+ skipChildren = true; // extractVariable handles children
371
+ }
372
+ // `export_statement` itself is not extracted — the walker descends
373
+ // into children, where the inner declaration (lexical_declaration,
374
+ // function_declaration, class_declaration, etc.) is dispatched to
375
+ // its own extractor. `isExported` walks the parent chain, so the
376
+ // exported flag is preserved automatically.
377
+ //
378
+ // Calling extractExportedVariables here AND descending caused every
379
+ // `export const X = ...` to produce two nodes for the same symbol —
380
+ // one kind:'variable' from extractExportedVariables and one
381
+ // kind:'constant' from extractVariable. The dedicated dispatch is
382
+ // the correct one (it picks kind from isConst, captures the
383
+ // initializer signature, and walks type annotations); the
384
+ // export-statement helper was redundant.
385
+ // Check for imports
386
+ else if (this.extractor.importTypes.includes(nodeType)) {
387
+ this.extractImport(node);
388
+ }
389
+ // Check for function calls
390
+ else if (this.extractor.callTypes.includes(nodeType)) {
391
+ this.extractCall(node);
392
+ }
393
+ // `new Foo(...)` / `Foo::new(...)` / object_creation_expression —
394
+ // produce an `instantiates` reference. Children still walked so
395
+ // nested calls inside the constructor args (`new Foo(bar())`) get
396
+ // their own `calls` refs.
397
+ else if (INSTANTIATION_KINDS.has(nodeType)) {
398
+ this.extractInstantiation(node);
399
+ // Java/C# `new T(...) { ... }` — anonymous class with body. Without
400
+ // extracting it as a class node + its methods, the interface→impl
401
+ // synthesizer (Phase 5.5) can't bridge T's abstract methods to the
402
+ // anonymous overrides, and an agent investigating a call through T
403
+ // (`strategy.iterator(...)` where strategy is a Strategy lambda body)
404
+ // has to Read the file to find the actual implementation.
405
+ const anonBody = this.findAnonymousClassBody(node);
406
+ if (anonBody) {
407
+ this.extractAnonymousClass(node, anonBody);
408
+ skipChildren = true;
409
+ }
410
+ }
411
+ // (Decorator handling lives inside the symbol-creating extractors
412
+ // — extractClass / extractFunction / extractProperty — because the
413
+ // decorator node sits BEFORE the symbol in the AST and the walker
414
+ // would otherwise see the wrong nodeStack head.)
415
+ // Rust: `impl Trait for Type { ... }` — creates implements edge from Type to Trait
416
+ else if (nodeType === 'impl_item') {
417
+ this.extractRustImplItem(node);
418
+ }
419
+ // TypeScript interface members: property_signature (`foo: T`, `foo?: T`)
420
+ // and method_signature (`foo(arg: A): R`) both carry type annotations the
421
+ // interface walker would otherwise drop. Extract them as `references`
422
+ // edges from the interface so resolvers can wire callers/impact for
423
+ // types that only appear in interface members.
424
+ else if ((nodeType === 'property_signature' || nodeType === 'method_signature') &&
425
+ this.isInsideClassLikeNode() &&
426
+ this.TYPE_ANNOTATION_LANGUAGES.has(this.language)) {
427
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
428
+ if (parentId) {
429
+ this.extractTypeAnnotations(node, parentId);
430
+ }
431
+ // don't skipChildren — nested signatures still need traversal
432
+ }
433
+ // Visit children (unless the extract method already visited them)
434
+ if (!skipChildren) {
435
+ for (let i = 0; i < node.namedChildCount; i++) {
436
+ const child = node.namedChild(i);
437
+ if (child) {
438
+ this.visitNode(child);
439
+ }
440
+ }
441
+ }
442
+ }
443
+ /**
444
+ * Create a Node object
445
+ */
446
+ createNode(kind, name, node, extra) {
447
+ // Skip nodes with empty/missing names — they are not meaningful symbols
448
+ // and would cause FK violations when edges reference them (see issue #42)
449
+ if (!name) {
450
+ return null;
451
+ }
452
+ const id = (0, tree_sitter_helpers_1.generateNodeId)(this.filePath, kind, name, node.startPosition.row + 1);
453
+ // Some grammars (e.g. Dart) model a function/method body as a *sibling* of
454
+ // the signature node, so the declaration node's own range is just the
455
+ // signature line. Extend endLine to the resolved body when it sits beyond
456
+ // the node so the node spans its body — required for any body-level analysis
457
+ // (callees, the callback synthesizer's body scan, context slices). Guarded to
458
+ // only ever extend: for child-body grammars the body is within range (no-op).
459
+ let endLine = node.endPosition.row + 1;
460
+ if (kind === 'function' || kind === 'method') {
461
+ const body = this.extractor?.resolveBody?.(node, this.extractor.bodyField);
462
+ if (body && body.endPosition.row + 1 > endLine) {
463
+ endLine = body.endPosition.row + 1;
464
+ }
465
+ }
466
+ const newNode = {
467
+ id,
468
+ kind,
469
+ name,
470
+ qualifiedName: this.buildQualifiedName(name),
471
+ filePath: this.filePath,
472
+ language: this.language,
473
+ startLine: node.startPosition.row + 1,
474
+ endLine,
475
+ startColumn: node.startPosition.column,
476
+ endColumn: node.endPosition.column,
477
+ updatedAt: Date.now(),
478
+ ...extra,
479
+ };
480
+ this.nodes.push(newNode);
481
+ // Add containment edge from parent
482
+ if (this.nodeStack.length > 0) {
483
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
484
+ if (parentId) {
485
+ this.edges.push({
486
+ source: parentId,
487
+ target: id,
488
+ kind: 'contains',
489
+ });
490
+ }
491
+ }
492
+ return newNode;
493
+ }
494
+ /**
495
+ * Find first named child whose type is in the given list.
496
+ * Used to locate inner type nodes (e.g. enum_specifier inside a typedef).
497
+ */
498
+ findChildByTypes(node, types) {
499
+ for (let i = 0; i < node.namedChildCount; i++) {
500
+ const child = node.namedChild(i);
501
+ if (child && types.includes(child.type))
502
+ return child;
503
+ }
504
+ return null;
505
+ }
506
+ /**
507
+ * Find a `packageTypes` child under the root, create a `namespace` node
508
+ * for it, and return its id so the caller can scope top-level
509
+ * declarations underneath. Returns null when no package header is
510
+ * present (script files, .kts without a package).
511
+ */
512
+ extractFilePackage(rootNode) {
513
+ const types = this.extractor?.packageTypes;
514
+ if (!types || types.length === 0 || !this.extractor?.extractPackage)
515
+ return null;
516
+ let pkgNode = null;
517
+ for (let i = 0; i < rootNode.namedChildCount; i++) {
518
+ const child = rootNode.namedChild(i);
519
+ if (child && types.includes(child.type)) {
520
+ pkgNode = child;
521
+ break;
522
+ }
523
+ }
524
+ if (!pkgNode)
525
+ return null;
526
+ const pkgName = this.extractor.extractPackage(pkgNode, this.source);
527
+ if (!pkgName)
528
+ return null;
529
+ const ns = this.createNode('namespace', pkgName, pkgNode);
530
+ return ns?.id ?? null;
531
+ }
532
+ /**
533
+ * Build qualified name from node stack
534
+ */
535
+ buildQualifiedName(name) {
536
+ // Build a qualified name from the semantic hierarchy only (no file path).
537
+ // The file path is stored separately in filePath and pollutes FTS if included here.
538
+ const parts = [];
539
+ for (const nodeId of this.nodeStack) {
540
+ const node = this.nodes.find((n) => n.id === nodeId);
541
+ if (node && node.kind !== 'file') {
542
+ parts.push(node.name);
543
+ }
544
+ }
545
+ parts.push(name);
546
+ return parts.join('::');
547
+ }
548
+ /**
549
+ * Build an ExtractorContext for passing to language-specific visitNode hooks.
550
+ */
551
+ makeExtractorContext() {
552
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
553
+ const self = this;
554
+ return {
555
+ createNode: (kind, name, node, extra) => self.createNode(kind, name, node, extra),
556
+ visitNode: (node) => self.visitNode(node),
557
+ visitFunctionBody: (body, functionId) => self.visitFunctionBody(body, functionId),
558
+ addUnresolvedReference: (ref) => self.unresolvedReferences.push(ref),
559
+ pushScope: (nodeId) => self.nodeStack.push(nodeId),
560
+ popScope: () => self.nodeStack.pop(),
561
+ get filePath() { return self.filePath; },
562
+ get source() { return self.source; },
563
+ get nodeStack() { return self.nodeStack; },
564
+ get nodes() { return self.nodes; },
565
+ };
566
+ }
567
+ /**
568
+ * Check if the current node stack indicates we are inside a class-like node
569
+ * (class, struct, interface, trait). File nodes do not count as class-like.
570
+ */
571
+ isInsideClassLikeNode() {
572
+ if (this.nodeStack.length === 0)
573
+ return false;
574
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
575
+ if (!parentId)
576
+ return false;
577
+ const parentNode = this.nodes.find((n) => n.id === parentId);
578
+ if (!parentNode)
579
+ return false;
580
+ return (parentNode.kind === 'class' ||
581
+ parentNode.kind === 'struct' ||
582
+ parentNode.kind === 'interface' ||
583
+ parentNode.kind === 'trait' ||
584
+ parentNode.kind === 'enum' ||
585
+ parentNode.kind === 'module');
586
+ }
587
+ /**
588
+ * Extract a function
589
+ */
590
+ extractFunction(node, nameOverride) {
591
+ if (!this.extractor)
592
+ return;
593
+ // If the language provides getReceiverType and this function has a receiver
594
+ // (e.g., Rust function_item inside an impl block), extract as method instead
595
+ if (this.extractor.getReceiverType?.(node, this.source)) {
596
+ this.extractMethod(node);
597
+ return;
598
+ }
599
+ // nameOverride is supplied only for explicitly-named anonymous functions the
600
+ // caller resolved itself (e.g. arrow values of exported-const object members
601
+ // — SvelteKit actions). Inline-object arrows reached by the general walker
602
+ // get no override, so they still fall through to the <anonymous> skip below.
603
+ let name = nameOverride ?? extractName(node, this.source, this.extractor);
604
+ // For arrow functions and function expressions assigned to variables,
605
+ // resolve the name from the parent variable_declarator.
606
+ // e.g. `export const useAuth = () => { ... }` — the arrow_function node
607
+ // has no `name` field; the name lives on the variable_declarator.
608
+ if (!nameOverride &&
609
+ name === '<anonymous>' &&
610
+ (node.type === 'arrow_function' || node.type === 'function_expression')) {
611
+ const parent = node.parent;
612
+ if (parent?.type === 'variable_declarator') {
613
+ const varName = (0, tree_sitter_helpers_1.getChildByField)(parent, 'name');
614
+ if (varName) {
615
+ name = (0, tree_sitter_helpers_1.getNodeText)(varName, this.source);
616
+ }
617
+ }
618
+ }
619
+ if (name === '<anonymous>')
620
+ return; // Skip anonymous functions
621
+ // Check for misparse artifacts (e.g. C++ macros causing "namespace detail" functions)
622
+ // Skip the node but still visit the body for calls and structural nodes
623
+ if (this.extractor.isMisparsedFunction?.(name, node)) {
624
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
625
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
626
+ if (body) {
627
+ this.visitFunctionBody(body, '');
628
+ }
629
+ return;
630
+ }
631
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
632
+ const signature = this.extractor.getSignature?.(node, this.source);
633
+ const visibility = this.extractor.getVisibility?.(node);
634
+ const isExported = this.extractor.isExported?.(node, this.source);
635
+ const isAsync = this.extractor.isAsync?.(node);
636
+ const isStatic = this.extractor.isStatic?.(node);
637
+ const funcNode = this.createNode('function', name, node, {
638
+ docstring,
639
+ signature,
640
+ visibility,
641
+ isExported,
642
+ isAsync,
643
+ isStatic,
644
+ });
645
+ if (!funcNode)
646
+ return;
647
+ // Extract type annotations (parameter types and return type)
648
+ this.extractTypeAnnotations(node, funcNode.id);
649
+ // Extract decorators applied to the function (rare in JS/TS but
650
+ // present in Python `@decorator def f():` and Java/Kotlin
651
+ // annotations on free functions).
652
+ this.extractDecoratorsFor(node, funcNode.id);
653
+ // Push to stack and visit body
654
+ this.nodeStack.push(funcNode.id);
655
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
656
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
657
+ if (body) {
658
+ this.visitFunctionBody(body, funcNode.id);
659
+ }
660
+ this.nodeStack.pop();
661
+ }
662
+ /**
663
+ * Extract a class
664
+ */
665
+ extractClass(node, kind = 'class') {
666
+ if (!this.extractor)
667
+ return;
668
+ const name = extractName(node, this.source, this.extractor);
669
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
670
+ const visibility = this.extractor.getVisibility?.(node);
671
+ const isExported = this.extractor.isExported?.(node, this.source);
672
+ const classNode = this.createNode(kind, name, node, {
673
+ docstring,
674
+ visibility,
675
+ isExported,
676
+ });
677
+ if (!classNode)
678
+ return;
679
+ // Extract extends/implements
680
+ this.extractInheritance(node, classNode.id);
681
+ // Extract decorators applied to the class (`@Foo class X {}`).
682
+ this.extractDecoratorsFor(node, classNode.id);
683
+ // Push to stack and visit body
684
+ this.nodeStack.push(classNode.id);
685
+ let body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
686
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
687
+ if (!body)
688
+ body = node;
689
+ // Visit all children for methods and properties
690
+ for (let i = 0; i < body.namedChildCount; i++) {
691
+ const child = body.namedChild(i);
692
+ if (child) {
693
+ this.visitNode(child);
694
+ }
695
+ }
696
+ this.nodeStack.pop();
697
+ }
698
+ /**
699
+ * Extract a method
700
+ */
701
+ extractMethod(node) {
702
+ if (!this.extractor)
703
+ return;
704
+ // For languages with receiver types (Go, Rust), include receiver in qualified name
705
+ // so FTS can match "scrapeLoop.run" → qualified_name "...::scrapeLoop::run"
706
+ const receiverType = this.extractor.getReceiverType?.(node, this.source);
707
+ // For most languages, only extract as method if inside a class-like node
708
+ // Languages with methodsAreTopLevel (e.g. Go) always treat them as methods
709
+ // Languages with getReceiverType (e.g. Rust) extract as method when receiver is found
710
+ if (!this.isInsideClassLikeNode() && !this.extractor.methodsAreTopLevel && !receiverType) {
711
+ // Skip method_definition nodes inside object literals (getters/setters/methods
712
+ // in inline objects). These are ephemeral and create noise (e.g., Svelte context
713
+ // objects: `ctx.set({ get view() { ... } })`).
714
+ if (node.parent?.type === 'object' || node.parent?.type === 'object_expression') {
715
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
716
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
717
+ if (body) {
718
+ this.visitFunctionBody(body, '');
719
+ }
720
+ return;
721
+ }
722
+ // Not inside a class-like node and no receiver type, treat as function
723
+ this.extractFunction(node);
724
+ return;
725
+ }
726
+ const name = extractName(node, this.source, this.extractor);
727
+ // Check for misparse artifacts (e.g. C++ "switch" inside macro-confused class body)
728
+ if (this.extractor.isMisparsedFunction?.(name, node)) {
729
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
730
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
731
+ if (body) {
732
+ this.visitFunctionBody(body, '');
733
+ }
734
+ return;
735
+ }
736
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
737
+ const signature = this.extractor.getSignature?.(node, this.source);
738
+ const visibility = this.extractor.getVisibility?.(node);
739
+ const isAsync = this.extractor.isAsync?.(node);
740
+ const isStatic = this.extractor.isStatic?.(node);
741
+ const extraProps = {
742
+ docstring,
743
+ signature,
744
+ visibility,
745
+ isAsync,
746
+ isStatic,
747
+ };
748
+ if (receiverType) {
749
+ extraProps.qualifiedName = `${receiverType}::${name}`;
750
+ }
751
+ const methodNode = this.createNode('method', name, node, extraProps);
752
+ if (!methodNode)
753
+ return;
754
+ // For methods with a receiver type but no class-like parent on the stack
755
+ // (e.g., Rust impl blocks), add a contains edge from the owning struct/trait
756
+ if (receiverType && !this.isInsideClassLikeNode()) {
757
+ const ownerNode = this.nodes.find((n) => n.name === receiverType &&
758
+ n.filePath === this.filePath &&
759
+ (n.kind === 'struct' || n.kind === 'class' || n.kind === 'enum' || n.kind === 'trait'));
760
+ if (ownerNode) {
761
+ this.edges.push({
762
+ source: ownerNode.id,
763
+ target: methodNode.id,
764
+ kind: 'contains',
765
+ });
766
+ }
767
+ }
768
+ // Extract type annotations (parameter types and return type)
769
+ this.extractTypeAnnotations(node, methodNode.id);
770
+ // Extract decorators (`@Get('/list') list() {}`).
771
+ this.extractDecoratorsFor(node, methodNode.id);
772
+ // Push to stack and visit body
773
+ this.nodeStack.push(methodNode.id);
774
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
775
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
776
+ if (body) {
777
+ this.visitFunctionBody(body, methodNode.id);
778
+ }
779
+ this.nodeStack.pop();
780
+ }
781
+ /**
782
+ * Extract an interface/protocol/trait
783
+ */
784
+ extractInterface(node) {
785
+ if (!this.extractor)
786
+ return;
787
+ const name = extractName(node, this.source, this.extractor);
788
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
789
+ const isExported = this.extractor.isExported?.(node, this.source);
790
+ const kind = this.extractor.interfaceKind ?? 'interface';
791
+ const interfaceNode = this.createNode(kind, name, node, {
792
+ docstring,
793
+ isExported,
794
+ });
795
+ if (!interfaceNode)
796
+ return;
797
+ // Extract extends (interface inheritance)
798
+ this.extractInheritance(node, interfaceNode.id);
799
+ // Visit body children for interface methods and nested types
800
+ this.nodeStack.push(interfaceNode.id);
801
+ let body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
802
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
803
+ if (!body)
804
+ body = node;
805
+ for (let i = 0; i < body.namedChildCount; i++) {
806
+ const child = body.namedChild(i);
807
+ if (child) {
808
+ this.visitNode(child);
809
+ }
810
+ }
811
+ this.nodeStack.pop();
812
+ }
813
+ /**
814
+ * Extract a struct
815
+ */
816
+ extractStruct(node) {
817
+ if (!this.extractor)
818
+ return;
819
+ // Skip forward declarations and type references (no body = not a definition)
820
+ const body = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
821
+ if (!body)
822
+ return;
823
+ const name = extractName(node, this.source, this.extractor);
824
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
825
+ const visibility = this.extractor.getVisibility?.(node);
826
+ const isExported = this.extractor.isExported?.(node, this.source);
827
+ const structNode = this.createNode('struct', name, node, {
828
+ docstring,
829
+ visibility,
830
+ isExported,
831
+ });
832
+ if (!structNode)
833
+ return;
834
+ // Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable)
835
+ this.extractInheritance(node, structNode.id);
836
+ // Push to stack for field extraction
837
+ this.nodeStack.push(structNode.id);
838
+ for (let i = 0; i < body.namedChildCount; i++) {
839
+ const child = body.namedChild(i);
840
+ if (child) {
841
+ this.visitNode(child);
842
+ }
843
+ }
844
+ this.nodeStack.pop();
845
+ }
846
+ /**
847
+ * Extract an enum
848
+ */
849
+ extractEnum(node) {
850
+ if (!this.extractor)
851
+ return;
852
+ // Skip forward declarations and type references (no body = not a definition)
853
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
854
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
855
+ if (!body)
856
+ return;
857
+ const name = extractName(node, this.source, this.extractor);
858
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
859
+ const visibility = this.extractor.getVisibility?.(node);
860
+ const isExported = this.extractor.isExported?.(node, this.source);
861
+ const enumNode = this.createNode('enum', name, node, {
862
+ docstring,
863
+ visibility,
864
+ isExported,
865
+ });
866
+ if (!enumNode)
867
+ return;
868
+ // Extract inheritance (e.g. Swift: enum AFError: Error)
869
+ this.extractInheritance(node, enumNode.id);
870
+ // Push to stack and visit body children (enum members, nested types, methods)
871
+ this.nodeStack.push(enumNode.id);
872
+ const memberTypes = this.extractor.enumMemberTypes;
873
+ for (let i = 0; i < body.namedChildCount; i++) {
874
+ const child = body.namedChild(i);
875
+ if (!child)
876
+ continue;
877
+ if (memberTypes?.includes(child.type)) {
878
+ this.extractEnumMembers(child);
879
+ }
880
+ else {
881
+ this.visitNode(child);
882
+ }
883
+ }
884
+ this.nodeStack.pop();
885
+ }
886
+ /**
887
+ * Extract enum member names from an enum member node.
888
+ * Handles multi-case declarations (Swift: `case put, delete`) and single-case patterns.
889
+ */
890
+ extractEnumMembers(node) {
891
+ // Try field-based name first (e.g. Rust enum_variant has a 'name' field)
892
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
893
+ if (nameNode) {
894
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source), node);
895
+ return;
896
+ }
897
+ // Check for identifier-like children (Swift: simple_identifier, TS: property_identifier)
898
+ let found = false;
899
+ for (let i = 0; i < node.namedChildCount; i++) {
900
+ const child = node.namedChild(i);
901
+ if (child && (child.type === 'simple_identifier' || child.type === 'identifier' || child.type === 'property_identifier')) {
902
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(child, this.source), child);
903
+ found = true;
904
+ }
905
+ }
906
+ // If the node itself IS the identifier (e.g. TS property_identifier directly in enum body)
907
+ if (!found && node.namedChildCount === 0) {
908
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(node, this.source), node);
909
+ }
910
+ }
911
+ /**
912
+ * Extract a class property declaration (e.g. C# `public string Name { get; set; }`).
913
+ * Extracts as 'property' kind node inside the owning class.
914
+ */
915
+ extractProperty(node) {
916
+ if (!this.extractor)
917
+ return;
918
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
919
+ const visibility = this.extractor.getVisibility?.(node);
920
+ const isStatic = this.extractor.isStatic?.(node) ?? false;
921
+ const hookName = this.extractor.extractPropertyName?.(node, this.source);
922
+ const nameNode = hookName
923
+ ? null
924
+ : (0, tree_sitter_helpers_1.getChildByField)(node, 'name') || node.namedChildren.find(c => c.type === 'identifier');
925
+ const name = hookName ?? (nameNode ? (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source) : null);
926
+ if (!name)
927
+ return;
928
+ // Get property type from the type child (first named child that isn't modifier or identifier)
929
+ const typeNode = node.namedChildren.find(c => c.type !== 'modifier' && c.type !== 'modifiers'
930
+ && c.type !== 'identifier' && c.type !== 'accessor_list'
931
+ && c.type !== 'accessors' && c.type !== 'equals_value_clause');
932
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
933
+ const signature = typeText ? `${typeText} ${name}` : name;
934
+ const propNode = this.createNode('property', name, node, {
935
+ docstring,
936
+ signature,
937
+ visibility,
938
+ isStatic,
939
+ });
940
+ // `@Inject() private svc: Foo` and similar — capture the
941
+ // decorator->target relationship for class properties too.
942
+ if (propNode) {
943
+ this.extractDecoratorsFor(node, propNode.id);
944
+ // Emit `references` edges from the property to types named in its
945
+ // type annotation (#381). The generic walker handles TS-style
946
+ // `type_annotation` children; the C# branch walks the `type` field.
947
+ this.extractTypeAnnotations(node, propNode.id);
948
+ }
949
+ }
950
+ /**
951
+ * Extract a class field declaration (e.g. Java field_declaration, C# field_declaration).
952
+ * Extracts each declarator as a 'field' kind node inside the owning class.
953
+ */
954
+ extractField(node) {
955
+ if (!this.extractor)
956
+ return;
957
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
958
+ const visibility = this.extractor.getVisibility?.(node);
959
+ const isStatic = this.extractor.isStatic?.(node) ?? false;
960
+ // Java field_declaration: "private final String name = value;" → variable_declarator(s) are direct children
961
+ // C# field_declaration: wraps in variable_declaration → variable_declarator(s)
962
+ let declarators = node.namedChildren.filter(c => c.type === 'variable_declarator');
963
+ // C#: look inside variable_declaration wrapper
964
+ if (declarators.length === 0) {
965
+ const varDecl = node.namedChildren.find(c => c.type === 'variable_declaration');
966
+ if (varDecl) {
967
+ declarators = varDecl.namedChildren.filter(c => c.type === 'variable_declarator');
968
+ }
969
+ }
970
+ // PHP property_declaration: property_element → variable_name → name
971
+ if (declarators.length === 0) {
972
+ const propElements = node.namedChildren.filter(c => c.type === 'property_element');
973
+ if (propElements.length > 0) {
974
+ // Get type annotation if present (e.g. "string", "int", "?Foo")
975
+ const typeNode = node.namedChildren.find(c => c.type !== 'visibility_modifier' && c.type !== 'static_modifier'
976
+ && c.type !== 'readonly_modifier' && c.type !== 'property_element'
977
+ && c.type !== 'var_modifier');
978
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
979
+ for (const elem of propElements) {
980
+ const varName = elem.namedChildren.find(c => c.type === 'variable_name');
981
+ const nameNode = varName?.namedChildren.find(c => c.type === 'name');
982
+ if (!nameNode)
983
+ continue;
984
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
985
+ const signature = typeText ? `${typeText} $${name}` : `$${name}`;
986
+ this.createNode('field', name, elem, {
987
+ docstring,
988
+ signature,
989
+ visibility,
990
+ isStatic,
991
+ });
992
+ }
993
+ return;
994
+ }
995
+ }
996
+ if (declarators.length > 0) {
997
+ // Get field type from the type child
998
+ // Java: type is a direct child of field_declaration
999
+ // C#: type is inside variable_declaration wrapper
1000
+ const varDecl = node.namedChildren.find(c => c.type === 'variable_declaration');
1001
+ const typeSearchNode = varDecl ?? node;
1002
+ const typeNode = typeSearchNode.namedChildren.find(c => c.type !== 'modifiers' && c.type !== 'modifier' && c.type !== 'variable_declarator'
1003
+ && c.type !== 'variable_declaration' && c.type !== 'marker_annotation' && c.type !== 'annotation');
1004
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
1005
+ for (const decl of declarators) {
1006
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(decl, 'name')
1007
+ || decl.namedChildren.find(c => c.type === 'identifier');
1008
+ if (!nameNode)
1009
+ continue;
1010
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1011
+ const signature = typeText ? `${typeText} ${name}` : name;
1012
+ const fieldNode = this.createNode('field', name, decl, {
1013
+ docstring,
1014
+ signature,
1015
+ visibility,
1016
+ isStatic,
1017
+ });
1018
+ // Java/Kotlin annotations / TS field decorators sit on the
1019
+ // outer field_declaration, not on the individual declarator.
1020
+ if (fieldNode) {
1021
+ this.extractDecoratorsFor(node, fieldNode.id);
1022
+ // Same as properties: emit `references` to the field's annotated
1023
+ // type. The outer `field_declaration` is the right scope to
1024
+ // search from — C# carries the `type` inside `variable_declaration`
1025
+ // and the language-aware path in `extractTypeAnnotations` descends
1026
+ // into that wrapper (#381).
1027
+ this.extractTypeAnnotations(node, fieldNode.id);
1028
+ }
1029
+ }
1030
+ }
1031
+ else {
1032
+ // Fallback: try to find an identifier child directly
1033
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name')
1034
+ || node.namedChildren.find(c => c.type === 'identifier');
1035
+ if (nameNode) {
1036
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1037
+ this.createNode('field', name, node, {
1038
+ docstring,
1039
+ visibility,
1040
+ isStatic,
1041
+ });
1042
+ }
1043
+ }
1044
+ }
1045
+ /**
1046
+ * Extract a variable declaration (const, let, var, etc.)
1047
+ *
1048
+ * Extracts top-level and module-level variable declarations.
1049
+ * Captures the variable name and first 100 chars of initializer in signature for searchability.
1050
+ */
1051
+ extractVariable(node) {
1052
+ if (!this.extractor)
1053
+ return;
1054
+ // Different languages have different variable declaration structures
1055
+ // TypeScript/JavaScript: lexical_declaration contains variable_declarator children
1056
+ // Python: assignment has left (identifier) and right (value)
1057
+ // Go: var_declaration, short_var_declaration, const_declaration
1058
+ const isConst = this.extractor.isConst?.(node) ?? false;
1059
+ const kind = isConst ? 'constant' : 'variable';
1060
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
1061
+ const isExported = this.extractor.isExported?.(node, this.source) ?? false;
1062
+ // Extract variable declarators based on language
1063
+ if (this.language === 'typescript' || this.language === 'javascript' ||
1064
+ this.language === 'tsx' || this.language === 'jsx') {
1065
+ // Handle lexical_declaration and variable_declaration
1066
+ // These contain one or more variable_declarator children
1067
+ for (let i = 0; i < node.namedChildCount; i++) {
1068
+ const child = node.namedChild(i);
1069
+ if (child?.type === 'variable_declarator') {
1070
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
1071
+ const valueNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'value');
1072
+ if (nameNode) {
1073
+ // Skip destructured patterns (e.g., `let { x, y } = $props()` in Svelte)
1074
+ // These produce ugly multi-line names like "{ class: className }"
1075
+ if (nameNode.type === 'object_pattern' || nameNode.type === 'array_pattern') {
1076
+ continue;
1077
+ }
1078
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1079
+ // Arrow functions / function expressions: extract as function instead of variable
1080
+ if (valueNode && (valueNode.type === 'arrow_function' || valueNode.type === 'function_expression')) {
1081
+ this.extractFunction(valueNode);
1082
+ continue;
1083
+ }
1084
+ // Capture first 100 chars of initializer for context (stored in signature for searchability)
1085
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
1086
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1087
+ const varNode = this.createNode(kind, name, child, {
1088
+ docstring,
1089
+ signature: initSignature,
1090
+ isExported,
1091
+ });
1092
+ // Extract type annotation references (e.g., const x: ITextModel = ...)
1093
+ if (varNode) {
1094
+ this.extractVariableTypeAnnotation(child, varNode.id);
1095
+ }
1096
+ if (valueNode &&
1097
+ valueNode.type !== 'object' &&
1098
+ valueNode.type !== 'object_expression') {
1099
+ this.visitFunctionBody(valueNode, '');
1100
+ }
1101
+ // Exported const object-of-functions: `export const actions =
1102
+ // { default: async () => {} }` (SvelteKit form actions / handler maps
1103
+ // / route tables). Extract each function-valued property as a function
1104
+ // named by its key + walk its body so its calls (e.g. api.post) are
1105
+ // captured. Scoped to EXPORTED consts to exclude the inline-object
1106
+ // noise (`ctx.set({...})`) the object-method skip deliberately avoids.
1107
+ if (isExported && valueNode &&
1108
+ (valueNode.type === 'object' || valueNode.type === 'object_expression')) {
1109
+ for (let j = 0; j < valueNode.namedChildCount; j++) {
1110
+ const pair = valueNode.namedChild(j);
1111
+ if (pair?.type !== 'pair')
1112
+ continue;
1113
+ const v = (0, tree_sitter_helpers_1.getChildByField)(pair, 'value');
1114
+ const k = (0, tree_sitter_helpers_1.getChildByField)(pair, 'key');
1115
+ if (k && v && (v.type === 'arrow_function' || v.type === 'function_expression')) {
1116
+ this.extractFunction(v, (0, tree_sitter_helpers_1.getNodeText)(k, this.source).replace(/^['"`]|['"`]$/g, ''));
1117
+ }
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ else if (this.language === 'python' || this.language === 'ruby') {
1125
+ // Python/Ruby assignment: left = right
1126
+ const left = (0, tree_sitter_helpers_1.getChildByField)(node, 'left') || node.namedChild(0);
1127
+ const right = (0, tree_sitter_helpers_1.getChildByField)(node, 'right') || node.namedChild(1);
1128
+ if (left && left.type === 'identifier') {
1129
+ const name = (0, tree_sitter_helpers_1.getNodeText)(left, this.source);
1130
+ // Skip if name starts with lowercase and looks like a function call result
1131
+ // Python constants are usually UPPER_CASE
1132
+ const initValue = right ? (0, tree_sitter_helpers_1.getNodeText)(right, this.source).slice(0, 100) : undefined;
1133
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1134
+ this.createNode(kind, name, node, {
1135
+ docstring,
1136
+ signature: initSignature,
1137
+ });
1138
+ }
1139
+ }
1140
+ else if (this.language === 'go') {
1141
+ // Go: var_declaration, short_var_declaration, const_declaration
1142
+ // These can have multiple identifiers on the left
1143
+ const specs = node.namedChildren.filter(c => c.type === 'var_spec' || c.type === 'const_spec');
1144
+ for (const spec of specs) {
1145
+ const nameNode = spec.namedChild(0);
1146
+ if (nameNode && nameNode.type === 'identifier') {
1147
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1148
+ const valueNode = spec.namedChildCount > 1 ? spec.namedChild(spec.namedChildCount - 1) : null;
1149
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
1150
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1151
+ this.createNode(node.type === 'const_declaration' ? 'constant' : 'variable', name, spec, {
1152
+ docstring,
1153
+ signature: initSignature,
1154
+ });
1155
+ }
1156
+ }
1157
+ // Handle short_var_declaration (:=)
1158
+ if (node.type === 'short_var_declaration') {
1159
+ const left = (0, tree_sitter_helpers_1.getChildByField)(node, 'left');
1160
+ const right = (0, tree_sitter_helpers_1.getChildByField)(node, 'right');
1161
+ if (left) {
1162
+ // Can be expression_list with multiple identifiers
1163
+ const identifiers = left.type === 'expression_list'
1164
+ ? left.namedChildren.filter(c => c.type === 'identifier')
1165
+ : [left];
1166
+ for (const id of identifiers) {
1167
+ const name = (0, tree_sitter_helpers_1.getNodeText)(id, this.source);
1168
+ const initValue = right ? (0, tree_sitter_helpers_1.getNodeText)(right, this.source).slice(0, 100) : undefined;
1169
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1170
+ this.createNode('variable', name, node, {
1171
+ docstring,
1172
+ signature: initSignature,
1173
+ });
1174
+ }
1175
+ }
1176
+ }
1177
+ }
1178
+ else if (this.language === 'lua' || this.language === 'luau') {
1179
+ // Lua/Luau: variable_declaration → assignment_statement → variable_list
1180
+ // (name: identifier...) = expression_list. `local x, y = 1, 2`
1181
+ // declares multiple names; only plain identifiers are locals.
1182
+ const assign = node.namedChildren.find((c) => c.type === 'assignment_statement') ?? node;
1183
+ const varList = assign.namedChildren.find((c) => c.type === 'variable_list');
1184
+ const exprList = assign.namedChildren.find((c) => c.type === 'expression_list');
1185
+ const values = exprList ? exprList.namedChildren : [];
1186
+ const names = varList ? varList.namedChildren.filter((c) => c.type === 'identifier') : [];
1187
+ names.forEach((nameNode, i) => {
1188
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1189
+ if (!name)
1190
+ return;
1191
+ const valueNode = values[i];
1192
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
1193
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1194
+ this.createNode(kind, name, nameNode, { docstring, signature: initSignature, isExported });
1195
+ });
1196
+ }
1197
+ else {
1198
+ // Generic fallback for other languages
1199
+ // Try to find identifier children
1200
+ for (let i = 0; i < node.namedChildCount; i++) {
1201
+ const child = node.namedChild(i);
1202
+ if (child?.type === 'identifier' || child?.type === 'variable_declarator') {
1203
+ const name = child.type === 'identifier'
1204
+ ? (0, tree_sitter_helpers_1.getNodeText)(child, this.source)
1205
+ : extractName(child, this.source, this.extractor);
1206
+ if (name && name !== '<anonymous>') {
1207
+ this.createNode(kind, name, child, {
1208
+ docstring,
1209
+ isExported,
1210
+ });
1211
+ }
1212
+ }
1213
+ }
1214
+ }
1215
+ }
1216
+ /**
1217
+ * Extract a type alias (e.g. `export type X = ...` in TypeScript).
1218
+ * For languages like Go, resolveTypeAliasKind detects when the type_spec
1219
+ * wraps a struct or interface definition and creates the correct node kind.
1220
+ * Returns true if children should be skipped (struct/interface handled body visiting).
1221
+ */
1222
+ extractTypeAlias(node) {
1223
+ if (!this.extractor)
1224
+ return false;
1225
+ const name = extractName(node, this.source, this.extractor);
1226
+ if (name === '<anonymous>')
1227
+ return false;
1228
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
1229
+ const isExported = this.extractor.isExported?.(node, this.source);
1230
+ // Check if this type alias is actually a struct or interface definition
1231
+ // (e.g. Go: `type Foo struct { ... }` is a type_spec wrapping struct_type)
1232
+ const resolvedKind = this.extractor.resolveTypeAliasKind?.(node, this.source);
1233
+ if (resolvedKind === 'struct') {
1234
+ const structNode = this.createNode('struct', name, node, { docstring, isExported });
1235
+ if (!structNode)
1236
+ return true;
1237
+ // Visit body children for field extraction
1238
+ this.nodeStack.push(structNode.id);
1239
+ // Try Go-style 'type' field first, then find inner struct child (C typedef struct)
1240
+ const typeChild = (0, tree_sitter_helpers_1.getChildByField)(node, 'type')
1241
+ || this.findChildByTypes(node, this.extractor.structTypes);
1242
+ if (typeChild) {
1243
+ // Extract struct embedding (e.g. Go: `type DB struct { *Head; Queryable }`)
1244
+ this.extractInheritance(typeChild, structNode.id);
1245
+ const body = (0, tree_sitter_helpers_1.getChildByField)(typeChild, this.extractor.bodyField) || typeChild;
1246
+ for (let i = 0; i < body.namedChildCount; i++) {
1247
+ const child = body.namedChild(i);
1248
+ if (child)
1249
+ this.visitNode(child);
1250
+ }
1251
+ }
1252
+ this.nodeStack.pop();
1253
+ return true;
1254
+ }
1255
+ if (resolvedKind === 'enum') {
1256
+ const enumNode = this.createNode('enum', name, node, { docstring, isExported });
1257
+ if (!enumNode)
1258
+ return true;
1259
+ this.nodeStack.push(enumNode.id);
1260
+ // Find the inner enum type child (e.g. C: typedef enum { ... } name)
1261
+ const innerEnum = this.findChildByTypes(node, this.extractor.enumTypes);
1262
+ if (innerEnum) {
1263
+ this.extractInheritance(innerEnum, enumNode.id);
1264
+ const body = this.extractor.resolveBody?.(innerEnum, this.extractor.bodyField)
1265
+ ?? (0, tree_sitter_helpers_1.getChildByField)(innerEnum, this.extractor.bodyField);
1266
+ if (body) {
1267
+ const memberTypes = this.extractor.enumMemberTypes;
1268
+ for (let i = 0; i < body.namedChildCount; i++) {
1269
+ const child = body.namedChild(i);
1270
+ if (!child)
1271
+ continue;
1272
+ if (memberTypes?.includes(child.type)) {
1273
+ this.extractEnumMembers(child);
1274
+ }
1275
+ else {
1276
+ this.visitNode(child);
1277
+ }
1278
+ }
1279
+ }
1280
+ }
1281
+ this.nodeStack.pop();
1282
+ return true;
1283
+ }
1284
+ if (resolvedKind === 'interface') {
1285
+ const kind = this.extractor.interfaceKind ?? 'interface';
1286
+ const interfaceNode = this.createNode(kind, name, node, { docstring, isExported });
1287
+ if (!interfaceNode)
1288
+ return true;
1289
+ // Extract interface inheritance from the inner type node
1290
+ const typeChild = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
1291
+ if (typeChild)
1292
+ this.extractInheritance(typeChild, interfaceNode.id);
1293
+ return true;
1294
+ }
1295
+ const typeAliasNode = this.createNode('type_alias', name, node, {
1296
+ docstring,
1297
+ isExported,
1298
+ });
1299
+ // Extract type references from the alias value (e.g., `type X = ITextModel | null`)
1300
+ if (typeAliasNode && this.TYPE_ANNOTATION_LANGUAGES.has(this.language)) {
1301
+ // The value is everything after the `=`, which is typically the last named child
1302
+ // In tree-sitter TS: type_alias_declaration has name + value children
1303
+ const value = (0, tree_sitter_helpers_1.getChildByField)(node, 'value');
1304
+ if (value) {
1305
+ this.extractTypeRefsFromSubtree(value, typeAliasNode.id);
1306
+ // `type X = { foo: T; bar(): T }` — make the members first-class
1307
+ // property/method nodes under the type alias so `recorder.stop()`
1308
+ // can attach the call edge to `RecorderHandle.stop` instead of
1309
+ // an unrelated class method picked by path-proximity (#359).
1310
+ if (this.language === 'typescript' || this.language === 'tsx') {
1311
+ this.extractTsTypeAliasMembers(value, typeAliasNode);
1312
+ }
1313
+ }
1314
+ }
1315
+ return false;
1316
+ }
1317
+ /**
1318
+ * Surface the members of a TypeScript `type X = { ... }` (or intersection
1319
+ * thereof) as `property` / `method` nodes under the type-alias node. Only
1320
+ * walks the immediate object_type / intersection operands so anonymous
1321
+ * nested object types inside generic arguments (`Promise<{ ok: true }>`)
1322
+ * don't produce phantom members.
1323
+ */
1324
+ extractTsTypeAliasMembers(value, typeAliasNode) {
1325
+ const objectTypes = [];
1326
+ if (value.type === 'object_type') {
1327
+ objectTypes.push(value);
1328
+ }
1329
+ else if (value.type === 'intersection_type') {
1330
+ for (let i = 0; i < value.namedChildCount; i++) {
1331
+ const op = value.namedChild(i);
1332
+ if (op && op.type === 'object_type')
1333
+ objectTypes.push(op);
1334
+ }
1335
+ }
1336
+ else {
1337
+ return;
1338
+ }
1339
+ this.nodeStack.push(typeAliasNode.id);
1340
+ for (const objType of objectTypes) {
1341
+ for (let i = 0; i < objType.namedChildCount; i++) {
1342
+ const child = objType.namedChild(i);
1343
+ if (!child)
1344
+ continue;
1345
+ if (child.type !== 'property_signature' && child.type !== 'method_signature')
1346
+ continue;
1347
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
1348
+ const memberName = nameNode ? (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source) : '';
1349
+ if (!memberName)
1350
+ continue;
1351
+ // `foo: () => T` and `foo(): T` are functionally a method on the
1352
+ // type contract. Treat the property_signature with a function-typed
1353
+ // annotation as a method too so call sites can resolve to it.
1354
+ const memberKind = child.type === 'method_signature'
1355
+ ? 'method'
1356
+ : this.isTsFunctionTypedProperty(child) ? 'method' : 'property';
1357
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(child, this.source);
1358
+ const signature = (0, tree_sitter_helpers_1.getNodeText)(child, this.source);
1359
+ this.createNode(memberKind, memberName, child, {
1360
+ docstring,
1361
+ signature,
1362
+ qualifiedName: `${typeAliasNode.name}::${memberName}`,
1363
+ });
1364
+ // Emit `references` edges from the type alias to types named in the
1365
+ // member's signature, matching the interface-member behavior added in
1366
+ // #432. We attach refs to the type-alias parent (consistent with
1367
+ // interface property_signature treatment).
1368
+ this.extractTypeAnnotations(child, typeAliasNode.id);
1369
+ }
1370
+ }
1371
+ this.nodeStack.pop();
1372
+ }
1373
+ /**
1374
+ * `foo: () => T` → property_signature whose type_annotation contains a
1375
+ * `function_type`. Treat that as a method-shaped contract member, since
1376
+ * the call site `obj.foo()` has identical semantics to `bar(): T`.
1377
+ */
1378
+ isTsFunctionTypedProperty(propertySignature) {
1379
+ const typeAnno = (0, tree_sitter_helpers_1.getChildByField)(propertySignature, 'type');
1380
+ if (!typeAnno)
1381
+ return false;
1382
+ for (let i = 0; i < typeAnno.namedChildCount; i++) {
1383
+ const inner = typeAnno.namedChild(i);
1384
+ if (inner && inner.type === 'function_type')
1385
+ return true;
1386
+ }
1387
+ return false;
1388
+ }
1389
+ // extractExportedVariables removed — the walker now descends into
1390
+ // export_statement children and the inner declaration's dedicated
1391
+ // extractor (extractVariable, extractFunction, extractClass, etc.)
1392
+ // handles the symbol with isExported=true via parent-walk in the
1393
+ // language extractor's isExported predicate.
1394
+ /**
1395
+ * Extract an import
1396
+ *
1397
+ * Creates an import node with the full import statement stored in signature for searchability.
1398
+ * Also creates unresolved references for resolution purposes.
1399
+ */
1400
+ extractImport(node) {
1401
+ if (!this.extractor)
1402
+ return;
1403
+ const importText = (0, tree_sitter_helpers_1.getNodeText)(node, this.source).trim();
1404
+ // Try language-specific hook first
1405
+ if (this.extractor.extractImport) {
1406
+ const info = this.extractor.extractImport(node, this.source);
1407
+ if (info) {
1408
+ this.createNode('import', info.moduleName, node, {
1409
+ signature: info.signature,
1410
+ });
1411
+ // Create unresolved reference unless the hook handled it
1412
+ if (!info.handledRefs && info.moduleName && this.nodeStack.length > 0) {
1413
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
1414
+ if (parentId) {
1415
+ this.unresolvedReferences.push({
1416
+ fromNodeId: parentId,
1417
+ referenceName: info.moduleName,
1418
+ referenceKind: 'imports',
1419
+ line: node.startPosition.row + 1,
1420
+ column: node.startPosition.column,
1421
+ });
1422
+ }
1423
+ }
1424
+ return;
1425
+ }
1426
+ // Hook returned null — fall through to multi-import inline handlers only
1427
+ // (hook returning null means "I didn't handle this" for multi-import cases,
1428
+ // NOT "use generic fallback" — the hook already declined)
1429
+ }
1430
+ // Multi-import cases that create multiple nodes (can't be expressed with single-return hook)
1431
+ // Python import_statement: import os, sys (creates one import per module)
1432
+ if (this.language === 'python' && node.type === 'import_statement') {
1433
+ for (let i = 0; i < node.namedChildCount; i++) {
1434
+ const child = node.namedChild(i);
1435
+ if (child?.type === 'dotted_name') {
1436
+ this.createNode('import', (0, tree_sitter_helpers_1.getNodeText)(child, this.source), node, {
1437
+ signature: importText,
1438
+ });
1439
+ }
1440
+ else if (child?.type === 'aliased_import') {
1441
+ const dottedName = child.namedChildren.find(c => c.type === 'dotted_name');
1442
+ if (dottedName) {
1443
+ this.createNode('import', (0, tree_sitter_helpers_1.getNodeText)(dottedName, this.source), node, {
1444
+ signature: importText,
1445
+ });
1446
+ }
1447
+ }
1448
+ }
1449
+ return;
1450
+ }
1451
+ // Go imports: single or grouped (creates one import per spec)
1452
+ if (this.language === 'go') {
1453
+ const parentId = this.nodeStack.length > 0 ? this.nodeStack[this.nodeStack.length - 1] : null;
1454
+ const extractFromSpec = (spec) => {
1455
+ const stringLiteral = spec.namedChildren.find(c => c.type === 'interpreted_string_literal');
1456
+ if (stringLiteral) {
1457
+ const importPath = (0, tree_sitter_helpers_1.getNodeText)(stringLiteral, this.source).replace(/['"]/g, '');
1458
+ if (importPath) {
1459
+ this.createNode('import', importPath, spec, {
1460
+ signature: (0, tree_sitter_helpers_1.getNodeText)(spec, this.source).trim(),
1461
+ });
1462
+ // Create unresolved reference so the resolver can create imports edges
1463
+ if (parentId) {
1464
+ this.unresolvedReferences.push({
1465
+ fromNodeId: parentId,
1466
+ referenceName: importPath,
1467
+ referenceKind: 'imports',
1468
+ line: spec.startPosition.row + 1,
1469
+ column: spec.startPosition.column,
1470
+ });
1471
+ }
1472
+ }
1473
+ }
1474
+ };
1475
+ const importSpecList = node.namedChildren.find(c => c.type === 'import_spec_list');
1476
+ if (importSpecList) {
1477
+ for (const spec of importSpecList.namedChildren.filter(c => c.type === 'import_spec')) {
1478
+ extractFromSpec(spec);
1479
+ }
1480
+ }
1481
+ else {
1482
+ const importSpec = node.namedChildren.find(c => c.type === 'import_spec');
1483
+ if (importSpec) {
1484
+ extractFromSpec(importSpec);
1485
+ }
1486
+ }
1487
+ return;
1488
+ }
1489
+ // PHP grouped imports: use X\{A, B} (creates one import per item)
1490
+ if (this.language === 'php') {
1491
+ const namespacePrefix = node.namedChildren.find(c => c.type === 'namespace_name');
1492
+ const useGroup = node.namedChildren.find(c => c.type === 'namespace_use_group');
1493
+ if (namespacePrefix && useGroup) {
1494
+ const prefix = (0, tree_sitter_helpers_1.getNodeText)(namespacePrefix, this.source);
1495
+ const useClauses = useGroup.namedChildren.filter((c) => c.type === 'namespace_use_group_clause' || c.type === 'namespace_use_clause');
1496
+ for (const clause of useClauses) {
1497
+ const nsName = clause.namedChildren.find((c) => c.type === 'namespace_name');
1498
+ const name = nsName
1499
+ ? nsName.namedChildren.find((c) => c.type === 'name')
1500
+ : clause.namedChildren.find((c) => c.type === 'name');
1501
+ if (name) {
1502
+ const fullPath = `${prefix}\\${(0, tree_sitter_helpers_1.getNodeText)(name, this.source)}`;
1503
+ this.createNode('import', fullPath, node, {
1504
+ signature: importText,
1505
+ });
1506
+ }
1507
+ }
1508
+ return;
1509
+ }
1510
+ }
1511
+ // If a hook exists but returned null, it intentionally declined this node — don't create fallback
1512
+ if (this.extractor.extractImport)
1513
+ return;
1514
+ // Generic fallback for languages without hooks
1515
+ this.createNode('import', importText, node, {
1516
+ signature: importText,
1517
+ });
1518
+ }
1519
+ /**
1520
+ * Extract a function call
1521
+ */
1522
+ extractCall(node) {
1523
+ if (this.nodeStack.length === 0)
1524
+ return;
1525
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
1526
+ if (!callerId)
1527
+ return;
1528
+ // Get the function/method being called
1529
+ let calleeName = '';
1530
+ // Java/Kotlin method_invocation has 'object' + 'name' fields instead of 'function'
1531
+ // PHP member_call_expression has 'object' + 'name', scoped_call_expression has 'scope' + 'name'
1532
+ const nameField = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
1533
+ const objectField = (0, tree_sitter_helpers_1.getChildByField)(node, 'object') || (0, tree_sitter_helpers_1.getChildByField)(node, 'scope');
1534
+ if (nameField && objectField && (node.type === 'method_invocation' || node.type === 'member_call_expression' || node.type === 'scoped_call_expression')) {
1535
+ // Method call with explicit receiver: receiver.method() / $receiver->method() / ClassName::method()
1536
+ const methodName = (0, tree_sitter_helpers_1.getNodeText)(nameField, this.source);
1537
+ // Java `this.userbo.toLogin2()` parses as method_invocation(object=field_access(this, userbo)).
1538
+ // Without unwrapping, receiverName is `this.userbo` and the name-matcher's
1539
+ // single-dot receiver regex fails. Pull out the immediate field after `this.`
1540
+ // so the receiver is the field name (`userbo`), which the resolver can then
1541
+ // look up in the enclosing class's field declarations.
1542
+ let receiverName;
1543
+ if (objectField.type === 'field_access') {
1544
+ const inner = (0, tree_sitter_helpers_1.getChildByField)(objectField, 'object');
1545
+ const fld = (0, tree_sitter_helpers_1.getChildByField)(objectField, 'field');
1546
+ if (inner && fld && (inner.type === 'this' || inner.type === 'this_expression')) {
1547
+ receiverName = (0, tree_sitter_helpers_1.getNodeText)(fld, this.source);
1548
+ }
1549
+ else {
1550
+ receiverName = (0, tree_sitter_helpers_1.getNodeText)(objectField, this.source);
1551
+ }
1552
+ }
1553
+ else {
1554
+ receiverName = (0, tree_sitter_helpers_1.getNodeText)(objectField, this.source);
1555
+ }
1556
+ // Strip PHP $ prefix from variable names
1557
+ receiverName = receiverName.replace(/^\$/, '');
1558
+ if (methodName) {
1559
+ // Skip self/this/parent/static receivers — they don't aid resolution
1560
+ const SKIP_RECEIVERS = new Set(['self', 'this', 'cls', 'super', 'parent', 'static']);
1561
+ if (SKIP_RECEIVERS.has(receiverName)) {
1562
+ calleeName = methodName;
1563
+ }
1564
+ else {
1565
+ calleeName = `${receiverName}.${methodName}`;
1566
+ }
1567
+ }
1568
+ }
1569
+ else if (node.type === 'message_expression') {
1570
+ // ObjC message expressions emit one `method` field child per selector
1571
+ // keyword: `[obj a:1 b:2 c:3]` has three `method=identifier` siblings.
1572
+ // Joining them with `:` reconstructs the full selector and matches the
1573
+ // multi-part selector names produced by the ObjC method_definition
1574
+ // extractor (`extractObjcMethodName` in languages/objc.ts). Without this
1575
+ // join, multi-keyword call sites only emitted the first keyword and never
1576
+ // resolved to their target methods (e.g. `GET:parameters:headers:...` had
1577
+ // zero callers despite obviously being called).
1578
+ const methodKeywords = [];
1579
+ for (let i = 0; i < node.namedChildCount; i++) {
1580
+ if (node.fieldNameForNamedChild(i) === 'method') {
1581
+ const kw = node.namedChild(i);
1582
+ if (kw)
1583
+ methodKeywords.push((0, tree_sitter_helpers_1.getNodeText)(kw, this.source));
1584
+ }
1585
+ }
1586
+ if (methodKeywords.length > 0) {
1587
+ const methodName = methodKeywords.length === 1
1588
+ ? methodKeywords[0]
1589
+ : methodKeywords.map((k) => `${k}:`).join('');
1590
+ const receiverField = (0, tree_sitter_helpers_1.getChildByField)(node, 'receiver');
1591
+ const SKIP_RECEIVERS = new Set(['self', 'super']);
1592
+ if (receiverField && receiverField.type !== 'message_expression') {
1593
+ const receiverName = (0, tree_sitter_helpers_1.getNodeText)(receiverField, this.source);
1594
+ if (receiverName && !SKIP_RECEIVERS.has(receiverName)) {
1595
+ calleeName = `${receiverName}.${methodName}`;
1596
+ }
1597
+ else {
1598
+ calleeName = methodName;
1599
+ }
1600
+ }
1601
+ else {
1602
+ calleeName = methodName;
1603
+ }
1604
+ }
1605
+ }
1606
+ else {
1607
+ const func = (0, tree_sitter_helpers_1.getChildByField)(node, 'function') || node.namedChild(0);
1608
+ if (func) {
1609
+ if (func.type === 'member_expression' || func.type === 'attribute' || func.type === 'selector_expression' || func.type === 'navigation_expression' || func.type === 'field_expression') {
1610
+ // Method call: obj.method() or obj.field.method()
1611
+ // Go uses selector_expression with 'field', JS/TS uses member_expression with 'property'
1612
+ // Kotlin uses navigation_expression with navigation_suffix > simple_identifier
1613
+ // C/C++ use field_expression for both `obj.method()` and `ptr->method()`
1614
+ let property = (0, tree_sitter_helpers_1.getChildByField)(func, 'property') || (0, tree_sitter_helpers_1.getChildByField)(func, 'field');
1615
+ if (!property) {
1616
+ const child1 = func.namedChild(1);
1617
+ // Kotlin: navigation_suffix wraps the method name — extract simple_identifier from it
1618
+ if (child1?.type === 'navigation_suffix') {
1619
+ property = child1.namedChildren.find((c) => c.type === 'simple_identifier') ?? child1;
1620
+ }
1621
+ else {
1622
+ property = child1;
1623
+ }
1624
+ }
1625
+ if (property) {
1626
+ const methodName = (0, tree_sitter_helpers_1.getNodeText)(property, this.source);
1627
+ // Include receiver name for qualified resolution (e.g., console.print → "console.print")
1628
+ // This helps the resolver distinguish method calls from bare function calls
1629
+ // (e.g., Python's console.print() vs builtin print())
1630
+ // Skip self/this/cls as they don't aid resolution
1631
+ const receiver = (0, tree_sitter_helpers_1.getChildByField)(func, 'object') ||
1632
+ (0, tree_sitter_helpers_1.getChildByField)(func, 'operand') ||
1633
+ (0, tree_sitter_helpers_1.getChildByField)(func, 'argument') ||
1634
+ func.namedChild(0);
1635
+ const SKIP_RECEIVERS = new Set(['self', 'this', 'cls', 'super']);
1636
+ if (receiver && (receiver.type === 'identifier' || receiver.type === 'simple_identifier' || receiver.type === 'field_identifier')) {
1637
+ const receiverName = (0, tree_sitter_helpers_1.getNodeText)(receiver, this.source);
1638
+ if (!SKIP_RECEIVERS.has(receiverName)) {
1639
+ calleeName = `${receiverName}.${methodName}`;
1640
+ }
1641
+ else {
1642
+ calleeName = methodName;
1643
+ }
1644
+ }
1645
+ else {
1646
+ calleeName = methodName;
1647
+ }
1648
+ }
1649
+ }
1650
+ else if (func.type === 'scoped_identifier' || func.type === 'scoped_call_expression') {
1651
+ // Scoped call: Module::function()
1652
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(func, this.source);
1653
+ }
1654
+ else {
1655
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(func, this.source);
1656
+ }
1657
+ }
1658
+ }
1659
+ if (calleeName) {
1660
+ this.unresolvedReferences.push({
1661
+ fromNodeId: callerId,
1662
+ referenceName: calleeName,
1663
+ referenceKind: 'calls',
1664
+ line: node.startPosition.row + 1,
1665
+ column: node.startPosition.column,
1666
+ });
1667
+ }
1668
+ }
1669
+ /**
1670
+ * `new Foo(...)` / `Foo::new(...)` / object_creation_expression —
1671
+ * emit an `instantiates` reference to the class name. The resolver
1672
+ * then links it to the class node, producing the `instantiates`
1673
+ * edge that powers "what creates instances of X" queries.
1674
+ *
1675
+ * Children are still walked so nested calls inside the constructor
1676
+ * arguments (`new Foo(bar())`) get their own `calls` references.
1677
+ */
1678
+ extractInstantiation(node) {
1679
+ if (this.nodeStack.length === 0)
1680
+ return;
1681
+ const fromId = this.nodeStack[this.nodeStack.length - 1];
1682
+ if (!fromId)
1683
+ return;
1684
+ // The class name is in the `constructor`/`type`/first-named-child
1685
+ // depending on grammar.
1686
+ const ctor = (0, tree_sitter_helpers_1.getChildByField)(node, 'constructor') ||
1687
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'type') ||
1688
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'name') ||
1689
+ node.namedChild(0);
1690
+ if (!ctor)
1691
+ return;
1692
+ let className = (0, tree_sitter_helpers_1.getNodeText)(ctor, this.source);
1693
+ // Strip type-argument suffix first: `new Map<K, V>()` would
1694
+ // otherwise produce className 'Map<K, V>' (the constructor
1695
+ // field is a `generic_type` node) and resolution would fail
1696
+ // because no class is named with the angle-bracket suffix.
1697
+ const ltIdx = className.indexOf('<');
1698
+ if (ltIdx > 0)
1699
+ className = className.slice(0, ltIdx);
1700
+ // For namespaced/qualified constructors (`new ns.Foo()`,
1701
+ // `new ns::Foo()`) keep the trailing identifier — that's what
1702
+ // matches a class node in the index.
1703
+ const lastDot = Math.max(className.lastIndexOf('.'), className.lastIndexOf('::'));
1704
+ if (lastDot >= 0)
1705
+ className = className.slice(lastDot + 1).replace(/^[:.]/, '');
1706
+ className = className.trim();
1707
+ if (className) {
1708
+ this.unresolvedReferences.push({
1709
+ fromNodeId: fromId,
1710
+ referenceName: className,
1711
+ referenceKind: 'instantiates',
1712
+ line: node.startPosition.row + 1,
1713
+ column: node.startPosition.column,
1714
+ });
1715
+ }
1716
+ }
1717
+ /**
1718
+ * Find a `class_body` child of an `object_creation_expression` — the
1719
+ * marker for an anonymous class (`new T() { ... }`). Returns the body
1720
+ * node so the caller can walk it as the anon class's members.
1721
+ */
1722
+ findAnonymousClassBody(node) {
1723
+ for (let i = 0; i < node.namedChildCount; i++) {
1724
+ const child = node.namedChild(i);
1725
+ // Java: `class_body`. C# uses the same node kind.
1726
+ if (child && (child.type === 'class_body' || child.type === 'declaration_list')) {
1727
+ return child;
1728
+ }
1729
+ }
1730
+ return null;
1731
+ }
1732
+ /**
1733
+ * Extract a Java/C# anonymous class — `new T() { ...members }`. Emits a
1734
+ * `class` node named `<T$anon@line>`, an `extends` reference to T (so
1735
+ * Phase 5.5 interface-impl can bridge), and walks the body so its
1736
+ * `method_declaration` members become method nodes under the anon class.
1737
+ *
1738
+ * Why this matters: without anon-class extraction, the overrides inside
1739
+ * a lambda-returned `new T() { @Override int foo(){...} }` are not nodes,
1740
+ * so a call through T.foo (the abstract parent method) has no static
1741
+ * target — the agent has to Read the file to find the implementation.
1742
+ */
1743
+ extractAnonymousClass(node, body) {
1744
+ if (!this.extractor)
1745
+ return;
1746
+ // The instantiated type sits in the same field/position that
1747
+ // extractInstantiation reads from. Use the same lookup so the anon
1748
+ // class's `extends` target matches the `instantiates` edge.
1749
+ const typeNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'constructor') ||
1750
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'type') ||
1751
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'name') ||
1752
+ node.namedChild(0);
1753
+ let typeName = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : 'Object';
1754
+ const ltIdx = typeName.indexOf('<');
1755
+ if (ltIdx > 0)
1756
+ typeName = typeName.slice(0, ltIdx);
1757
+ const lastDot = Math.max(typeName.lastIndexOf('.'), typeName.lastIndexOf('::'));
1758
+ if (lastDot >= 0)
1759
+ typeName = typeName.slice(lastDot + 1).replace(/^[:.]/, '');
1760
+ typeName = typeName.trim() || 'Object';
1761
+ const anonName = `<${typeName}$anon@${node.startPosition.row + 1}>`;
1762
+ const classNode = this.createNode('class', anonName, node, {});
1763
+ if (!classNode)
1764
+ return;
1765
+ // The anonymous class implicitly extends/implements the named type.
1766
+ // We can't tell at extraction time whether T is a class or an interface,
1767
+ // so emit `extends`. Resolution will still bind T to whatever it is, and
1768
+ // Phase 5.5 (which already handles both `extends` and `implements`) will
1769
+ // bridge T's methods to the override names found in the anon body.
1770
+ this.unresolvedReferences.push({
1771
+ fromNodeId: classNode.id,
1772
+ referenceName: typeName,
1773
+ referenceKind: 'extends',
1774
+ line: typeNode?.startPosition.row ?? node.startPosition.row,
1775
+ column: typeNode?.startPosition.column ?? node.startPosition.column,
1776
+ });
1777
+ // Walk the body's children so method_declaration nodes inside become
1778
+ // method nodes scoped to the anon class.
1779
+ this.nodeStack.push(classNode.id);
1780
+ for (let i = 0; i < body.namedChildCount; i++) {
1781
+ const child = body.namedChild(i);
1782
+ if (child)
1783
+ this.visitNode(child);
1784
+ }
1785
+ this.nodeStack.pop();
1786
+ }
1787
+ /**
1788
+ * Scan `declNode` and its preceding siblings (within the parent's
1789
+ * named children) for decorator nodes, emitting a `decorates`
1790
+ * reference from `decoratedId` to each decorator's function name.
1791
+ *
1792
+ * Why preceding siblings: in TypeScript, `@Foo class Bar {}` parses
1793
+ * as an `export_statement` (or top-level wrapper) with the
1794
+ * `decorator` as a child *before* the `class_declaration` — so the
1795
+ * decorator isn't a child of the class itself. For methods/
1796
+ * properties, the decorator IS a direct child of the declaration,
1797
+ * so we also scan declNode.namedChildren.
1798
+ *
1799
+ * Idempotent across grammars: if neither location yields decorators
1800
+ * (most non-decorator-using languages), the function is a no-op.
1801
+ */
1802
+ extractDecoratorsFor(declNode, decoratedId) {
1803
+ const consider = (n) => {
1804
+ if (!n)
1805
+ return;
1806
+ // `marker_annotation` is Java's grammar for arg-less annotations
1807
+ // (`@Override`, `@Deprecated`); without including it, every
1808
+ // such Java annotation would be silently skipped.
1809
+ if (n.type !== 'decorator' &&
1810
+ n.type !== 'annotation' &&
1811
+ n.type !== 'marker_annotation') {
1812
+ return;
1813
+ }
1814
+ // Find the leading identifier: skip the `@` punct, unwrap
1815
+ // a call_expression if the decorator is invoked with args.
1816
+ let target = null;
1817
+ for (let i = 0; i < n.namedChildCount; i++) {
1818
+ const child = n.namedChild(i);
1819
+ if (!child)
1820
+ continue;
1821
+ if (child.type === 'call_expression') {
1822
+ const fn = (0, tree_sitter_helpers_1.getChildByField)(child, 'function') ?? child.namedChild(0);
1823
+ if (fn)
1824
+ target = fn;
1825
+ if (target)
1826
+ break;
1827
+ }
1828
+ if (child.type === 'identifier' ||
1829
+ child.type === 'member_expression' ||
1830
+ child.type === 'scoped_identifier' ||
1831
+ child.type === 'navigation_expression') {
1832
+ target = child;
1833
+ break;
1834
+ }
1835
+ }
1836
+ if (!target)
1837
+ return;
1838
+ let name = (0, tree_sitter_helpers_1.getNodeText)(target, this.source);
1839
+ const lastDot = Math.max(name.lastIndexOf('.'), name.lastIndexOf('::'));
1840
+ if (lastDot >= 0)
1841
+ name = name.slice(lastDot + 1).replace(/^[:.]/, '');
1842
+ if (!name)
1843
+ return;
1844
+ this.unresolvedReferences.push({
1845
+ fromNodeId: decoratedId,
1846
+ referenceName: name,
1847
+ referenceKind: 'decorates',
1848
+ line: n.startPosition.row + 1,
1849
+ column: n.startPosition.column,
1850
+ });
1851
+ };
1852
+ // 1. Decorators that are direct children of the declaration
1853
+ // (method/property style, also some grammars for class).
1854
+ for (let i = 0; i < declNode.namedChildCount; i++) {
1855
+ consider(declNode.namedChild(i));
1856
+ }
1857
+ // 2. Decorators that are PRECEDING siblings of the declaration
1858
+ // inside the parent's children (TypeScript class style).
1859
+ // Walk BACKWARDS from the declaration and stop at the first
1860
+ // non-decorator sibling — without that stop, decorators
1861
+ // belonging to an EARLIER unrelated declaration leak in
1862
+ // (e.g. `@A class Foo {} @B class Bar {}` would otherwise
1863
+ // attribute @A to Bar).
1864
+ //
1865
+ // Note on identity: tree-sitter web bindings return fresh JS
1866
+ // wrapper objects from `parent`/`namedChild` navigation, so
1867
+ // `sibling === declNode` is unreliable — `startIndex` does
1868
+ // the matching instead.
1869
+ const parent = declNode.parent;
1870
+ if (parent) {
1871
+ const declStart = declNode.startIndex;
1872
+ let declIdx = -1;
1873
+ for (let i = 0; i < parent.namedChildCount; i++) {
1874
+ const sibling = parent.namedChild(i);
1875
+ if (sibling && sibling.startIndex === declStart) {
1876
+ declIdx = i;
1877
+ break;
1878
+ }
1879
+ }
1880
+ if (declIdx > 0) {
1881
+ for (let j = declIdx - 1; j >= 0; j--) {
1882
+ const sibling = parent.namedChild(j);
1883
+ if (!sibling)
1884
+ continue;
1885
+ if (sibling.type !== 'decorator' && sibling.type !== 'annotation' && sibling.type !== 'marker_annotation') {
1886
+ break; // non-decorator separator → stop consuming
1887
+ }
1888
+ consider(sibling);
1889
+ }
1890
+ }
1891
+ }
1892
+ }
1893
+ /**
1894
+ * Visit function body and extract calls (and structural nodes).
1895
+ *
1896
+ * In addition to call expressions, this also detects class/struct/enum
1897
+ * definitions inside function bodies. This handles two cases:
1898
+ * 1. Local class/struct/enum definitions (valid in C++, Java, etc.)
1899
+ * 2. C++ macro misparsing — macros like NLOHMANN_JSON_NAMESPACE_BEGIN cause
1900
+ * tree-sitter to interpret the namespace block as a function_definition,
1901
+ * hiding real class/struct/enum nodes inside the "function body".
1902
+ */
1903
+ visitFunctionBody(body, _functionId) {
1904
+ if (!this.extractor)
1905
+ return;
1906
+ const visitForCallsAndStructure = (node) => {
1907
+ const nodeType = node.type;
1908
+ if (this.extractor.callTypes.includes(nodeType)) {
1909
+ this.extractCall(node);
1910
+ }
1911
+ else if (INSTANTIATION_KINDS.has(nodeType)) {
1912
+ // `new Foo()` inside a function body — emit an `instantiates`
1913
+ // reference. Without this branch the body walker only knew
1914
+ // about `call_expression`, so constructor invocations
1915
+ // produced no graph edges at all.
1916
+ this.extractInstantiation(node);
1917
+ // Anonymous class with body: `new T() { ... }` (Java/C#). Extract as
1918
+ // a class so interface-impl synthesis (Phase 5.5) can bridge T's
1919
+ // methods to the overrides — same rationale as in visitNode.
1920
+ const anonBody = this.findAnonymousClassBody(node);
1921
+ if (anonBody) {
1922
+ this.extractAnonymousClass(node, anonBody);
1923
+ return;
1924
+ }
1925
+ }
1926
+ else if (this.extractor.extractBareCall) {
1927
+ const calleeName = this.extractor.extractBareCall(node, this.source);
1928
+ if (calleeName && this.nodeStack.length > 0) {
1929
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
1930
+ if (callerId) {
1931
+ this.unresolvedReferences.push({
1932
+ fromNodeId: callerId,
1933
+ referenceName: calleeName,
1934
+ referenceKind: 'calls',
1935
+ line: node.startPosition.row + 1,
1936
+ column: node.startPosition.column,
1937
+ });
1938
+ }
1939
+ }
1940
+ }
1941
+ // Nested NAMED functions inside a body — function declarations and named
1942
+ // function expressions like `.on('mount', function onmount(){})` — become
1943
+ // their own nodes so the graph can link to them (callback handlers, local
1944
+ // helpers). Anonymous arrows/expressions fall through to the default
1945
+ // recursion below, keeping their inner calls attributed to the enclosing
1946
+ // function: this bounds the new nodes to NAMED functions only (no explosion,
1947
+ // no lost edges). extractFunction walks the nested body itself, so we return.
1948
+ if (this.extractor.functionTypes.includes(nodeType)) {
1949
+ const nestedName = extractName(node, this.source, this.extractor);
1950
+ if (nestedName && nestedName !== '<anonymous>') {
1951
+ this.extractFunction(node);
1952
+ return;
1953
+ }
1954
+ }
1955
+ // Extract structural nodes found inside function bodies.
1956
+ // Each extract method visits its own children, so we return after extracting.
1957
+ if (this.extractor.classTypes.includes(nodeType)) {
1958
+ const classification = this.extractor.classifyClassNode?.(node) ?? 'class';
1959
+ if (classification === 'struct')
1960
+ this.extractStruct(node);
1961
+ else if (classification === 'enum')
1962
+ this.extractEnum(node);
1963
+ else if (classification === 'interface')
1964
+ this.extractInterface(node);
1965
+ else if (classification === 'trait')
1966
+ this.extractClass(node, 'trait');
1967
+ else
1968
+ this.extractClass(node);
1969
+ return;
1970
+ }
1971
+ if (this.extractor.structTypes.includes(nodeType)) {
1972
+ this.extractStruct(node);
1973
+ return;
1974
+ }
1975
+ if (this.extractor.enumTypes.includes(nodeType)) {
1976
+ this.extractEnum(node);
1977
+ return;
1978
+ }
1979
+ if (this.extractor.interfaceTypes.includes(nodeType)) {
1980
+ this.extractInterface(node);
1981
+ return;
1982
+ }
1983
+ for (let i = 0; i < node.namedChildCount; i++) {
1984
+ const child = node.namedChild(i);
1985
+ if (child) {
1986
+ visitForCallsAndStructure(child);
1987
+ }
1988
+ }
1989
+ };
1990
+ visitForCallsAndStructure(body);
1991
+ }
1992
+ /**
1993
+ * Extract inheritance relationships
1994
+ */
1995
+ extractInheritance(node, classId) {
1996
+ // Objective-C @interface MyClass : NSObject <ProtoA, ProtoB>
1997
+ if (node.type === 'class_interface') {
1998
+ const superclass = (0, tree_sitter_helpers_1.getChildByField)(node, 'superclass');
1999
+ if (superclass) {
2000
+ const name = (0, tree_sitter_helpers_1.getNodeText)(superclass, this.source);
2001
+ this.unresolvedReferences.push({
2002
+ fromNodeId: classId,
2003
+ referenceName: name,
2004
+ referenceKind: 'extends',
2005
+ line: superclass.startPosition.row + 1,
2006
+ column: superclass.startPosition.column,
2007
+ });
2008
+ }
2009
+ for (let j = 0; j < node.namedChildCount; j++) {
2010
+ const argList = node.namedChild(j);
2011
+ if (argList?.type !== 'parameterized_arguments')
2012
+ continue;
2013
+ for (let k = 0; k < argList.namedChildCount; k++) {
2014
+ const typeName = argList.namedChild(k);
2015
+ if (!typeName)
2016
+ continue;
2017
+ const typeId = typeName.namedChildren.find((c) => c.type === 'type_identifier' || c.type === 'identifier');
2018
+ if (!typeId)
2019
+ continue;
2020
+ const protocolName = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2021
+ this.unresolvedReferences.push({
2022
+ fromNodeId: classId,
2023
+ referenceName: protocolName,
2024
+ referenceKind: 'implements',
2025
+ line: typeId.startPosition.row + 1,
2026
+ column: typeId.startPosition.column,
2027
+ });
2028
+ }
2029
+ }
2030
+ return;
2031
+ }
2032
+ // Look for extends/implements clauses
2033
+ for (let i = 0; i < node.namedChildCount; i++) {
2034
+ const child = node.namedChild(i);
2035
+ if (!child)
2036
+ continue;
2037
+ if (child.type === 'extends_clause' ||
2038
+ child.type === 'superclass' ||
2039
+ child.type === 'base_clause' || // PHP class extends
2040
+ child.type === 'extends_interfaces' // Java interface extends
2041
+ ) {
2042
+ // Extract parent class/interface names
2043
+ // Java uses type_list wrapper: superclass -> type_identifier, extends_interfaces -> type_list -> type_identifier
2044
+ const typeList = child.namedChildren.find((c) => c.type === 'type_list');
2045
+ const targets = typeList ? typeList.namedChildren : [child.namedChild(0)];
2046
+ for (const target of targets) {
2047
+ if (target) {
2048
+ const name = (0, tree_sitter_helpers_1.getNodeText)(target, this.source);
2049
+ this.unresolvedReferences.push({
2050
+ fromNodeId: classId,
2051
+ referenceName: name,
2052
+ referenceKind: 'extends',
2053
+ line: target.startPosition.row + 1,
2054
+ column: target.startPosition.column,
2055
+ });
2056
+ }
2057
+ }
2058
+ }
2059
+ // C++ base classes: `class Derived : public Base, private Other` →
2060
+ // base_class_clause holds access specifiers + base type(s). Emit an extends
2061
+ // ref per base type (skip the public/private/protected keywords).
2062
+ if (child.type === 'base_class_clause') {
2063
+ for (const t of child.namedChildren) {
2064
+ if (t.type === 'type_identifier' ||
2065
+ t.type === 'qualified_identifier' ||
2066
+ t.type === 'template_type') {
2067
+ this.unresolvedReferences.push({
2068
+ fromNodeId: classId,
2069
+ referenceName: (0, tree_sitter_helpers_1.getNodeText)(t, this.source),
2070
+ referenceKind: 'extends',
2071
+ line: t.startPosition.row + 1,
2072
+ column: t.startPosition.column,
2073
+ });
2074
+ }
2075
+ }
2076
+ }
2077
+ if (child.type === 'implements_clause' ||
2078
+ child.type === 'class_interface_clause' ||
2079
+ child.type === 'super_interfaces' || // Java class implements
2080
+ child.type === 'interfaces' // Dart
2081
+ ) {
2082
+ // Extract implemented interfaces
2083
+ // Java uses type_list wrapper: super_interfaces -> type_list -> type_identifier
2084
+ const typeList = child.namedChildren.find((c) => c.type === 'type_list');
2085
+ const targets = typeList ? typeList.namedChildren : child.namedChildren;
2086
+ for (const iface of targets) {
2087
+ if (iface) {
2088
+ const name = (0, tree_sitter_helpers_1.getNodeText)(iface, this.source);
2089
+ this.unresolvedReferences.push({
2090
+ fromNodeId: classId,
2091
+ referenceName: name,
2092
+ referenceKind: 'implements',
2093
+ line: iface.startPosition.row + 1,
2094
+ column: iface.startPosition.column,
2095
+ });
2096
+ }
2097
+ }
2098
+ }
2099
+ // Python superclass list: `class Flask(Scaffold, Mixin):`
2100
+ // argument_list contains identifier children for each parent class
2101
+ if (child.type === 'argument_list' && node.type === 'class_definition') {
2102
+ for (const arg of child.namedChildren) {
2103
+ if (arg.type === 'identifier' || arg.type === 'attribute') {
2104
+ const name = (0, tree_sitter_helpers_1.getNodeText)(arg, this.source);
2105
+ this.unresolvedReferences.push({
2106
+ fromNodeId: classId,
2107
+ referenceName: name,
2108
+ referenceKind: 'extends',
2109
+ line: arg.startPosition.row + 1,
2110
+ column: arg.startPosition.column,
2111
+ });
2112
+ }
2113
+ }
2114
+ }
2115
+ // Go interface embedding: `type Querier interface { LabelQuerier; ... }`
2116
+ // constraint_elem wraps the embedded interface type identifier
2117
+ if (child.type === 'constraint_elem') {
2118
+ const typeId = child.namedChildren.find((c) => c.type === 'type_identifier');
2119
+ if (typeId) {
2120
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2121
+ this.unresolvedReferences.push({
2122
+ fromNodeId: classId,
2123
+ referenceName: name,
2124
+ referenceKind: 'extends',
2125
+ line: typeId.startPosition.row + 1,
2126
+ column: typeId.startPosition.column,
2127
+ });
2128
+ }
2129
+ }
2130
+ // Go struct embedding: field_declaration without field_identifier
2131
+ // e.g. `type DB struct { *Head; Queryable }` — no field name means embedded type
2132
+ if (child.type === 'field_declaration') {
2133
+ const hasFieldIdentifier = child.namedChildren.some((c) => c.type === 'field_identifier');
2134
+ if (!hasFieldIdentifier) {
2135
+ const typeId = child.namedChildren.find((c) => c.type === 'type_identifier');
2136
+ if (typeId) {
2137
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2138
+ this.unresolvedReferences.push({
2139
+ fromNodeId: classId,
2140
+ referenceName: name,
2141
+ referenceKind: 'extends',
2142
+ line: typeId.startPosition.row + 1,
2143
+ column: typeId.startPosition.column,
2144
+ });
2145
+ }
2146
+ }
2147
+ }
2148
+ // Rust trait supertraits: `trait SubTrait: SuperTrait + Display { ... }`
2149
+ // trait_bounds contains type_identifier, generic_type, or higher_ranked_trait_bound children
2150
+ if (child.type === 'trait_bounds') {
2151
+ for (const bound of child.namedChildren) {
2152
+ let typeName;
2153
+ let posNode;
2154
+ if (bound.type === 'type_identifier') {
2155
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(bound, this.source);
2156
+ posNode = bound;
2157
+ }
2158
+ else if (bound.type === 'generic_type') {
2159
+ // e.g. `Deserialize<'de>`
2160
+ const inner = bound.namedChildren.find((c) => c.type === 'type_identifier');
2161
+ if (inner) {
2162
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(inner, this.source);
2163
+ posNode = inner;
2164
+ }
2165
+ }
2166
+ else if (bound.type === 'higher_ranked_trait_bound') {
2167
+ // e.g. `for<'de> Deserialize<'de>`
2168
+ const generic = bound.namedChildren.find((c) => c.type === 'generic_type');
2169
+ const typeId = generic?.namedChildren.find((c) => c.type === 'type_identifier')
2170
+ ?? bound.namedChildren.find((c) => c.type === 'type_identifier');
2171
+ if (typeId) {
2172
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2173
+ posNode = typeId;
2174
+ }
2175
+ }
2176
+ if (typeName && posNode) {
2177
+ this.unresolvedReferences.push({
2178
+ fromNodeId: classId,
2179
+ referenceName: typeName,
2180
+ referenceKind: 'extends',
2181
+ line: posNode.startPosition.row + 1,
2182
+ column: posNode.startPosition.column,
2183
+ });
2184
+ }
2185
+ }
2186
+ }
2187
+ // C#: `class Movie : BaseItem, IPlugin` → base_list with identifier children
2188
+ // base_list combines both base class and interfaces in a single colon-separated list.
2189
+ // We emit all as 'extends' since the syntax doesn't distinguish them.
2190
+ if (child.type === 'base_list') {
2191
+ for (const baseType of child.namedChildren) {
2192
+ if (baseType) {
2193
+ // For generic base types like `ClientBase<T>`, extract just the type name
2194
+ const name = baseType.type === 'generic_name'
2195
+ ? (0, tree_sitter_helpers_1.getNodeText)(baseType.namedChildren.find((c) => c.type === 'identifier') ?? baseType, this.source)
2196
+ : (0, tree_sitter_helpers_1.getNodeText)(baseType, this.source);
2197
+ this.unresolvedReferences.push({
2198
+ fromNodeId: classId,
2199
+ referenceName: name,
2200
+ referenceKind: 'extends',
2201
+ line: baseType.startPosition.row + 1,
2202
+ column: baseType.startPosition.column,
2203
+ });
2204
+ }
2205
+ }
2206
+ }
2207
+ // Kotlin: `class Foo : Bar, Baz` → delegation_specifier > user_type > type_identifier
2208
+ // Also handles `class Foo : Bar()` → delegation_specifier > constructor_invocation > user_type
2209
+ if (child.type === 'delegation_specifier') {
2210
+ const userType = child.namedChildren.find((c) => c.type === 'user_type');
2211
+ const constructorInvocation = child.namedChildren.find((c) => c.type === 'constructor_invocation');
2212
+ const target = userType ?? constructorInvocation;
2213
+ if (target) {
2214
+ const typeId = target.type === 'user_type'
2215
+ ? target.namedChildren.find((c) => c.type === 'type_identifier') ?? target
2216
+ : target.namedChildren.find((c) => c.type === 'user_type')?.namedChildren.find((c) => c.type === 'type_identifier')
2217
+ ?? target.namedChildren.find((c) => c.type === 'user_type') ?? target;
2218
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2219
+ this.unresolvedReferences.push({
2220
+ fromNodeId: classId,
2221
+ referenceName: name,
2222
+ referenceKind: 'extends',
2223
+ line: typeId.startPosition.row + 1,
2224
+ column: typeId.startPosition.column,
2225
+ });
2226
+ }
2227
+ }
2228
+ // Swift: inheritance_specifier > user_type > type_identifier
2229
+ // Used for class inheritance, protocol conformance, and protocol inheritance
2230
+ if (child.type === 'inheritance_specifier') {
2231
+ const userType = child.namedChildren.find((c) => c.type === 'user_type');
2232
+ const typeId = userType?.namedChildren.find((c) => c.type === 'type_identifier');
2233
+ if (typeId) {
2234
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
2235
+ this.unresolvedReferences.push({
2236
+ fromNodeId: classId,
2237
+ referenceName: name,
2238
+ referenceKind: 'extends',
2239
+ line: typeId.startPosition.row + 1,
2240
+ column: typeId.startPosition.column,
2241
+ });
2242
+ }
2243
+ }
2244
+ // JavaScript class_heritage has bare identifier without extends_clause wrapper
2245
+ // e.g. `class Foo extends Bar {}` → class_heritage → identifier("Bar")
2246
+ if ((child.type === 'identifier' || child.type === 'type_identifier') &&
2247
+ node.type === 'class_heritage') {
2248
+ const name = (0, tree_sitter_helpers_1.getNodeText)(child, this.source);
2249
+ this.unresolvedReferences.push({
2250
+ fromNodeId: classId,
2251
+ referenceName: name,
2252
+ referenceKind: 'extends',
2253
+ line: child.startPosition.row + 1,
2254
+ column: child.startPosition.column,
2255
+ });
2256
+ }
2257
+ // Recurse into container nodes (e.g. field_declaration_list in Go structs,
2258
+ // class_heritage in TypeScript which wraps extends_clause/implements_clause)
2259
+ if (child.type === 'field_declaration_list' || child.type === 'class_heritage') {
2260
+ this.extractInheritance(child, classId);
2261
+ }
2262
+ }
2263
+ }
2264
+ /**
2265
+ * Rust `impl Trait for Type` — creates an implements edge from Type to Trait.
2266
+ * For plain `impl Type { ... }` (no trait), no inheritance edge is needed.
2267
+ */
2268
+ extractRustImplItem(node) {
2269
+ // Check if this is `impl Trait for Type` by looking for a `for` keyword
2270
+ const hasFor = node.children.some((c) => c.type === 'for' && !c.isNamed);
2271
+ if (!hasFor)
2272
+ return;
2273
+ // In `impl Trait for Type`, the type_identifiers are:
2274
+ // first = Trait name, last = implementing Type name
2275
+ // Also handle generic types like `impl<T> Trait for MyStruct<T>`
2276
+ const typeIdents = node.namedChildren.filter((c) => c.type === 'type_identifier' || c.type === 'generic_type' || c.type === 'scoped_type_identifier');
2277
+ if (typeIdents.length < 2)
2278
+ return;
2279
+ const traitNode = typeIdents[0];
2280
+ const typeNode = typeIdents[typeIdents.length - 1];
2281
+ // Get the trait name (handle scoped paths like std::fmt::Display)
2282
+ const traitName = traitNode.type === 'scoped_type_identifier'
2283
+ ? this.source.substring(traitNode.startIndex, traitNode.endIndex)
2284
+ : (0, tree_sitter_helpers_1.getNodeText)(traitNode, this.source);
2285
+ // Get the implementing type name (extract inner type_identifier for generics)
2286
+ let typeName;
2287
+ if (typeNode.type === 'generic_type') {
2288
+ const inner = typeNode.namedChildren.find((c) => c.type === 'type_identifier');
2289
+ typeName = inner ? (0, tree_sitter_helpers_1.getNodeText)(inner, this.source) : (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source);
2290
+ }
2291
+ else {
2292
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source);
2293
+ }
2294
+ // Find the struct/type node for the implementing type
2295
+ const typeNodeId = this.findNodeByName(typeName);
2296
+ if (typeNodeId) {
2297
+ this.unresolvedReferences.push({
2298
+ fromNodeId: typeNodeId,
2299
+ referenceName: traitName,
2300
+ referenceKind: 'implements',
2301
+ line: traitNode.startPosition.row + 1,
2302
+ column: traitNode.startPosition.column,
2303
+ });
2304
+ }
2305
+ }
2306
+ /**
2307
+ * Find a previously-extracted node by name (used for back-references like impl blocks)
2308
+ */
2309
+ findNodeByName(name) {
2310
+ for (const node of this.nodes) {
2311
+ if (node.name === name && (node.kind === 'struct' || node.kind === 'enum' || node.kind === 'class')) {
2312
+ return node.id;
2313
+ }
2314
+ }
2315
+ return undefined;
2316
+ }
2317
+ /**
2318
+ * Languages that support type annotations (TypeScript, etc.)
2319
+ */
2320
+ TYPE_ANNOTATION_LANGUAGES = new Set([
2321
+ 'typescript', 'tsx', 'dart', 'kotlin', 'swift', 'rust', 'go', 'java', 'csharp',
2322
+ ]);
2323
+ /**
2324
+ * Built-in/primitive type names that shouldn't create references
2325
+ */
2326
+ BUILTIN_TYPES = new Set([
2327
+ 'string', 'number', 'boolean', 'void', 'null', 'undefined', 'never', 'any', 'unknown',
2328
+ 'object', 'symbol', 'bigint', 'true', 'false',
2329
+ // Rust
2330
+ 'str', 'bool', 'i8', 'i16', 'i32', 'i64', 'i128', 'isize',
2331
+ 'u8', 'u16', 'u32', 'u64', 'u128', 'usize', 'f32', 'f64', 'char',
2332
+ // Java/C#
2333
+ 'int', 'long', 'short', 'byte', 'float', 'double', 'char',
2334
+ // Go
2335
+ 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64',
2336
+ 'float32', 'float64', 'complex64', 'complex128', 'rune', 'error',
2337
+ ]);
2338
+ /**
2339
+ * Extract type references from type annotations on a function/method/field node.
2340
+ * Creates 'references' edges for parameter types, return types, and field types.
2341
+ */
2342
+ extractTypeAnnotations(node, nodeId) {
2343
+ if (!this.extractor)
2344
+ return;
2345
+ if (!this.TYPE_ANNOTATION_LANGUAGES.has(this.language))
2346
+ return;
2347
+ // C# tree-sitter doesn't produce `type_identifier` leaves — it uses
2348
+ // `identifier`, `predefined_type`, `qualified_name`, `generic_name`,
2349
+ // etc. — so the generic walker below emits zero references for it.
2350
+ // Dispatch to a C#-aware path that only walks type-position subtrees
2351
+ // (the `type` field of a parameter/method/property/field), so
2352
+ // parameter NAMES never accidentally surface as type refs (#381).
2353
+ if (this.language === 'csharp') {
2354
+ this.extractCsharpTypeRefs(node, nodeId);
2355
+ return;
2356
+ }
2357
+ // Extract parameter type annotations
2358
+ const params = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.paramsField || 'parameters');
2359
+ if (params) {
2360
+ this.extractTypeRefsFromSubtree(params, nodeId);
2361
+ }
2362
+ // Extract return type annotation
2363
+ const returnType = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.returnField || 'return_type');
2364
+ if (returnType) {
2365
+ this.extractTypeRefsFromSubtree(returnType, nodeId);
2366
+ }
2367
+ // Extract direct type annotation (for class fields like `model: ITextModel`)
2368
+ const typeAnnotation = node.namedChildren.find((c) => c.type === 'type_annotation');
2369
+ if (typeAnnotation) {
2370
+ this.extractTypeRefsFromSubtree(typeAnnotation, nodeId);
2371
+ }
2372
+ }
2373
+ /**
2374
+ * Extract C# type references from a node that owns a type position —
2375
+ * a method/constructor declaration, a property declaration, or a
2376
+ * field declaration (which wraps `variable_declaration → type`).
2377
+ *
2378
+ * Walks ONLY into known type fields, so parameter names like
2379
+ * `request` in `Build(UserDto request)` are never mis-emitted as
2380
+ * type references. Once inside a type subtree, `walkCsharpTypePosition`
2381
+ * recognizes C#'s actual type-leaf node kinds (`identifier`,
2382
+ * `qualified_name`, `generic_name`, `array_type`, `nullable_type`,
2383
+ * `tuple_type`, …) — none of which are `type_identifier`. Closes #381.
2384
+ */
2385
+ extractCsharpTypeRefs(node, nodeId) {
2386
+ // Return type / property type — the field is named `type`.
2387
+ const directType = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
2388
+ if (directType)
2389
+ this.walkCsharpTypePosition(directType, nodeId);
2390
+ // Field declarations wrap declarators in a `variable_declaration`
2391
+ // whose `type` field carries the type. The outer `field_declaration`
2392
+ // has no `type` field of its own, so the call above is a no-op here
2393
+ // and we descend one level.
2394
+ const varDecl = node.namedChildren.find((c) => c.type === 'variable_declaration');
2395
+ if (varDecl) {
2396
+ const vdType = (0, tree_sitter_helpers_1.getChildByField)(varDecl, 'type');
2397
+ if (vdType)
2398
+ this.walkCsharpTypePosition(vdType, nodeId);
2399
+ }
2400
+ // Method / constructor parameters. The field name on
2401
+ // `method_declaration` is `parameters`; it points at a
2402
+ // `parameter_list` whose `parameter` children each have their own
2403
+ // `type` field. Walking ONLY the type field skips parameter NAMES,
2404
+ // which would otherwise mis-emit as type references.
2405
+ const params = (0, tree_sitter_helpers_1.getChildByField)(node, 'parameters');
2406
+ if (params) {
2407
+ for (let i = 0; i < params.namedChildCount; i++) {
2408
+ const child = params.namedChild(i);
2409
+ if (!child || child.type !== 'parameter')
2410
+ continue;
2411
+ const paramType = (0, tree_sitter_helpers_1.getChildByField)(child, 'type');
2412
+ if (paramType)
2413
+ this.walkCsharpTypePosition(paramType, nodeId);
2414
+ }
2415
+ }
2416
+ }
2417
+ /**
2418
+ * Walk a C# subtree that is KNOWN to be in a type position
2419
+ * (return type, parameter type, property type, field type, generic
2420
+ * argument). Identifiers here are type names, not parameter names.
2421
+ */
2422
+ walkCsharpTypePosition(node, fromNodeId) {
2423
+ // `predefined_type` is int/string/bool/etc. — never a project ref.
2424
+ if (node.type === 'predefined_type')
2425
+ return;
2426
+ // Bare type name: `Foo` in `Foo bar`, or the `Foo` inside `List<Foo>`.
2427
+ if (node.type === 'identifier') {
2428
+ const name = (0, tree_sitter_helpers_1.getNodeText)(node, this.source);
2429
+ if (name && !this.BUILTIN_TYPES.has(name)) {
2430
+ this.unresolvedReferences.push({
2431
+ fromNodeId,
2432
+ referenceName: name,
2433
+ referenceKind: 'references',
2434
+ line: node.startPosition.row + 1,
2435
+ column: node.startPosition.column,
2436
+ });
2437
+ }
2438
+ return;
2439
+ }
2440
+ // `Namespace.Foo` → the rightmost identifier is the type. Emit the
2441
+ // full qualified name as the reference; the resolver can still match
2442
+ // on the trailing simple name when needed.
2443
+ if (node.type === 'qualified_name') {
2444
+ const text = (0, tree_sitter_helpers_1.getNodeText)(node, this.source);
2445
+ const last = text.split('.').pop() ?? text;
2446
+ if (last && !this.BUILTIN_TYPES.has(last)) {
2447
+ this.unresolvedReferences.push({
2448
+ fromNodeId,
2449
+ referenceName: last,
2450
+ referenceKind: 'references',
2451
+ line: node.startPosition.row + 1,
2452
+ column: node.startPosition.column,
2453
+ });
2454
+ }
2455
+ return;
2456
+ }
2457
+ // `(int Code, Foo Payload)` — tuple element has BOTH a `type` and a
2458
+ // `name` field; descending into all named children would mis-emit
2459
+ // the element name (`Code`, `Payload`) as a type ref. Walk only the
2460
+ // type field.
2461
+ if (node.type === 'tuple_element') {
2462
+ const t = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
2463
+ if (t)
2464
+ this.walkCsharpTypePosition(t, fromNodeId);
2465
+ return;
2466
+ }
2467
+ // Composite type nodes — recurse into named children. Covers
2468
+ // `generic_name` (head identifier + `type_argument_list`),
2469
+ // `nullable_type`, `array_type`, `pointer_type`, `tuple_type`,
2470
+ // `ref_type`, and any newer wrapping shapes the grammar adds.
2471
+ // Identifiers reached here are all type-positional (parameter/field
2472
+ // names are gated out before we descend).
2473
+ for (let i = 0; i < node.namedChildCount; i++) {
2474
+ const child = node.namedChild(i);
2475
+ if (child)
2476
+ this.walkCsharpTypePosition(child, fromNodeId);
2477
+ }
2478
+ }
2479
+ /**
2480
+ * Extract type references from a variable's type annotation.
2481
+ */
2482
+ extractVariableTypeAnnotation(node, nodeId) {
2483
+ if (!this.TYPE_ANNOTATION_LANGUAGES.has(this.language))
2484
+ return;
2485
+ // Find type_annotation child (covers TS `: Type`, Rust `: Type`, etc.)
2486
+ const typeAnnotation = node.namedChildren.find((c) => c.type === 'type_annotation');
2487
+ if (typeAnnotation) {
2488
+ this.extractTypeRefsFromSubtree(typeAnnotation, nodeId);
2489
+ }
2490
+ }
2491
+ /**
2492
+ * Recursively walk a subtree and extract all type_identifier references.
2493
+ * Handles unions, intersections, generics, arrays, etc.
2494
+ */
2495
+ extractTypeRefsFromSubtree(node, fromNodeId) {
2496
+ if (node.type === 'type_identifier') {
2497
+ const typeName = (0, tree_sitter_helpers_1.getNodeText)(node, this.source);
2498
+ if (typeName && !this.BUILTIN_TYPES.has(typeName)) {
2499
+ this.unresolvedReferences.push({
2500
+ fromNodeId,
2501
+ referenceName: typeName,
2502
+ referenceKind: 'references',
2503
+ line: node.startPosition.row + 1,
2504
+ column: node.startPosition.column,
2505
+ });
2506
+ }
2507
+ return; // type_identifier is a leaf
2508
+ }
2509
+ // Recurse into children (handles union_type, intersection_type, generic_type, etc.)
2510
+ for (let i = 0; i < node.namedChildCount; i++) {
2511
+ const child = node.namedChild(i);
2512
+ if (child) {
2513
+ this.extractTypeRefsFromSubtree(child, fromNodeId);
2514
+ }
2515
+ }
2516
+ }
2517
+ /**
2518
+ * Handle Pascal-specific AST structures.
2519
+ * Returns true if the node was fully handled and children should be skipped.
2520
+ */
2521
+ visitPascalNode(node) {
2522
+ const nodeType = node.type;
2523
+ // Unit/Program/Library → module node
2524
+ if (nodeType === 'unit' || nodeType === 'program' || nodeType === 'library') {
2525
+ const moduleNameNode = node.namedChildren.find((c) => c.type === 'moduleName');
2526
+ const name = moduleNameNode ? (0, tree_sitter_helpers_1.getNodeText)(moduleNameNode, this.source) : '';
2527
+ // Fallback to filename without extension if module name is empty
2528
+ const moduleName = name || path.basename(this.filePath).replace(/\.[^.]+$/, '');
2529
+ this.createNode('module', moduleName, node);
2530
+ // Continue visiting children (interface/implementation sections)
2531
+ for (let i = 0; i < node.namedChildCount; i++) {
2532
+ const child = node.namedChild(i);
2533
+ if (child)
2534
+ this.visitNode(child);
2535
+ }
2536
+ return true;
2537
+ }
2538
+ // declType wraps declClass/declIntf/declEnum/type-alias
2539
+ // The name lives on declType, the inner node determines the kind
2540
+ if (nodeType === 'declType') {
2541
+ this.extractPascalDeclType(node);
2542
+ return true;
2543
+ }
2544
+ // declUses → import nodes for each unit name
2545
+ if (nodeType === 'declUses') {
2546
+ this.extractPascalUses(node);
2547
+ return true;
2548
+ }
2549
+ // declConsts → container; visit children for individual declConst
2550
+ if (nodeType === 'declConsts') {
2551
+ for (let i = 0; i < node.namedChildCount; i++) {
2552
+ const child = node.namedChild(i);
2553
+ if (child?.type === 'declConst') {
2554
+ this.extractPascalConst(child);
2555
+ }
2556
+ }
2557
+ return true;
2558
+ }
2559
+ // declConst at top level (outside declConsts)
2560
+ if (nodeType === 'declConst') {
2561
+ this.extractPascalConst(node);
2562
+ return true;
2563
+ }
2564
+ // declTypes → container for type declarations
2565
+ if (nodeType === 'declTypes') {
2566
+ for (let i = 0; i < node.namedChildCount; i++) {
2567
+ const child = node.namedChild(i);
2568
+ if (child)
2569
+ this.visitNode(child);
2570
+ }
2571
+ return true;
2572
+ }
2573
+ // declVars → container for variable declarations
2574
+ if (nodeType === 'declVars') {
2575
+ for (let i = 0; i < node.namedChildCount; i++) {
2576
+ const child = node.namedChild(i);
2577
+ if (child?.type === 'declVar') {
2578
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
2579
+ if (nameNode) {
2580
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2581
+ this.createNode('variable', name, child);
2582
+ }
2583
+ }
2584
+ }
2585
+ return true;
2586
+ }
2587
+ // defProc in implementation section → extract calls but don't create duplicate nodes
2588
+ if (nodeType === 'defProc') {
2589
+ this.extractPascalDefProc(node);
2590
+ return true;
2591
+ }
2592
+ // declProp → property node
2593
+ if (nodeType === 'declProp') {
2594
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2595
+ if (nameNode) {
2596
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2597
+ const visibility = this.extractor.getVisibility?.(node);
2598
+ this.createNode('property', name, node, { visibility });
2599
+ }
2600
+ return true;
2601
+ }
2602
+ // declField → field node
2603
+ if (nodeType === 'declField') {
2604
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2605
+ if (nameNode) {
2606
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2607
+ const visibility = this.extractor.getVisibility?.(node);
2608
+ this.createNode('field', name, node, { visibility });
2609
+ }
2610
+ return true;
2611
+ }
2612
+ // declSection → visit children (propagates visibility via getVisibility)
2613
+ if (nodeType === 'declSection') {
2614
+ for (let i = 0; i < node.namedChildCount; i++) {
2615
+ const child = node.namedChild(i);
2616
+ if (child)
2617
+ this.visitNode(child);
2618
+ }
2619
+ return true;
2620
+ }
2621
+ // exprCall → extract function call reference
2622
+ if (nodeType === 'exprCall') {
2623
+ this.extractPascalCall(node);
2624
+ return true;
2625
+ }
2626
+ // interface/implementation sections → visit children
2627
+ if (nodeType === 'interface' || nodeType === 'implementation') {
2628
+ for (let i = 0; i < node.namedChildCount; i++) {
2629
+ const child = node.namedChild(i);
2630
+ if (child)
2631
+ this.visitNode(child);
2632
+ }
2633
+ return true;
2634
+ }
2635
+ // block (begin..end) → visit for calls
2636
+ if (nodeType === 'block') {
2637
+ this.visitPascalBlock(node);
2638
+ return true;
2639
+ }
2640
+ return false;
2641
+ }
2642
+ /**
2643
+ * Extract a Pascal declType node (class, interface, enum, or type alias)
2644
+ */
2645
+ extractPascalDeclType(node) {
2646
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2647
+ if (!nameNode)
2648
+ return;
2649
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2650
+ // Find the inner type declaration
2651
+ const declClass = node.namedChildren.find((c) => c.type === 'declClass');
2652
+ const declIntf = node.namedChildren.find((c) => c.type === 'declIntf');
2653
+ const typeChild = node.namedChildren.find((c) => c.type === 'type');
2654
+ if (declClass) {
2655
+ const classNode = this.createNode('class', name, node);
2656
+ if (classNode) {
2657
+ // Extract inheritance from typeref children of declClass
2658
+ this.extractPascalInheritance(declClass, classNode.id);
2659
+ // Visit class body
2660
+ this.nodeStack.push(classNode.id);
2661
+ for (let i = 0; i < declClass.namedChildCount; i++) {
2662
+ const child = declClass.namedChild(i);
2663
+ if (child)
2664
+ this.visitNode(child);
2665
+ }
2666
+ this.nodeStack.pop();
2667
+ }
2668
+ }
2669
+ else if (declIntf) {
2670
+ const ifaceNode = this.createNode('interface', name, node);
2671
+ if (ifaceNode) {
2672
+ // Visit interface members
2673
+ this.nodeStack.push(ifaceNode.id);
2674
+ for (let i = 0; i < declIntf.namedChildCount; i++) {
2675
+ const child = declIntf.namedChild(i);
2676
+ if (child)
2677
+ this.visitNode(child);
2678
+ }
2679
+ this.nodeStack.pop();
2680
+ }
2681
+ }
2682
+ else if (typeChild) {
2683
+ // Check if it contains a declEnum
2684
+ const declEnum = typeChild.namedChildren.find((c) => c.type === 'declEnum');
2685
+ if (declEnum) {
2686
+ const enumNode = this.createNode('enum', name, node);
2687
+ if (enumNode) {
2688
+ // Extract enum members
2689
+ this.nodeStack.push(enumNode.id);
2690
+ for (let i = 0; i < declEnum.namedChildCount; i++) {
2691
+ const child = declEnum.namedChild(i);
2692
+ if (child?.type === 'declEnumValue') {
2693
+ const memberName = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
2694
+ if (memberName) {
2695
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(memberName, this.source), child);
2696
+ }
2697
+ }
2698
+ }
2699
+ this.nodeStack.pop();
2700
+ }
2701
+ }
2702
+ else {
2703
+ // Simple type alias: type TFoo = string / type TFoo = Integer
2704
+ this.createNode('type_alias', name, node);
2705
+ }
2706
+ }
2707
+ else {
2708
+ // Fallback: could be a forward declaration or simple alias
2709
+ this.createNode('type_alias', name, node);
2710
+ }
2711
+ }
2712
+ /**
2713
+ * Extract Pascal uses clause into individual import nodes
2714
+ */
2715
+ extractPascalUses(node) {
2716
+ const importText = (0, tree_sitter_helpers_1.getNodeText)(node, this.source).trim();
2717
+ for (let i = 0; i < node.namedChildCount; i++) {
2718
+ const child = node.namedChild(i);
2719
+ if (child?.type === 'moduleName') {
2720
+ const unitName = (0, tree_sitter_helpers_1.getNodeText)(child, this.source);
2721
+ this.createNode('import', unitName, child, {
2722
+ signature: importText,
2723
+ });
2724
+ // Create unresolved reference for resolution
2725
+ if (this.nodeStack.length > 0) {
2726
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
2727
+ if (parentId) {
2728
+ this.unresolvedReferences.push({
2729
+ fromNodeId: parentId,
2730
+ referenceName: unitName,
2731
+ referenceKind: 'imports',
2732
+ line: child.startPosition.row + 1,
2733
+ column: child.startPosition.column,
2734
+ });
2735
+ }
2736
+ }
2737
+ }
2738
+ }
2739
+ }
2740
+ /**
2741
+ * Extract a Pascal constant declaration
2742
+ */
2743
+ extractPascalConst(node) {
2744
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2745
+ if (!nameNode)
2746
+ return;
2747
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2748
+ const defaultValue = node.namedChildren.find((c) => c.type === 'defaultValue');
2749
+ const sig = defaultValue ? (0, tree_sitter_helpers_1.getNodeText)(defaultValue, this.source) : undefined;
2750
+ this.createNode('constant', name, node, { signature: sig });
2751
+ }
2752
+ /**
2753
+ * Extract Pascal inheritance (extends/implements) from declClass typeref children
2754
+ */
2755
+ extractPascalInheritance(declClass, classId) {
2756
+ const typerefs = declClass.namedChildren.filter((c) => c.type === 'typeref');
2757
+ for (let i = 0; i < typerefs.length; i++) {
2758
+ const ref = typerefs[i];
2759
+ const name = (0, tree_sitter_helpers_1.getNodeText)(ref, this.source);
2760
+ this.unresolvedReferences.push({
2761
+ fromNodeId: classId,
2762
+ referenceName: name,
2763
+ referenceKind: i === 0 ? 'extends' : 'implements',
2764
+ line: ref.startPosition.row + 1,
2765
+ column: ref.startPosition.column,
2766
+ });
2767
+ }
2768
+ }
2769
+ /**
2770
+ * Extract calls and resolve method context from a Pascal defProc (implementation body).
2771
+ * Does not create a new node — the declaration was already captured from the interface section.
2772
+ */
2773
+ extractPascalDefProc(node) {
2774
+ // Find the matching declaration node by name to use as call parent
2775
+ const declProc = node.namedChildren.find((c) => c.type === 'declProc');
2776
+ if (!declProc)
2777
+ return;
2778
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(declProc, 'name');
2779
+ if (!nameNode)
2780
+ return;
2781
+ const fullName = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source).trim();
2782
+ // fullName is like "TAuthService.Create"
2783
+ const shortName = fullName.includes('.') ? fullName.split('.').pop() : fullName;
2784
+ const fullNameKey = fullName.toLowerCase();
2785
+ const shortNameKey = shortName.toLowerCase();
2786
+ // Build method index on first use (O(n) once, then O(1) per lookup)
2787
+ if (!this.methodIndex) {
2788
+ this.methodIndex = new Map();
2789
+ for (const n of this.nodes) {
2790
+ if (n.kind === 'method' || n.kind === 'function') {
2791
+ const nameKey = n.name.toLowerCase();
2792
+ // Keep first seen short-name mapping to avoid silently overwriting earlier entries.
2793
+ if (!this.methodIndex.has(nameKey)) {
2794
+ this.methodIndex.set(nameKey, n.id);
2795
+ }
2796
+ // For Pascal methods, also index qualified forms (e.g. TAuthService.Create).
2797
+ if (n.kind === 'method') {
2798
+ const qualifiedParts = n.qualifiedName.split('::');
2799
+ if (qualifiedParts.length >= 2) {
2800
+ // Create suffix keys so both "Module.Class.Method" and "Class.Method" can resolve.
2801
+ for (let i = 0; i < qualifiedParts.length - 1; i++) {
2802
+ const scopedName = qualifiedParts.slice(i).join('.').toLowerCase();
2803
+ this.methodIndex.set(scopedName, n.id);
2804
+ }
2805
+ }
2806
+ }
2807
+ }
2808
+ }
2809
+ }
2810
+ const parentId = this.methodIndex.get(fullNameKey) ||
2811
+ this.methodIndex.get(shortNameKey) ||
2812
+ this.nodeStack[this.nodeStack.length - 1];
2813
+ if (!parentId)
2814
+ return;
2815
+ // Visit the block for calls
2816
+ const block = node.namedChildren.find((c) => c.type === 'block');
2817
+ if (block) {
2818
+ this.nodeStack.push(parentId);
2819
+ this.visitPascalBlock(block);
2820
+ this.nodeStack.pop();
2821
+ }
2822
+ }
2823
+ /**
2824
+ * Extract function calls from a Pascal expression
2825
+ */
2826
+ extractPascalCall(node) {
2827
+ if (this.nodeStack.length === 0)
2828
+ return;
2829
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
2830
+ if (!callerId)
2831
+ return;
2832
+ // Get the callee name — first child is typically the identifier or exprDot
2833
+ const firstChild = node.namedChild(0);
2834
+ if (!firstChild)
2835
+ return;
2836
+ let calleeName = '';
2837
+ if (firstChild.type === 'exprDot') {
2838
+ // Qualified call: Obj.Method(...)
2839
+ const identifiers = firstChild.namedChildren.filter((c) => c.type === 'identifier');
2840
+ if (identifiers.length > 0) {
2841
+ calleeName = identifiers.map((id) => (0, tree_sitter_helpers_1.getNodeText)(id, this.source)).join('.');
2842
+ }
2843
+ }
2844
+ else if (firstChild.type === 'identifier') {
2845
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(firstChild, this.source);
2846
+ }
2847
+ if (calleeName) {
2848
+ this.unresolvedReferences.push({
2849
+ fromNodeId: callerId,
2850
+ referenceName: calleeName,
2851
+ referenceKind: 'calls',
2852
+ line: node.startPosition.row + 1,
2853
+ column: node.startPosition.column,
2854
+ });
2855
+ }
2856
+ // Also visit arguments for nested calls
2857
+ const args = node.namedChildren.find((c) => c.type === 'exprArgs');
2858
+ if (args) {
2859
+ this.visitPascalBlock(args);
2860
+ }
2861
+ }
2862
+ /**
2863
+ * Recursively visit a Pascal block/statement tree for call expressions
2864
+ */
2865
+ visitPascalBlock(node) {
2866
+ for (let i = 0; i < node.namedChildCount; i++) {
2867
+ const child = node.namedChild(i);
2868
+ if (!child)
2869
+ continue;
2870
+ if (child.type === 'exprCall') {
2871
+ this.extractPascalCall(child);
2872
+ }
2873
+ else if (child.type === 'exprDot') {
2874
+ // Check if exprDot contains an exprCall
2875
+ for (let j = 0; j < child.namedChildCount; j++) {
2876
+ const grandchild = child.namedChild(j);
2877
+ if (grandchild?.type === 'exprCall') {
2878
+ this.extractPascalCall(grandchild);
2879
+ }
2880
+ }
2881
+ }
2882
+ else {
2883
+ this.visitPascalBlock(child);
2884
+ }
2885
+ }
2886
+ }
2887
+ }
2888
+ exports.TreeSitterExtractor = TreeSitterExtractor;
2889
+ /**
2890
+ * Extract nodes and edges from source code.
2891
+ *
2892
+ * If `frameworkNames` is provided, framework-specific extractors matching
2893
+ * those names and the file's language are run after the tree-sitter pass.
2894
+ * Their nodes/references/errors are merged into the returned result.
2895
+ */
2896
+ function extractFromSource(filePath, source, language, frameworkNames) {
2897
+ const detectedLanguage = language || (0, grammars_1.detectLanguage)(filePath, source);
2898
+ const fileExtension = path.extname(filePath).toLowerCase();
2899
+ let result;
2900
+ // Use custom extractor for Svelte
2901
+ if (detectedLanguage === 'svelte') {
2902
+ const extractor = new svelte_extractor_1.SvelteExtractor(filePath, source);
2903
+ result = extractor.extract();
2904
+ }
2905
+ else if (detectedLanguage === 'vue') {
2906
+ // Use custom extractor for Vue
2907
+ const extractor = new vue_extractor_1.VueExtractor(filePath, source);
2908
+ result = extractor.extract();
2909
+ }
2910
+ else if (detectedLanguage === 'liquid') {
2911
+ // Use custom extractor for Liquid
2912
+ const extractor = new liquid_extractor_1.LiquidExtractor(filePath, source);
2913
+ result = extractor.extract();
2914
+ }
2915
+ else if (detectedLanguage === 'xml') {
2916
+ // Custom extractor for MyBatis mapper XML. Non-mapper XML returns just a
2917
+ // file node so the watcher tracks it without emitting symbols.
2918
+ const extractor = new mybatis_extractor_1.MyBatisExtractor(filePath, source);
2919
+ result = extractor.extract();
2920
+ }
2921
+ else if (detectedLanguage === 'yaml' || detectedLanguage === 'twig' || detectedLanguage === 'properties') {
2922
+ // No symbol extraction at this stage — files are tracked at the file-record
2923
+ // level only. Framework extractors (Drupal routing yml, Spring `@Value`
2924
+ // resolution against application.yml/application.properties) run later and
2925
+ // add per-file nodes/references when they apply.
2926
+ result = { nodes: [], edges: [], unresolvedReferences: [], errors: [], durationMs: 0 };
2927
+ }
2928
+ else if (detectedLanguage === 'pascal' &&
2929
+ (fileExtension === '.dfm' || fileExtension === '.fmx')) {
2930
+ // Use custom extractor for DFM/FMX form files
2931
+ const extractor = new dfm_extractor_1.DfmExtractor(filePath, source);
2932
+ result = extractor.extract();
2933
+ }
2934
+ else {
2935
+ const extractor = new TreeSitterExtractor(filePath, source, detectedLanguage);
2936
+ result = extractor.extract();
2937
+ }
2938
+ // Framework-specific extraction (routes, middleware, etc.)
2939
+ if (frameworkNames && frameworkNames.length > 0) {
2940
+ const allResolvers = (0, frameworks_1.getAllFrameworkResolvers)();
2941
+ const applicable = (0, frameworks_1.getApplicableFrameworks)(allResolvers.filter((r) => frameworkNames.includes(r.name)), detectedLanguage);
2942
+ for (const fw of applicable) {
2943
+ if (!fw.extract)
2944
+ continue;
2945
+ try {
2946
+ const fwResult = fw.extract(filePath, source);
2947
+ result.nodes.push(...fwResult.nodes);
2948
+ result.unresolvedReferences.push(...fwResult.references);
2949
+ }
2950
+ catch (err) {
2951
+ result.errors.push({
2952
+ message: `Framework extractor '${fw.name}' failed: ${err instanceof Error ? err.message : String(err)}`,
2953
+ filePath,
2954
+ severity: 'warning',
2955
+ });
2956
+ }
2957
+ }
2958
+ }
2959
+ return result;
2960
+ }
2961
+ //# sourceMappingURL=tree-sitter.js.map