@colbymchenry/codegraph-darwin-arm64 0.9.0

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 (569) hide show
  1. package/bin/codegraph +3 -0
  2. package/lib/dist/bin/codegraph.d.ts +21 -0
  3. package/lib/dist/bin/codegraph.d.ts.map +1 -0
  4. package/lib/dist/bin/codegraph.js +1273 -0
  5. package/lib/dist/bin/codegraph.js.map +1 -0
  6. package/lib/dist/bin/node-version-check.d.ts +37 -0
  7. package/lib/dist/bin/node-version-check.d.ts.map +1 -0
  8. package/lib/dist/bin/node-version-check.js +79 -0
  9. package/lib/dist/bin/node-version-check.js.map +1 -0
  10. package/lib/dist/bin/uninstall.d.ts +14 -0
  11. package/lib/dist/bin/uninstall.d.ts.map +1 -0
  12. package/lib/dist/bin/uninstall.js +36 -0
  13. package/lib/dist/bin/uninstall.js.map +1 -0
  14. package/lib/dist/config.d.ts +51 -0
  15. package/lib/dist/config.d.ts.map +1 -0
  16. package/lib/dist/config.js +321 -0
  17. package/lib/dist/config.js.map +1 -0
  18. package/lib/dist/context/formatter.d.ts +30 -0
  19. package/lib/dist/context/formatter.d.ts.map +1 -0
  20. package/lib/dist/context/formatter.js +244 -0
  21. package/lib/dist/context/formatter.js.map +1 -0
  22. package/lib/dist/context/index.d.ts +97 -0
  23. package/lib/dist/context/index.d.ts.map +1 -0
  24. package/lib/dist/context/index.js +1050 -0
  25. package/lib/dist/context/index.js.map +1 -0
  26. package/lib/dist/db/index.d.ts +83 -0
  27. package/lib/dist/db/index.d.ts.map +1 -0
  28. package/lib/dist/db/index.js +219 -0
  29. package/lib/dist/db/index.js.map +1 -0
  30. package/lib/dist/db/migrations.d.ts +44 -0
  31. package/lib/dist/db/migrations.d.ts.map +1 -0
  32. package/lib/dist/db/migrations.js +131 -0
  33. package/lib/dist/db/migrations.js.map +1 -0
  34. package/lib/dist/db/queries.d.ts +253 -0
  35. package/lib/dist/db/queries.d.ts.map +1 -0
  36. package/lib/dist/db/queries.js +1207 -0
  37. package/lib/dist/db/queries.js.map +1 -0
  38. package/lib/dist/db/schema.sql +151 -0
  39. package/lib/dist/db/sqlite-adapter.d.ts +46 -0
  40. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -0
  41. package/lib/dist/db/sqlite-adapter.js +114 -0
  42. package/lib/dist/db/sqlite-adapter.js.map +1 -0
  43. package/lib/dist/directory.d.ts +57 -0
  44. package/lib/dist/directory.d.ts.map +1 -0
  45. package/lib/dist/directory.js +264 -0
  46. package/lib/dist/directory.js.map +1 -0
  47. package/lib/dist/errors.d.ts +136 -0
  48. package/lib/dist/errors.d.ts.map +1 -0
  49. package/lib/dist/errors.js +219 -0
  50. package/lib/dist/errors.js.map +1 -0
  51. package/lib/dist/extraction/dfm-extractor.d.ts +31 -0
  52. package/lib/dist/extraction/dfm-extractor.d.ts.map +1 -0
  53. package/lib/dist/extraction/dfm-extractor.js +151 -0
  54. package/lib/dist/extraction/dfm-extractor.js.map +1 -0
  55. package/lib/dist/extraction/grammars.d.ts +78 -0
  56. package/lib/dist/extraction/grammars.d.ts.map +1 -0
  57. package/lib/dist/extraction/grammars.js +332 -0
  58. package/lib/dist/extraction/grammars.js.map +1 -0
  59. package/lib/dist/extraction/index.d.ts +130 -0
  60. package/lib/dist/extraction/index.d.ts.map +1 -0
  61. package/lib/dist/extraction/index.js +1305 -0
  62. package/lib/dist/extraction/index.js.map +1 -0
  63. package/lib/dist/extraction/languages/c-cpp.d.ts +4 -0
  64. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  65. package/lib/dist/extraction/languages/c-cpp.js +126 -0
  66. package/lib/dist/extraction/languages/c-cpp.js.map +1 -0
  67. package/lib/dist/extraction/languages/csharp.d.ts +3 -0
  68. package/lib/dist/extraction/languages/csharp.d.ts.map +1 -0
  69. package/lib/dist/extraction/languages/csharp.js +72 -0
  70. package/lib/dist/extraction/languages/csharp.js.map +1 -0
  71. package/lib/dist/extraction/languages/dart.d.ts +3 -0
  72. package/lib/dist/extraction/languages/dart.d.ts.map +1 -0
  73. package/lib/dist/extraction/languages/dart.js +192 -0
  74. package/lib/dist/extraction/languages/dart.js.map +1 -0
  75. package/lib/dist/extraction/languages/go.d.ts +3 -0
  76. package/lib/dist/extraction/languages/go.d.ts.map +1 -0
  77. package/lib/dist/extraction/languages/go.js +58 -0
  78. package/lib/dist/extraction/languages/go.js.map +1 -0
  79. package/lib/dist/extraction/languages/index.d.ts +10 -0
  80. package/lib/dist/extraction/languages/index.d.ts.map +1 -0
  81. package/lib/dist/extraction/languages/index.js +49 -0
  82. package/lib/dist/extraction/languages/index.js.map +1 -0
  83. package/lib/dist/extraction/languages/java.d.ts +3 -0
  84. package/lib/dist/extraction/languages/java.d.ts.map +1 -0
  85. package/lib/dist/extraction/languages/java.js +64 -0
  86. package/lib/dist/extraction/languages/java.js.map +1 -0
  87. package/lib/dist/extraction/languages/javascript.d.ts +3 -0
  88. package/lib/dist/extraction/languages/javascript.d.ts.map +1 -0
  89. package/lib/dist/extraction/languages/javascript.js +90 -0
  90. package/lib/dist/extraction/languages/javascript.js.map +1 -0
  91. package/lib/dist/extraction/languages/kotlin.d.ts +3 -0
  92. package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -0
  93. package/lib/dist/extraction/languages/kotlin.js +253 -0
  94. package/lib/dist/extraction/languages/kotlin.js.map +1 -0
  95. package/lib/dist/extraction/languages/lua.d.ts +3 -0
  96. package/lib/dist/extraction/languages/lua.d.ts.map +1 -0
  97. package/lib/dist/extraction/languages/lua.js +150 -0
  98. package/lib/dist/extraction/languages/lua.js.map +1 -0
  99. package/lib/dist/extraction/languages/luau.d.ts +3 -0
  100. package/lib/dist/extraction/languages/luau.d.ts.map +1 -0
  101. package/lib/dist/extraction/languages/luau.js +37 -0
  102. package/lib/dist/extraction/languages/luau.js.map +1 -0
  103. package/lib/dist/extraction/languages/pascal.d.ts +3 -0
  104. package/lib/dist/extraction/languages/pascal.d.ts.map +1 -0
  105. package/lib/dist/extraction/languages/pascal.js +66 -0
  106. package/lib/dist/extraction/languages/pascal.js.map +1 -0
  107. package/lib/dist/extraction/languages/php.d.ts +3 -0
  108. package/lib/dist/extraction/languages/php.d.ts.map +1 -0
  109. package/lib/dist/extraction/languages/php.js +107 -0
  110. package/lib/dist/extraction/languages/php.js.map +1 -0
  111. package/lib/dist/extraction/languages/python.d.ts +3 -0
  112. package/lib/dist/extraction/languages/python.d.ts.map +1 -0
  113. package/lib/dist/extraction/languages/python.js +56 -0
  114. package/lib/dist/extraction/languages/python.js.map +1 -0
  115. package/lib/dist/extraction/languages/ruby.d.ts +3 -0
  116. package/lib/dist/extraction/languages/ruby.d.ts.map +1 -0
  117. package/lib/dist/extraction/languages/ruby.js +114 -0
  118. package/lib/dist/extraction/languages/ruby.js.map +1 -0
  119. package/lib/dist/extraction/languages/rust.d.ts +3 -0
  120. package/lib/dist/extraction/languages/rust.d.ts.map +1 -0
  121. package/lib/dist/extraction/languages/rust.js +109 -0
  122. package/lib/dist/extraction/languages/rust.js.map +1 -0
  123. package/lib/dist/extraction/languages/scala.d.ts +3 -0
  124. package/lib/dist/extraction/languages/scala.d.ts.map +1 -0
  125. package/lib/dist/extraction/languages/scala.js +139 -0
  126. package/lib/dist/extraction/languages/scala.js.map +1 -0
  127. package/lib/dist/extraction/languages/swift.d.ts +3 -0
  128. package/lib/dist/extraction/languages/swift.d.ts.map +1 -0
  129. package/lib/dist/extraction/languages/swift.js +91 -0
  130. package/lib/dist/extraction/languages/swift.js.map +1 -0
  131. package/lib/dist/extraction/languages/typescript.d.ts +3 -0
  132. package/lib/dist/extraction/languages/typescript.d.ts.map +1 -0
  133. package/lib/dist/extraction/languages/typescript.js +129 -0
  134. package/lib/dist/extraction/languages/typescript.js.map +1 -0
  135. package/lib/dist/extraction/liquid-extractor.d.ts +52 -0
  136. package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -0
  137. package/lib/dist/extraction/liquid-extractor.js +313 -0
  138. package/lib/dist/extraction/liquid-extractor.js.map +1 -0
  139. package/lib/dist/extraction/parse-worker.d.ts +8 -0
  140. package/lib/dist/extraction/parse-worker.d.ts.map +1 -0
  141. package/lib/dist/extraction/parse-worker.js +94 -0
  142. package/lib/dist/extraction/parse-worker.js.map +1 -0
  143. package/lib/dist/extraction/svelte-extractor.d.ts +56 -0
  144. package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -0
  145. package/lib/dist/extraction/svelte-extractor.js +272 -0
  146. package/lib/dist/extraction/svelte-extractor.js.map +1 -0
  147. package/lib/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  148. package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  149. package/lib/dist/extraction/tree-sitter-helpers.js +103 -0
  150. package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -0
  151. package/lib/dist/extraction/tree-sitter-types.d.ts +179 -0
  152. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  153. package/lib/dist/extraction/tree-sitter-types.js +10 -0
  154. package/lib/dist/extraction/tree-sitter-types.js.map +1 -0
  155. package/lib/dist/extraction/tree-sitter.d.ts +233 -0
  156. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -0
  157. package/lib/dist/extraction/tree-sitter.js +2425 -0
  158. package/lib/dist/extraction/tree-sitter.js.map +1 -0
  159. package/lib/dist/extraction/vue-extractor.d.ts +36 -0
  160. package/lib/dist/extraction/vue-extractor.d.ts.map +1 -0
  161. package/lib/dist/extraction/vue-extractor.js +163 -0
  162. package/lib/dist/extraction/vue-extractor.js.map +1 -0
  163. package/lib/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  164. package/lib/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  165. package/lib/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  166. package/lib/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  167. package/lib/dist/graph/index.d.ts +8 -0
  168. package/lib/dist/graph/index.d.ts.map +1 -0
  169. package/lib/dist/graph/index.js +13 -0
  170. package/lib/dist/graph/index.js.map +1 -0
  171. package/lib/dist/graph/queries.d.ts +106 -0
  172. package/lib/dist/graph/queries.d.ts.map +1 -0
  173. package/lib/dist/graph/queries.js +366 -0
  174. package/lib/dist/graph/queries.js.map +1 -0
  175. package/lib/dist/graph/traversal.d.ts +127 -0
  176. package/lib/dist/graph/traversal.d.ts.map +1 -0
  177. package/lib/dist/graph/traversal.js +493 -0
  178. package/lib/dist/graph/traversal.js.map +1 -0
  179. package/lib/dist/index.d.ts +453 -0
  180. package/lib/dist/index.d.ts.map +1 -0
  181. package/lib/dist/index.js +833 -0
  182. package/lib/dist/index.js.map +1 -0
  183. package/lib/dist/installer/claude-md-template.d.ts +14 -0
  184. package/lib/dist/installer/claude-md-template.d.ts.map +1 -0
  185. package/lib/dist/installer/claude-md-template.js +21 -0
  186. package/lib/dist/installer/claude-md-template.js.map +1 -0
  187. package/lib/dist/installer/config-writer.d.ts +29 -0
  188. package/lib/dist/installer/config-writer.d.ts.map +1 -0
  189. package/lib/dist/installer/config-writer.js +111 -0
  190. package/lib/dist/installer/config-writer.js.map +1 -0
  191. package/lib/dist/installer/index.d.ts +65 -0
  192. package/lib/dist/installer/index.d.ts.map +1 -0
  193. package/lib/dist/installer/index.js +406 -0
  194. package/lib/dist/installer/index.js.map +1 -0
  195. package/lib/dist/installer/instructions-template.d.ts +28 -0
  196. package/lib/dist/installer/instructions-template.d.ts.map +1 -0
  197. package/lib/dist/installer/instructions-template.js +64 -0
  198. package/lib/dist/installer/instructions-template.js.map +1 -0
  199. package/lib/dist/installer/targets/claude.d.ts +47 -0
  200. package/lib/dist/installer/targets/claude.d.ts.map +1 -0
  201. package/lib/dist/installer/targets/claude.js +401 -0
  202. package/lib/dist/installer/targets/claude.js.map +1 -0
  203. package/lib/dist/installer/targets/codex.d.ts +18 -0
  204. package/lib/dist/installer/targets/codex.d.ts.map +1 -0
  205. package/lib/dist/installer/targets/codex.js +185 -0
  206. package/lib/dist/installer/targets/codex.js.map +1 -0
  207. package/lib/dist/installer/targets/cursor.d.ts +35 -0
  208. package/lib/dist/installer/targets/cursor.d.ts.map +1 -0
  209. package/lib/dist/installer/targets/cursor.js +229 -0
  210. package/lib/dist/installer/targets/cursor.js.map +1 -0
  211. package/lib/dist/installer/targets/opencode.d.ts +30 -0
  212. package/lib/dist/installer/targets/opencode.d.ts.map +1 -0
  213. package/lib/dist/installer/targets/opencode.js +235 -0
  214. package/lib/dist/installer/targets/opencode.js.map +1 -0
  215. package/lib/dist/installer/targets/registry.d.ts +35 -0
  216. package/lib/dist/installer/targets/registry.d.ts.map +1 -0
  217. package/lib/dist/installer/targets/registry.js +83 -0
  218. package/lib/dist/installer/targets/registry.js.map +1 -0
  219. package/lib/dist/installer/targets/shared.d.ts +77 -0
  220. package/lib/dist/installer/targets/shared.d.ts.map +1 -0
  221. package/lib/dist/installer/targets/shared.js +246 -0
  222. package/lib/dist/installer/targets/shared.js.map +1 -0
  223. package/lib/dist/installer/targets/toml.d.ts +52 -0
  224. package/lib/dist/installer/targets/toml.d.ts.map +1 -0
  225. package/lib/dist/installer/targets/toml.js +147 -0
  226. package/lib/dist/installer/targets/toml.js.map +1 -0
  227. package/lib/dist/installer/targets/types.d.ts +116 -0
  228. package/lib/dist/installer/targets/types.d.ts.map +1 -0
  229. package/lib/dist/installer/targets/types.js +16 -0
  230. package/lib/dist/installer/targets/types.js.map +1 -0
  231. package/lib/dist/mcp/index.d.ts +94 -0
  232. package/lib/dist/mcp/index.d.ts.map +1 -0
  233. package/lib/dist/mcp/index.js +453 -0
  234. package/lib/dist/mcp/index.js.map +1 -0
  235. package/lib/dist/mcp/server-instructions.d.ts +19 -0
  236. package/lib/dist/mcp/server-instructions.d.ts.map +1 -0
  237. package/lib/dist/mcp/server-instructions.js +71 -0
  238. package/lib/dist/mcp/server-instructions.js.map +1 -0
  239. package/lib/dist/mcp/tools.d.ts +257 -0
  240. package/lib/dist/mcp/tools.d.ts.map +1 -0
  241. package/lib/dist/mcp/tools.js +1646 -0
  242. package/lib/dist/mcp/tools.js.map +1 -0
  243. package/lib/dist/mcp/transport.d.ts +106 -0
  244. package/lib/dist/mcp/transport.d.ts.map +1 -0
  245. package/lib/dist/mcp/transport.js +233 -0
  246. package/lib/dist/mcp/transport.js.map +1 -0
  247. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  248. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  249. package/lib/dist/resolution/frameworks/cargo-workspace.js +225 -0
  250. package/lib/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  251. package/lib/dist/resolution/frameworks/csharp.d.ts +8 -0
  252. package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  253. package/lib/dist/resolution/frameworks/csharp.js +213 -0
  254. package/lib/dist/resolution/frameworks/csharp.js.map +1 -0
  255. package/lib/dist/resolution/frameworks/express.d.ts +8 -0
  256. package/lib/dist/resolution/frameworks/express.d.ts.map +1 -0
  257. package/lib/dist/resolution/frameworks/express.js +225 -0
  258. package/lib/dist/resolution/frameworks/express.js.map +1 -0
  259. package/lib/dist/resolution/frameworks/go.d.ts +8 -0
  260. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -0
  261. package/lib/dist/resolution/frameworks/go.js +158 -0
  262. package/lib/dist/resolution/frameworks/go.js.map +1 -0
  263. package/lib/dist/resolution/frameworks/index.d.ts +42 -0
  264. package/lib/dist/resolution/frameworks/index.d.ts.map +1 -0
  265. package/lib/dist/resolution/frameworks/index.js +133 -0
  266. package/lib/dist/resolution/frameworks/index.js.map +1 -0
  267. package/lib/dist/resolution/frameworks/java.d.ts +8 -0
  268. package/lib/dist/resolution/frameworks/java.d.ts.map +1 -0
  269. package/lib/dist/resolution/frameworks/java.js +177 -0
  270. package/lib/dist/resolution/frameworks/java.js.map +1 -0
  271. package/lib/dist/resolution/frameworks/laravel.d.ts +13 -0
  272. package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  273. package/lib/dist/resolution/frameworks/laravel.js +248 -0
  274. package/lib/dist/resolution/frameworks/laravel.js.map +1 -0
  275. package/lib/dist/resolution/frameworks/nestjs.d.ts +26 -0
  276. package/lib/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  277. package/lib/dist/resolution/frameworks/nestjs.js +374 -0
  278. package/lib/dist/resolution/frameworks/nestjs.js.map +1 -0
  279. package/lib/dist/resolution/frameworks/python.d.ts +10 -0
  280. package/lib/dist/resolution/frameworks/python.d.ts.map +1 -0
  281. package/lib/dist/resolution/frameworks/python.js +278 -0
  282. package/lib/dist/resolution/frameworks/python.js.map +1 -0
  283. package/lib/dist/resolution/frameworks/react.d.ts +8 -0
  284. package/lib/dist/resolution/frameworks/react.d.ts.map +1 -0
  285. package/lib/dist/resolution/frameworks/react.js +272 -0
  286. package/lib/dist/resolution/frameworks/react.js.map +1 -0
  287. package/lib/dist/resolution/frameworks/ruby.d.ts +8 -0
  288. package/lib/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  289. package/lib/dist/resolution/frameworks/ruby.js +198 -0
  290. package/lib/dist/resolution/frameworks/ruby.js.map +1 -0
  291. package/lib/dist/resolution/frameworks/rust.d.ts +8 -0
  292. package/lib/dist/resolution/frameworks/rust.d.ts.map +1 -0
  293. package/lib/dist/resolution/frameworks/rust.js +207 -0
  294. package/lib/dist/resolution/frameworks/rust.js.map +1 -0
  295. package/lib/dist/resolution/frameworks/svelte.d.ts +9 -0
  296. package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  297. package/lib/dist/resolution/frameworks/svelte.js +249 -0
  298. package/lib/dist/resolution/frameworks/svelte.js.map +1 -0
  299. package/lib/dist/resolution/frameworks/swift.d.ts +10 -0
  300. package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -0
  301. package/lib/dist/resolution/frameworks/swift.js +376 -0
  302. package/lib/dist/resolution/frameworks/swift.js.map +1 -0
  303. package/lib/dist/resolution/frameworks/vue.d.ts +9 -0
  304. package/lib/dist/resolution/frameworks/vue.d.ts.map +1 -0
  305. package/lib/dist/resolution/frameworks/vue.js +306 -0
  306. package/lib/dist/resolution/frameworks/vue.js.map +1 -0
  307. package/lib/dist/resolution/import-resolver.d.ts +40 -0
  308. package/lib/dist/resolution/import-resolver.d.ts.map +1 -0
  309. package/lib/dist/resolution/import-resolver.js +663 -0
  310. package/lib/dist/resolution/import-resolver.js.map +1 -0
  311. package/lib/dist/resolution/index.d.ts +106 -0
  312. package/lib/dist/resolution/index.d.ts.map +1 -0
  313. package/lib/dist/resolution/index.js +709 -0
  314. package/lib/dist/resolution/index.js.map +1 -0
  315. package/lib/dist/resolution/name-matcher.d.ts +32 -0
  316. package/lib/dist/resolution/name-matcher.d.ts.map +1 -0
  317. package/lib/dist/resolution/name-matcher.js +384 -0
  318. package/lib/dist/resolution/name-matcher.js.map +1 -0
  319. package/lib/dist/resolution/path-aliases.d.ts +68 -0
  320. package/lib/dist/resolution/path-aliases.d.ts.map +1 -0
  321. package/lib/dist/resolution/path-aliases.js +238 -0
  322. package/lib/dist/resolution/path-aliases.js.map +1 -0
  323. package/lib/dist/resolution/strip-comments.d.ts +27 -0
  324. package/lib/dist/resolution/strip-comments.d.ts.map +1 -0
  325. package/lib/dist/resolution/strip-comments.js +441 -0
  326. package/lib/dist/resolution/strip-comments.js.map +1 -0
  327. package/lib/dist/resolution/types.d.ts +172 -0
  328. package/lib/dist/resolution/types.d.ts.map +1 -0
  329. package/lib/dist/resolution/types.js +8 -0
  330. package/lib/dist/resolution/types.js.map +1 -0
  331. package/lib/dist/search/query-parser.d.ts +57 -0
  332. package/lib/dist/search/query-parser.d.ts.map +1 -0
  333. package/lib/dist/search/query-parser.js +177 -0
  334. package/lib/dist/search/query-parser.js.map +1 -0
  335. package/lib/dist/search/query-utils.d.ts +53 -0
  336. package/lib/dist/search/query-utils.d.ts.map +1 -0
  337. package/lib/dist/search/query-utils.js +350 -0
  338. package/lib/dist/search/query-utils.js.map +1 -0
  339. package/lib/dist/sync/git-hooks.d.ts +45 -0
  340. package/lib/dist/sync/git-hooks.d.ts.map +1 -0
  341. package/lib/dist/sync/git-hooks.js +223 -0
  342. package/lib/dist/sync/git-hooks.js.map +1 -0
  343. package/lib/dist/sync/index.d.ts +17 -0
  344. package/lib/dist/sync/index.d.ts.map +1 -0
  345. package/lib/dist/sync/index.js +28 -0
  346. package/lib/dist/sync/index.js.map +1 -0
  347. package/lib/dist/sync/watch-policy.d.ts +48 -0
  348. package/lib/dist/sync/watch-policy.d.ts.map +1 -0
  349. package/lib/dist/sync/watch-policy.js +124 -0
  350. package/lib/dist/sync/watch-policy.js.map +1 -0
  351. package/lib/dist/sync/watcher.d.ts +81 -0
  352. package/lib/dist/sync/watcher.d.ts.map +1 -0
  353. package/lib/dist/sync/watcher.js +194 -0
  354. package/lib/dist/sync/watcher.js.map +1 -0
  355. package/lib/dist/types.d.ts +423 -0
  356. package/lib/dist/types.d.ts.map +1 -0
  357. package/lib/dist/types.js +262 -0
  358. package/lib/dist/types.js.map +1 -0
  359. package/lib/dist/ui/glyphs.d.ts +42 -0
  360. package/lib/dist/ui/glyphs.d.ts.map +1 -0
  361. package/lib/dist/ui/glyphs.js +78 -0
  362. package/lib/dist/ui/glyphs.js.map +1 -0
  363. package/lib/dist/ui/shimmer-progress.d.ts +11 -0
  364. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -0
  365. package/lib/dist/ui/shimmer-progress.js +90 -0
  366. package/lib/dist/ui/shimmer-progress.js.map +1 -0
  367. package/lib/dist/ui/shimmer-worker.d.ts +2 -0
  368. package/lib/dist/ui/shimmer-worker.d.ts.map +1 -0
  369. package/lib/dist/ui/shimmer-worker.js +118 -0
  370. package/lib/dist/ui/shimmer-worker.js.map +1 -0
  371. package/lib/dist/ui/types.d.ts +17 -0
  372. package/lib/dist/ui/types.d.ts.map +1 -0
  373. package/lib/dist/ui/types.js +3 -0
  374. package/lib/dist/ui/types.js.map +1 -0
  375. package/lib/dist/utils.d.ts +205 -0
  376. package/lib/dist/utils.d.ts.map +1 -0
  377. package/lib/dist/utils.js +549 -0
  378. package/lib/dist/utils.js.map +1 -0
  379. package/lib/node_modules/.package-lock.json +116 -0
  380. package/lib/node_modules/@clack/core/CHANGELOG.md +348 -0
  381. package/lib/node_modules/@clack/core/LICENSE +9 -0
  382. package/lib/node_modules/@clack/core/README.md +22 -0
  383. package/lib/node_modules/@clack/core/dist/index.d.mts +363 -0
  384. package/lib/node_modules/@clack/core/dist/index.mjs +17 -0
  385. package/lib/node_modules/@clack/core/dist/index.mjs.map +1 -0
  386. package/lib/node_modules/@clack/core/package.json +63 -0
  387. package/lib/node_modules/@clack/prompts/CHANGELOG.md +591 -0
  388. package/lib/node_modules/@clack/prompts/LICENSE +9 -0
  389. package/lib/node_modules/@clack/prompts/README.md +375 -0
  390. package/lib/node_modules/@clack/prompts/dist/index.d.mts +396 -0
  391. package/lib/node_modules/@clack/prompts/dist/index.mjs +144 -0
  392. package/lib/node_modules/@clack/prompts/dist/index.mjs.map +1 -0
  393. package/lib/node_modules/@clack/prompts/package.json +68 -0
  394. package/lib/node_modules/commander/LICENSE +22 -0
  395. package/lib/node_modules/commander/Readme.md +1176 -0
  396. package/lib/node_modules/commander/esm.mjs +16 -0
  397. package/lib/node_modules/commander/index.js +24 -0
  398. package/lib/node_modules/commander/lib/argument.js +150 -0
  399. package/lib/node_modules/commander/lib/command.js +2777 -0
  400. package/lib/node_modules/commander/lib/error.js +39 -0
  401. package/lib/node_modules/commander/lib/help.js +747 -0
  402. package/lib/node_modules/commander/lib/option.js +380 -0
  403. package/lib/node_modules/commander/lib/suggestSimilar.js +101 -0
  404. package/lib/node_modules/commander/package-support.json +19 -0
  405. package/lib/node_modules/commander/package.json +82 -0
  406. package/lib/node_modules/commander/typings/esm.d.mts +3 -0
  407. package/lib/node_modules/commander/typings/index.d.ts +1113 -0
  408. package/lib/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  409. package/lib/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  410. package/lib/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  411. package/lib/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  412. package/lib/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  413. package/lib/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  414. package/lib/node_modules/fast-string-truncated-width/license +21 -0
  415. package/lib/node_modules/fast-string-truncated-width/package.json +35 -0
  416. package/lib/node_modules/fast-string-truncated-width/readme.md +59 -0
  417. package/lib/node_modules/fast-string-width/dist/index.d.ts +4 -0
  418. package/lib/node_modules/fast-string-width/dist/index.js +14 -0
  419. package/lib/node_modules/fast-string-width/license +21 -0
  420. package/lib/node_modules/fast-string-width/package.json +34 -0
  421. package/lib/node_modules/fast-string-width/readme.md +42 -0
  422. package/lib/node_modules/fast-wrap-ansi/LICENSE +23 -0
  423. package/lib/node_modules/fast-wrap-ansi/README.md +26 -0
  424. package/lib/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  425. package/lib/node_modules/fast-wrap-ansi/lib/main.js +219 -0
  426. package/lib/node_modules/fast-wrap-ansi/lib/main.js.map +1 -0
  427. package/lib/node_modules/fast-wrap-ansi/package.json +51 -0
  428. package/lib/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  429. package/lib/node_modules/jsonc-parser/LICENSE.md +21 -0
  430. package/lib/node_modules/jsonc-parser/README.md +364 -0
  431. package/lib/node_modules/jsonc-parser/SECURITY.md +41 -0
  432. package/lib/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  433. package/lib/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  434. package/lib/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  435. package/lib/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  436. package/lib/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  437. package/lib/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  438. package/lib/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  439. package/lib/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  440. package/lib/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  441. package/lib/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  442. package/lib/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  443. package/lib/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  444. package/lib/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  445. package/lib/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  446. package/lib/node_modules/jsonc-parser/package.json +37 -0
  447. package/lib/node_modules/picomatch/LICENSE +21 -0
  448. package/lib/node_modules/picomatch/README.md +738 -0
  449. package/lib/node_modules/picomatch/index.js +17 -0
  450. package/lib/node_modules/picomatch/lib/constants.js +180 -0
  451. package/lib/node_modules/picomatch/lib/parse.js +1085 -0
  452. package/lib/node_modules/picomatch/lib/picomatch.js +341 -0
  453. package/lib/node_modules/picomatch/lib/scan.js +391 -0
  454. package/lib/node_modules/picomatch/lib/utils.js +72 -0
  455. package/lib/node_modules/picomatch/package.json +83 -0
  456. package/lib/node_modules/picomatch/posix.js +3 -0
  457. package/lib/node_modules/sisteransi/license +21 -0
  458. package/lib/node_modules/sisteransi/package.json +34 -0
  459. package/lib/node_modules/sisteransi/readme.md +113 -0
  460. package/lib/node_modules/sisteransi/src/index.js +58 -0
  461. package/lib/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  462. package/lib/node_modules/tree-sitter-wasms/LICENSE +24 -0
  463. package/lib/node_modules/tree-sitter-wasms/README.md +23 -0
  464. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
  465. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
  466. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
  467. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
  468. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
  469. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
  470. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
  471. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
  472. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
  473. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
  474. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
  475. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
  476. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
  477. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
  478. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
  479. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
  480. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
  481. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
  482. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
  483. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
  484. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
  485. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
  486. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
  487. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
  488. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
  489. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
  490. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
  491. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
  492. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
  493. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
  494. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
  495. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
  496. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
  497. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
  498. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
  499. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
  500. package/lib/node_modules/tree-sitter-wasms/package.json +64 -0
  501. package/lib/node_modules/web-tree-sitter/LICENSE +21 -0
  502. package/lib/node_modules/web-tree-sitter/README.md +269 -0
  503. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.cjs +4558 -0
  504. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.cjs.map +7 -0
  505. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.js +4516 -0
  506. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.js.map +7 -0
  507. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.wasm +0 -0
  508. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.wasm.map +31 -0
  509. package/lib/node_modules/web-tree-sitter/lib/alloc.c +48 -0
  510. package/lib/node_modules/web-tree-sitter/lib/alloc.h +41 -0
  511. package/lib/node_modules/web-tree-sitter/lib/array.h +291 -0
  512. package/lib/node_modules/web-tree-sitter/lib/atomic.h +68 -0
  513. package/lib/node_modules/web-tree-sitter/lib/clock.h +146 -0
  514. package/lib/node_modules/web-tree-sitter/lib/error_costs.h +11 -0
  515. package/lib/node_modules/web-tree-sitter/lib/get_changed_ranges.c +523 -0
  516. package/lib/node_modules/web-tree-sitter/lib/get_changed_ranges.h +36 -0
  517. package/lib/node_modules/web-tree-sitter/lib/host.h +21 -0
  518. package/lib/node_modules/web-tree-sitter/lib/language.c +293 -0
  519. package/lib/node_modules/web-tree-sitter/lib/language.h +293 -0
  520. package/lib/node_modules/web-tree-sitter/lib/length.h +52 -0
  521. package/lib/node_modules/web-tree-sitter/lib/lexer.c +483 -0
  522. package/lib/node_modules/web-tree-sitter/lib/lexer.h +54 -0
  523. package/lib/node_modules/web-tree-sitter/lib/lib.c +12 -0
  524. package/lib/node_modules/web-tree-sitter/lib/node.c +875 -0
  525. package/lib/node_modules/web-tree-sitter/lib/parser.c +2297 -0
  526. package/lib/node_modules/web-tree-sitter/lib/parser.h +286 -0
  527. package/lib/node_modules/web-tree-sitter/lib/point.h +48 -0
  528. package/lib/node_modules/web-tree-sitter/lib/query.c +4347 -0
  529. package/lib/node_modules/web-tree-sitter/lib/reduce_action.h +34 -0
  530. package/lib/node_modules/web-tree-sitter/lib/reusable_node.h +95 -0
  531. package/lib/node_modules/web-tree-sitter/lib/stack.c +912 -0
  532. package/lib/node_modules/web-tree-sitter/lib/stack.h +133 -0
  533. package/lib/node_modules/web-tree-sitter/lib/subtree.c +1034 -0
  534. package/lib/node_modules/web-tree-sitter/lib/subtree.h +399 -0
  535. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.c +987 -0
  536. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.cjs +2988 -0
  537. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.wasm +0 -0
  538. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.wasm.map +1 -0
  539. package/lib/node_modules/web-tree-sitter/lib/tree.c +170 -0
  540. package/lib/node_modules/web-tree-sitter/lib/tree.h +31 -0
  541. package/lib/node_modules/web-tree-sitter/lib/tree_cursor.c +716 -0
  542. package/lib/node_modules/web-tree-sitter/lib/tree_cursor.h +48 -0
  543. package/lib/node_modules/web-tree-sitter/lib/ts_assert.h +11 -0
  544. package/lib/node_modules/web-tree-sitter/lib/unicode.h +75 -0
  545. package/lib/node_modules/web-tree-sitter/lib/wasm_store.c +1937 -0
  546. package/lib/node_modules/web-tree-sitter/lib/wasm_store.h +31 -0
  547. package/lib/node_modules/web-tree-sitter/package.json +98 -0
  548. package/lib/node_modules/web-tree-sitter/src/bindings.ts +26 -0
  549. package/lib/node_modules/web-tree-sitter/src/constants.ts +133 -0
  550. package/lib/node_modules/web-tree-sitter/src/index.ts +31 -0
  551. package/lib/node_modules/web-tree-sitter/src/language.ts +291 -0
  552. package/lib/node_modules/web-tree-sitter/src/lookahead_iterator.ts +75 -0
  553. package/lib/node_modules/web-tree-sitter/src/marshal.ts +176 -0
  554. package/lib/node_modules/web-tree-sitter/src/node.ts +646 -0
  555. package/lib/node_modules/web-tree-sitter/src/parser.ts +325 -0
  556. package/lib/node_modules/web-tree-sitter/src/query.ts +973 -0
  557. package/lib/node_modules/web-tree-sitter/src/tree.ts +145 -0
  558. package/lib/node_modules/web-tree-sitter/src/tree_cursor.ts +318 -0
  559. package/lib/node_modules/web-tree-sitter/tree-sitter.cjs +4031 -0
  560. package/lib/node_modules/web-tree-sitter/tree-sitter.cjs.map +7 -0
  561. package/lib/node_modules/web-tree-sitter/tree-sitter.js +3980 -0
  562. package/lib/node_modules/web-tree-sitter/tree-sitter.js.map +7 -0
  563. package/lib/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
  564. package/lib/node_modules/web-tree-sitter/tree-sitter.wasm.map +30 -0
  565. package/lib/node_modules/web-tree-sitter/web-tree-sitter.d.ts +1030 -0
  566. package/lib/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +56 -0
  567. package/lib/package.json +55 -0
  568. package/node +0 -0
  569. package/package.json +17 -0
@@ -0,0 +1,2425 @@
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 frameworks_1 = require("../resolution/frameworks");
52
+ // Re-export for backward compatibility
53
+ var tree_sitter_helpers_2 = require("./tree-sitter-helpers");
54
+ Object.defineProperty(exports, "generateNodeId", { enumerable: true, get: function () { return tree_sitter_helpers_2.generateNodeId; } });
55
+ /**
56
+ * Extract the name from a node based on language
57
+ */
58
+ function extractName(node, source, extractor) {
59
+ // Try field name first
60
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, extractor.nameField);
61
+ if (nameNode) {
62
+ // Unwrap pointer_declarator(s) for C/C++ pointer return types
63
+ let resolved = nameNode;
64
+ while (resolved.type === 'pointer_declarator') {
65
+ const inner = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'declarator') || resolved.namedChild(0);
66
+ if (!inner)
67
+ break;
68
+ resolved = inner;
69
+ }
70
+ // Handle complex declarators (C/C++)
71
+ if (resolved.type === 'function_declarator' || resolved.type === 'declarator') {
72
+ const innerName = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'declarator') || resolved.namedChild(0);
73
+ return innerName ? (0, tree_sitter_helpers_1.getNodeText)(innerName, source) : (0, tree_sitter_helpers_1.getNodeText)(resolved, source);
74
+ }
75
+ // Lua: `function t.f()` / `function t:m()` — the name node is a dot/method
76
+ // index expression; the simple name is the trailing field/method (the table
77
+ // receiver is captured separately via getReceiverType).
78
+ if (resolved.type === 'dot_index_expression') {
79
+ const field = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'field');
80
+ if (field)
81
+ return (0, tree_sitter_helpers_1.getNodeText)(field, source);
82
+ }
83
+ if (resolved.type === 'method_index_expression') {
84
+ const method = (0, tree_sitter_helpers_1.getChildByField)(resolved, 'method');
85
+ if (method)
86
+ return (0, tree_sitter_helpers_1.getNodeText)(method, source);
87
+ }
88
+ return (0, tree_sitter_helpers_1.getNodeText)(resolved, source);
89
+ }
90
+ // For Dart method_signature, look inside inner signature types
91
+ if (node.type === 'method_signature') {
92
+ for (let i = 0; i < node.namedChildCount; i++) {
93
+ const child = node.namedChild(i);
94
+ if (child && (child.type === 'function_signature' ||
95
+ child.type === 'getter_signature' ||
96
+ child.type === 'setter_signature' ||
97
+ child.type === 'constructor_signature' ||
98
+ child.type === 'factory_constructor_signature')) {
99
+ // Find identifier inside the inner signature
100
+ for (let j = 0; j < child.namedChildCount; j++) {
101
+ const inner = child.namedChild(j);
102
+ if (inner?.type === 'identifier') {
103
+ return (0, tree_sitter_helpers_1.getNodeText)(inner, source);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ // Arrow/function expressions get their name from the parent variable_declarator,
110
+ // not from identifiers in their body. Without this, single-expression arrow
111
+ // functions like `const fn = () => someIdentifier` get named "someIdentifier"
112
+ // instead of "fn", because the fallback below finds the body identifier.
113
+ if (node.type === 'arrow_function' || node.type === 'function_expression') {
114
+ return '<anonymous>';
115
+ }
116
+ // Fall back to first identifier child
117
+ for (let i = 0; i < node.namedChildCount; i++) {
118
+ const child = node.namedChild(i);
119
+ if (child &&
120
+ (child.type === 'identifier' ||
121
+ child.type === 'type_identifier' ||
122
+ child.type === 'simple_identifier' ||
123
+ child.type === 'constant')) {
124
+ return (0, tree_sitter_helpers_1.getNodeText)(child, source);
125
+ }
126
+ }
127
+ return '<anonymous>';
128
+ }
129
+ /**
130
+ * Tree-sitter node kinds that represent constructor invocations
131
+ * (`new Foo()` and friends). Used by extractInstantiation to emit
132
+ * an `instantiates` reference targeting the class name.
133
+ */
134
+ const INSTANTIATION_KINDS = new Set([
135
+ 'new_expression', // typescript / javascript / tsx / jsx
136
+ 'object_creation_expression', // java / c#
137
+ 'instance_creation_expression', // some grammars
138
+ ]);
139
+ /**
140
+ * TreeSitterExtractor - Main extraction class
141
+ */
142
+ class TreeSitterExtractor {
143
+ filePath;
144
+ language;
145
+ source;
146
+ tree = null;
147
+ nodes = [];
148
+ edges = [];
149
+ unresolvedReferences = [];
150
+ errors = [];
151
+ extractor = null;
152
+ nodeStack = []; // Stack of parent node IDs
153
+ methodIndex = null; // lookup key → node ID for Pascal defProc lookup
154
+ constructor(filePath, source, language) {
155
+ this.filePath = filePath;
156
+ this.source = source;
157
+ this.language = language || (0, grammars_1.detectLanguage)(filePath, source);
158
+ this.extractor = languages_1.EXTRACTORS[this.language] || null;
159
+ }
160
+ /**
161
+ * Parse and extract from the source code
162
+ */
163
+ extract() {
164
+ const startTime = Date.now();
165
+ if (!(0, grammars_1.isLanguageSupported)(this.language)) {
166
+ return {
167
+ nodes: [],
168
+ edges: [],
169
+ unresolvedReferences: [],
170
+ errors: [
171
+ {
172
+ message: `Unsupported language: ${this.language}`,
173
+ filePath: this.filePath,
174
+ severity: 'error',
175
+ code: 'unsupported_language',
176
+ },
177
+ ],
178
+ durationMs: Date.now() - startTime,
179
+ };
180
+ }
181
+ const parser = (0, grammars_1.getParser)(this.language);
182
+ if (!parser) {
183
+ return {
184
+ nodes: [],
185
+ edges: [],
186
+ unresolvedReferences: [],
187
+ errors: [
188
+ {
189
+ message: `Failed to get parser for language: ${this.language}`,
190
+ filePath: this.filePath,
191
+ severity: 'error',
192
+ code: 'parser_error',
193
+ },
194
+ ],
195
+ durationMs: Date.now() - startTime,
196
+ };
197
+ }
198
+ try {
199
+ this.tree = parser.parse(this.source) ?? null;
200
+ if (!this.tree) {
201
+ throw new Error('Parser returned null tree');
202
+ }
203
+ // Create file node representing the source file
204
+ const fileNode = {
205
+ id: `file:${this.filePath}`,
206
+ kind: 'file',
207
+ name: path.basename(this.filePath),
208
+ qualifiedName: this.filePath,
209
+ filePath: this.filePath,
210
+ language: this.language,
211
+ startLine: 1,
212
+ endLine: this.source.split('\n').length,
213
+ startColumn: 0,
214
+ endColumn: 0,
215
+ isExported: false,
216
+ updatedAt: Date.now(),
217
+ };
218
+ this.nodes.push(fileNode);
219
+ // Push file node onto stack so top-level declarations get contains edges
220
+ this.nodeStack.push(fileNode.id);
221
+ this.visitNode(this.tree.rootNode);
222
+ this.nodeStack.pop();
223
+ }
224
+ catch (error) {
225
+ const msg = error instanceof Error ? error.message : String(error);
226
+ // WASM memory errors leave the module in a corrupted state — all subsequent
227
+ // parses would also fail. Re-throw so the worker can detect and crash,
228
+ // forcing a clean restart with a fresh heap.
229
+ if (msg.includes('memory access out of bounds') || msg.includes('out of memory')) {
230
+ throw error;
231
+ }
232
+ this.errors.push({
233
+ message: `Parse error: ${msg}`,
234
+ filePath: this.filePath,
235
+ severity: 'error',
236
+ code: 'parse_error',
237
+ });
238
+ }
239
+ finally {
240
+ // Free tree-sitter WASM memory immediately — trees hold native heap memory
241
+ // invisible to V8's GC that accumulates across thousands of files.
242
+ if (this.tree) {
243
+ this.tree.delete();
244
+ this.tree = null;
245
+ }
246
+ // Release source string to reduce GC pressure
247
+ this.source = '';
248
+ }
249
+ return {
250
+ nodes: this.nodes,
251
+ edges: this.edges,
252
+ unresolvedReferences: this.unresolvedReferences,
253
+ errors: this.errors,
254
+ durationMs: Date.now() - startTime,
255
+ };
256
+ }
257
+ /**
258
+ * Visit a node and extract information
259
+ */
260
+ visitNode(node) {
261
+ if (!this.extractor)
262
+ return;
263
+ const nodeType = node.type;
264
+ let skipChildren = false;
265
+ // Language-specific custom visitor hook
266
+ if (this.extractor.visitNode) {
267
+ const ctx = this.makeExtractorContext();
268
+ const handled = this.extractor.visitNode(node, ctx);
269
+ if (handled)
270
+ return;
271
+ }
272
+ // Pascal-specific AST handling
273
+ if (this.language === 'pascal') {
274
+ skipChildren = this.visitPascalNode(node);
275
+ if (skipChildren)
276
+ return;
277
+ }
278
+ // Check for function declarations
279
+ // For Python/Ruby, function_definition inside a class should be treated as method
280
+ if (this.extractor.functionTypes.includes(nodeType)) {
281
+ if (this.isInsideClassLikeNode() && this.extractor.methodTypes.includes(nodeType)) {
282
+ // Inside a class - treat as method
283
+ this.extractMethod(node);
284
+ skipChildren = true; // extractMethod visits children via visitFunctionBody
285
+ }
286
+ else {
287
+ this.extractFunction(node);
288
+ skipChildren = true; // extractFunction visits children via visitFunctionBody
289
+ }
290
+ }
291
+ // Check for class declarations
292
+ else if (this.extractor.classTypes.includes(nodeType)) {
293
+ // Some languages reuse class_declaration for structs/enums (e.g. Swift)
294
+ const classification = this.extractor.classifyClassNode?.(node) ?? 'class';
295
+ if (classification === 'struct') {
296
+ this.extractStruct(node);
297
+ }
298
+ else if (classification === 'enum') {
299
+ this.extractEnum(node);
300
+ }
301
+ else if (classification === 'interface') {
302
+ this.extractInterface(node);
303
+ }
304
+ else if (classification === 'trait') {
305
+ this.extractClass(node, 'trait');
306
+ }
307
+ else {
308
+ this.extractClass(node);
309
+ }
310
+ skipChildren = true; // extractClass visits body children
311
+ }
312
+ // Extra class node types (e.g. Dart mixin_declaration, extension_declaration)
313
+ else if (this.extractor.extraClassNodeTypes?.includes(nodeType)) {
314
+ this.extractClass(node);
315
+ skipChildren = true;
316
+ }
317
+ // Check for method declarations (only if not already handled by functionTypes)
318
+ else if (this.extractor.methodTypes.includes(nodeType)) {
319
+ this.extractMethod(node);
320
+ skipChildren = true; // extractMethod visits children via visitFunctionBody
321
+ }
322
+ // Check for interface/protocol/trait declarations
323
+ else if (this.extractor.interfaceTypes.includes(nodeType)) {
324
+ this.extractInterface(node);
325
+ skipChildren = true; // extractInterface visits body children
326
+ }
327
+ // Check for struct declarations
328
+ else if (this.extractor.structTypes.includes(nodeType)) {
329
+ this.extractStruct(node);
330
+ skipChildren = true; // extractStruct visits body children
331
+ }
332
+ // Check for enum declarations
333
+ else if (this.extractor.enumTypes.includes(nodeType)) {
334
+ this.extractEnum(node);
335
+ skipChildren = true; // extractEnum visits body children
336
+ }
337
+ // Check for type alias declarations (e.g. `type X = ...` in TypeScript)
338
+ // For Go, type_spec wraps struct/interface definitions — resolveTypeAliasKind
339
+ // detects these and extractTypeAlias creates the correct node kind.
340
+ else if (this.extractor.typeAliasTypes.includes(nodeType)) {
341
+ skipChildren = this.extractTypeAlias(node);
342
+ }
343
+ // Check for class properties (e.g. C# property_declaration)
344
+ else if (this.extractor.propertyTypes?.includes(nodeType) && this.isInsideClassLikeNode()) {
345
+ this.extractProperty(node);
346
+ skipChildren = true;
347
+ }
348
+ // Check for class fields (e.g. Java field_declaration, C# field_declaration)
349
+ else if (this.extractor.fieldTypes?.includes(nodeType) && this.isInsideClassLikeNode()) {
350
+ this.extractField(node);
351
+ skipChildren = true;
352
+ }
353
+ // Check for variable declarations (const, let, var, etc.)
354
+ // Only extract top-level variables (not inside functions/methods)
355
+ else if (this.extractor.variableTypes.includes(nodeType) && !this.isInsideClassLikeNode()) {
356
+ this.extractVariable(node);
357
+ skipChildren = true; // extractVariable handles children
358
+ }
359
+ // `export_statement` itself is not extracted — the walker descends
360
+ // into children, where the inner declaration (lexical_declaration,
361
+ // function_declaration, class_declaration, etc.) is dispatched to
362
+ // its own extractor. `isExported` walks the parent chain, so the
363
+ // exported flag is preserved automatically.
364
+ //
365
+ // Calling extractExportedVariables here AND descending caused every
366
+ // `export const X = ...` to produce two nodes for the same symbol —
367
+ // one kind:'variable' from extractExportedVariables and one
368
+ // kind:'constant' from extractVariable. The dedicated dispatch is
369
+ // the correct one (it picks kind from isConst, captures the
370
+ // initializer signature, and walks type annotations); the
371
+ // export-statement helper was redundant.
372
+ // Check for imports
373
+ else if (this.extractor.importTypes.includes(nodeType)) {
374
+ this.extractImport(node);
375
+ }
376
+ // Check for function calls
377
+ else if (this.extractor.callTypes.includes(nodeType)) {
378
+ this.extractCall(node);
379
+ }
380
+ // `new Foo(...)` / `Foo::new(...)` / object_creation_expression —
381
+ // produce an `instantiates` reference. Children still walked so
382
+ // nested calls inside the constructor args (`new Foo(bar())`) get
383
+ // their own `calls` refs.
384
+ else if (INSTANTIATION_KINDS.has(nodeType)) {
385
+ this.extractInstantiation(node);
386
+ }
387
+ // (Decorator handling lives inside the symbol-creating extractors
388
+ // — extractClass / extractFunction / extractProperty — because the
389
+ // decorator node sits BEFORE the symbol in the AST and the walker
390
+ // would otherwise see the wrong nodeStack head.)
391
+ // Rust: `impl Trait for Type { ... }` — creates implements edge from Type to Trait
392
+ else if (nodeType === 'impl_item') {
393
+ this.extractRustImplItem(node);
394
+ }
395
+ // Visit children (unless the extract method already visited them)
396
+ if (!skipChildren) {
397
+ for (let i = 0; i < node.namedChildCount; i++) {
398
+ const child = node.namedChild(i);
399
+ if (child) {
400
+ this.visitNode(child);
401
+ }
402
+ }
403
+ }
404
+ }
405
+ /**
406
+ * Create a Node object
407
+ */
408
+ createNode(kind, name, node, extra) {
409
+ // Skip nodes with empty/missing names — they are not meaningful symbols
410
+ // and would cause FK violations when edges reference them (see issue #42)
411
+ if (!name) {
412
+ return null;
413
+ }
414
+ const id = (0, tree_sitter_helpers_1.generateNodeId)(this.filePath, kind, name, node.startPosition.row + 1);
415
+ const newNode = {
416
+ id,
417
+ kind,
418
+ name,
419
+ qualifiedName: this.buildQualifiedName(name),
420
+ filePath: this.filePath,
421
+ language: this.language,
422
+ startLine: node.startPosition.row + 1,
423
+ endLine: node.endPosition.row + 1,
424
+ startColumn: node.startPosition.column,
425
+ endColumn: node.endPosition.column,
426
+ updatedAt: Date.now(),
427
+ ...extra,
428
+ };
429
+ this.nodes.push(newNode);
430
+ // Add containment edge from parent
431
+ if (this.nodeStack.length > 0) {
432
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
433
+ if (parentId) {
434
+ this.edges.push({
435
+ source: parentId,
436
+ target: id,
437
+ kind: 'contains',
438
+ });
439
+ }
440
+ }
441
+ return newNode;
442
+ }
443
+ /**
444
+ * Find first named child whose type is in the given list.
445
+ * Used to locate inner type nodes (e.g. enum_specifier inside a typedef).
446
+ */
447
+ findChildByTypes(node, types) {
448
+ for (let i = 0; i < node.namedChildCount; i++) {
449
+ const child = node.namedChild(i);
450
+ if (child && types.includes(child.type))
451
+ return child;
452
+ }
453
+ return null;
454
+ }
455
+ /**
456
+ * Build qualified name from node stack
457
+ */
458
+ buildQualifiedName(name) {
459
+ // Build a qualified name from the semantic hierarchy only (no file path).
460
+ // The file path is stored separately in filePath and pollutes FTS if included here.
461
+ const parts = [];
462
+ for (const nodeId of this.nodeStack) {
463
+ const node = this.nodes.find((n) => n.id === nodeId);
464
+ if (node && node.kind !== 'file') {
465
+ parts.push(node.name);
466
+ }
467
+ }
468
+ parts.push(name);
469
+ return parts.join('::');
470
+ }
471
+ /**
472
+ * Build an ExtractorContext for passing to language-specific visitNode hooks.
473
+ */
474
+ makeExtractorContext() {
475
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
476
+ const self = this;
477
+ return {
478
+ createNode: (kind, name, node, extra) => self.createNode(kind, name, node, extra),
479
+ visitNode: (node) => self.visitNode(node),
480
+ visitFunctionBody: (body, functionId) => self.visitFunctionBody(body, functionId),
481
+ addUnresolvedReference: (ref) => self.unresolvedReferences.push(ref),
482
+ pushScope: (nodeId) => self.nodeStack.push(nodeId),
483
+ popScope: () => self.nodeStack.pop(),
484
+ get filePath() { return self.filePath; },
485
+ get source() { return self.source; },
486
+ get nodeStack() { return self.nodeStack; },
487
+ get nodes() { return self.nodes; },
488
+ };
489
+ }
490
+ /**
491
+ * Check if the current node stack indicates we are inside a class-like node
492
+ * (class, struct, interface, trait). File nodes do not count as class-like.
493
+ */
494
+ isInsideClassLikeNode() {
495
+ if (this.nodeStack.length === 0)
496
+ return false;
497
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
498
+ if (!parentId)
499
+ return false;
500
+ const parentNode = this.nodes.find((n) => n.id === parentId);
501
+ if (!parentNode)
502
+ return false;
503
+ return (parentNode.kind === 'class' ||
504
+ parentNode.kind === 'struct' ||
505
+ parentNode.kind === 'interface' ||
506
+ parentNode.kind === 'trait' ||
507
+ parentNode.kind === 'enum' ||
508
+ parentNode.kind === 'module');
509
+ }
510
+ /**
511
+ * Extract a function
512
+ */
513
+ extractFunction(node) {
514
+ if (!this.extractor)
515
+ return;
516
+ // If the language provides getReceiverType and this function has a receiver
517
+ // (e.g., Rust function_item inside an impl block), extract as method instead
518
+ if (this.extractor.getReceiverType?.(node, this.source)) {
519
+ this.extractMethod(node);
520
+ return;
521
+ }
522
+ let name = extractName(node, this.source, this.extractor);
523
+ // For arrow functions and function expressions assigned to variables,
524
+ // resolve the name from the parent variable_declarator.
525
+ // e.g. `export const useAuth = () => { ... }` — the arrow_function node
526
+ // has no `name` field; the name lives on the variable_declarator.
527
+ if (name === '<anonymous>' &&
528
+ (node.type === 'arrow_function' || node.type === 'function_expression')) {
529
+ const parent = node.parent;
530
+ if (parent?.type === 'variable_declarator') {
531
+ const varName = (0, tree_sitter_helpers_1.getChildByField)(parent, 'name');
532
+ if (varName) {
533
+ name = (0, tree_sitter_helpers_1.getNodeText)(varName, this.source);
534
+ }
535
+ }
536
+ }
537
+ if (name === '<anonymous>')
538
+ return; // Skip anonymous functions
539
+ // Check for misparse artifacts (e.g. C++ macros causing "namespace detail" functions)
540
+ // Skip the node but still visit the body for calls and structural nodes
541
+ if (this.extractor.isMisparsedFunction?.(name, node)) {
542
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
543
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
544
+ if (body) {
545
+ this.visitFunctionBody(body, '');
546
+ }
547
+ return;
548
+ }
549
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
550
+ const signature = this.extractor.getSignature?.(node, this.source);
551
+ const visibility = this.extractor.getVisibility?.(node);
552
+ const isExported = this.extractor.isExported?.(node, this.source);
553
+ const isAsync = this.extractor.isAsync?.(node);
554
+ const isStatic = this.extractor.isStatic?.(node);
555
+ const funcNode = this.createNode('function', name, node, {
556
+ docstring,
557
+ signature,
558
+ visibility,
559
+ isExported,
560
+ isAsync,
561
+ isStatic,
562
+ });
563
+ if (!funcNode)
564
+ return;
565
+ // Extract type annotations (parameter types and return type)
566
+ this.extractTypeAnnotations(node, funcNode.id);
567
+ // Extract decorators applied to the function (rare in JS/TS but
568
+ // present in Python `@decorator def f():` and Java/Kotlin
569
+ // annotations on free functions).
570
+ this.extractDecoratorsFor(node, funcNode.id);
571
+ // Push to stack and visit body
572
+ this.nodeStack.push(funcNode.id);
573
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
574
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
575
+ if (body) {
576
+ this.visitFunctionBody(body, funcNode.id);
577
+ }
578
+ this.nodeStack.pop();
579
+ }
580
+ /**
581
+ * Extract a class
582
+ */
583
+ extractClass(node, kind = 'class') {
584
+ if (!this.extractor)
585
+ return;
586
+ const name = extractName(node, this.source, this.extractor);
587
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
588
+ const visibility = this.extractor.getVisibility?.(node);
589
+ const isExported = this.extractor.isExported?.(node, this.source);
590
+ const classNode = this.createNode(kind, name, node, {
591
+ docstring,
592
+ visibility,
593
+ isExported,
594
+ });
595
+ if (!classNode)
596
+ return;
597
+ // Extract extends/implements
598
+ this.extractInheritance(node, classNode.id);
599
+ // Extract decorators applied to the class (`@Foo class X {}`).
600
+ this.extractDecoratorsFor(node, classNode.id);
601
+ // Push to stack and visit body
602
+ this.nodeStack.push(classNode.id);
603
+ let body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
604
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
605
+ if (!body)
606
+ body = node;
607
+ // Visit all children for methods and properties
608
+ for (let i = 0; i < body.namedChildCount; i++) {
609
+ const child = body.namedChild(i);
610
+ if (child) {
611
+ this.visitNode(child);
612
+ }
613
+ }
614
+ this.nodeStack.pop();
615
+ }
616
+ /**
617
+ * Extract a method
618
+ */
619
+ extractMethod(node) {
620
+ if (!this.extractor)
621
+ return;
622
+ // For languages with receiver types (Go, Rust), include receiver in qualified name
623
+ // so FTS can match "scrapeLoop.run" → qualified_name "...::scrapeLoop::run"
624
+ const receiverType = this.extractor.getReceiverType?.(node, this.source);
625
+ // For most languages, only extract as method if inside a class-like node
626
+ // Languages with methodsAreTopLevel (e.g. Go) always treat them as methods
627
+ // Languages with getReceiverType (e.g. Rust) extract as method when receiver is found
628
+ if (!this.isInsideClassLikeNode() && !this.extractor.methodsAreTopLevel && !receiverType) {
629
+ // Skip method_definition nodes inside object literals (getters/setters/methods
630
+ // in inline objects). These are ephemeral and create noise (e.g., Svelte context
631
+ // objects: `ctx.set({ get view() { ... } })`).
632
+ if (node.parent?.type === 'object' || node.parent?.type === 'object_expression') {
633
+ return;
634
+ }
635
+ // Not inside a class-like node and no receiver type, treat as function
636
+ this.extractFunction(node);
637
+ return;
638
+ }
639
+ const name = extractName(node, this.source, this.extractor);
640
+ // Check for misparse artifacts (e.g. C++ "switch" inside macro-confused class body)
641
+ if (this.extractor.isMisparsedFunction?.(name, node)) {
642
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
643
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
644
+ if (body) {
645
+ this.visitFunctionBody(body, '');
646
+ }
647
+ return;
648
+ }
649
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
650
+ const signature = this.extractor.getSignature?.(node, this.source);
651
+ const visibility = this.extractor.getVisibility?.(node);
652
+ const isAsync = this.extractor.isAsync?.(node);
653
+ const isStatic = this.extractor.isStatic?.(node);
654
+ const extraProps = {
655
+ docstring,
656
+ signature,
657
+ visibility,
658
+ isAsync,
659
+ isStatic,
660
+ };
661
+ if (receiverType) {
662
+ extraProps.qualifiedName = `${receiverType}::${name}`;
663
+ }
664
+ const methodNode = this.createNode('method', name, node, extraProps);
665
+ if (!methodNode)
666
+ return;
667
+ // For methods with a receiver type but no class-like parent on the stack
668
+ // (e.g., Rust impl blocks), add a contains edge from the owning struct/trait
669
+ if (receiverType && !this.isInsideClassLikeNode()) {
670
+ const ownerNode = this.nodes.find((n) => n.name === receiverType &&
671
+ n.filePath === this.filePath &&
672
+ (n.kind === 'struct' || n.kind === 'class' || n.kind === 'enum' || n.kind === 'trait'));
673
+ if (ownerNode) {
674
+ this.edges.push({
675
+ source: ownerNode.id,
676
+ target: methodNode.id,
677
+ kind: 'contains',
678
+ });
679
+ }
680
+ }
681
+ // Extract type annotations (parameter types and return type)
682
+ this.extractTypeAnnotations(node, methodNode.id);
683
+ // Extract decorators (`@Get('/list') list() {}`).
684
+ this.extractDecoratorsFor(node, methodNode.id);
685
+ // Push to stack and visit body
686
+ this.nodeStack.push(methodNode.id);
687
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
688
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
689
+ if (body) {
690
+ this.visitFunctionBody(body, methodNode.id);
691
+ }
692
+ this.nodeStack.pop();
693
+ }
694
+ /**
695
+ * Extract an interface/protocol/trait
696
+ */
697
+ extractInterface(node) {
698
+ if (!this.extractor)
699
+ return;
700
+ const name = extractName(node, this.source, this.extractor);
701
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
702
+ const isExported = this.extractor.isExported?.(node, this.source);
703
+ const kind = this.extractor.interfaceKind ?? 'interface';
704
+ const interfaceNode = this.createNode(kind, name, node, {
705
+ docstring,
706
+ isExported,
707
+ });
708
+ if (!interfaceNode)
709
+ return;
710
+ // Extract extends (interface inheritance)
711
+ this.extractInheritance(node, interfaceNode.id);
712
+ // Visit body children for interface methods and nested types
713
+ this.nodeStack.push(interfaceNode.id);
714
+ let body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
715
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
716
+ if (!body)
717
+ body = node;
718
+ for (let i = 0; i < body.namedChildCount; i++) {
719
+ const child = body.namedChild(i);
720
+ if (child) {
721
+ this.visitNode(child);
722
+ }
723
+ }
724
+ this.nodeStack.pop();
725
+ }
726
+ /**
727
+ * Extract a struct
728
+ */
729
+ extractStruct(node) {
730
+ if (!this.extractor)
731
+ return;
732
+ // Skip forward declarations and type references (no body = not a definition)
733
+ const body = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
734
+ if (!body)
735
+ return;
736
+ const name = extractName(node, this.source, this.extractor);
737
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
738
+ const visibility = this.extractor.getVisibility?.(node);
739
+ const isExported = this.extractor.isExported?.(node, this.source);
740
+ const structNode = this.createNode('struct', name, node, {
741
+ docstring,
742
+ visibility,
743
+ isExported,
744
+ });
745
+ if (!structNode)
746
+ return;
747
+ // Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable)
748
+ this.extractInheritance(node, structNode.id);
749
+ // Push to stack for field extraction
750
+ this.nodeStack.push(structNode.id);
751
+ for (let i = 0; i < body.namedChildCount; i++) {
752
+ const child = body.namedChild(i);
753
+ if (child) {
754
+ this.visitNode(child);
755
+ }
756
+ }
757
+ this.nodeStack.pop();
758
+ }
759
+ /**
760
+ * Extract an enum
761
+ */
762
+ extractEnum(node) {
763
+ if (!this.extractor)
764
+ return;
765
+ // Skip forward declarations and type references (no body = not a definition)
766
+ const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
767
+ ?? (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.bodyField);
768
+ if (!body)
769
+ return;
770
+ const name = extractName(node, this.source, this.extractor);
771
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
772
+ const visibility = this.extractor.getVisibility?.(node);
773
+ const isExported = this.extractor.isExported?.(node, this.source);
774
+ const enumNode = this.createNode('enum', name, node, {
775
+ docstring,
776
+ visibility,
777
+ isExported,
778
+ });
779
+ if (!enumNode)
780
+ return;
781
+ // Extract inheritance (e.g. Swift: enum AFError: Error)
782
+ this.extractInheritance(node, enumNode.id);
783
+ // Push to stack and visit body children (enum members, nested types, methods)
784
+ this.nodeStack.push(enumNode.id);
785
+ const memberTypes = this.extractor.enumMemberTypes;
786
+ for (let i = 0; i < body.namedChildCount; i++) {
787
+ const child = body.namedChild(i);
788
+ if (!child)
789
+ continue;
790
+ if (memberTypes?.includes(child.type)) {
791
+ this.extractEnumMembers(child);
792
+ }
793
+ else {
794
+ this.visitNode(child);
795
+ }
796
+ }
797
+ this.nodeStack.pop();
798
+ }
799
+ /**
800
+ * Extract enum member names from an enum member node.
801
+ * Handles multi-case declarations (Swift: `case put, delete`) and single-case patterns.
802
+ */
803
+ extractEnumMembers(node) {
804
+ // Try field-based name first (e.g. Rust enum_variant has a 'name' field)
805
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
806
+ if (nameNode) {
807
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source), node);
808
+ return;
809
+ }
810
+ // Check for identifier-like children (Swift: simple_identifier, TS: property_identifier)
811
+ let found = false;
812
+ for (let i = 0; i < node.namedChildCount; i++) {
813
+ const child = node.namedChild(i);
814
+ if (child && (child.type === 'simple_identifier' || child.type === 'identifier' || child.type === 'property_identifier')) {
815
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(child, this.source), child);
816
+ found = true;
817
+ }
818
+ }
819
+ // If the node itself IS the identifier (e.g. TS property_identifier directly in enum body)
820
+ if (!found && node.namedChildCount === 0) {
821
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(node, this.source), node);
822
+ }
823
+ }
824
+ /**
825
+ * Extract a class property declaration (e.g. C# `public string Name { get; set; }`).
826
+ * Extracts as 'property' kind node inside the owning class.
827
+ */
828
+ extractProperty(node) {
829
+ if (!this.extractor)
830
+ return;
831
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
832
+ const visibility = this.extractor.getVisibility?.(node);
833
+ const isStatic = this.extractor.isStatic?.(node) ?? false;
834
+ // Property name is a direct identifier child
835
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name')
836
+ || node.namedChildren.find(c => c.type === 'identifier');
837
+ if (!nameNode)
838
+ return;
839
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
840
+ // Get property type from the type child (first named child that isn't modifier or identifier)
841
+ const typeNode = node.namedChildren.find(c => c.type !== 'modifier' && c.type !== 'modifiers'
842
+ && c.type !== 'identifier' && c.type !== 'accessor_list'
843
+ && c.type !== 'accessors' && c.type !== 'equals_value_clause');
844
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
845
+ const signature = typeText ? `${typeText} ${name}` : name;
846
+ const propNode = this.createNode('property', name, node, {
847
+ docstring,
848
+ signature,
849
+ visibility,
850
+ isStatic,
851
+ });
852
+ // `@Inject() private svc: Foo` and similar — capture the
853
+ // decorator->target relationship for class properties too.
854
+ if (propNode) {
855
+ this.extractDecoratorsFor(node, propNode.id);
856
+ }
857
+ }
858
+ /**
859
+ * Extract a class field declaration (e.g. Java field_declaration, C# field_declaration).
860
+ * Extracts each declarator as a 'field' kind node inside the owning class.
861
+ */
862
+ extractField(node) {
863
+ if (!this.extractor)
864
+ return;
865
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
866
+ const visibility = this.extractor.getVisibility?.(node);
867
+ const isStatic = this.extractor.isStatic?.(node) ?? false;
868
+ // Java field_declaration: "private final String name = value;" → variable_declarator(s) are direct children
869
+ // C# field_declaration: wraps in variable_declaration → variable_declarator(s)
870
+ let declarators = node.namedChildren.filter(c => c.type === 'variable_declarator');
871
+ // C#: look inside variable_declaration wrapper
872
+ if (declarators.length === 0) {
873
+ const varDecl = node.namedChildren.find(c => c.type === 'variable_declaration');
874
+ if (varDecl) {
875
+ declarators = varDecl.namedChildren.filter(c => c.type === 'variable_declarator');
876
+ }
877
+ }
878
+ // PHP property_declaration: property_element → variable_name → name
879
+ if (declarators.length === 0) {
880
+ const propElements = node.namedChildren.filter(c => c.type === 'property_element');
881
+ if (propElements.length > 0) {
882
+ // Get type annotation if present (e.g. "string", "int", "?Foo")
883
+ const typeNode = node.namedChildren.find(c => c.type !== 'visibility_modifier' && c.type !== 'static_modifier'
884
+ && c.type !== 'readonly_modifier' && c.type !== 'property_element'
885
+ && c.type !== 'var_modifier');
886
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
887
+ for (const elem of propElements) {
888
+ const varName = elem.namedChildren.find(c => c.type === 'variable_name');
889
+ const nameNode = varName?.namedChildren.find(c => c.type === 'name');
890
+ if (!nameNode)
891
+ continue;
892
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
893
+ const signature = typeText ? `${typeText} $${name}` : `$${name}`;
894
+ this.createNode('field', name, elem, {
895
+ docstring,
896
+ signature,
897
+ visibility,
898
+ isStatic,
899
+ });
900
+ }
901
+ return;
902
+ }
903
+ }
904
+ if (declarators.length > 0) {
905
+ // Get field type from the type child
906
+ // Java: type is a direct child of field_declaration
907
+ // C#: type is inside variable_declaration wrapper
908
+ const varDecl = node.namedChildren.find(c => c.type === 'variable_declaration');
909
+ const typeSearchNode = varDecl ?? node;
910
+ const typeNode = typeSearchNode.namedChildren.find(c => c.type !== 'modifiers' && c.type !== 'modifier' && c.type !== 'variable_declarator'
911
+ && c.type !== 'variable_declaration' && c.type !== 'marker_annotation' && c.type !== 'annotation');
912
+ const typeText = typeNode ? (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source) : undefined;
913
+ for (const decl of declarators) {
914
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(decl, 'name')
915
+ || decl.namedChildren.find(c => c.type === 'identifier');
916
+ if (!nameNode)
917
+ continue;
918
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
919
+ const signature = typeText ? `${typeText} ${name}` : name;
920
+ const fieldNode = this.createNode('field', name, decl, {
921
+ docstring,
922
+ signature,
923
+ visibility,
924
+ isStatic,
925
+ });
926
+ // Java/Kotlin annotations / TS field decorators sit on the
927
+ // outer field_declaration, not on the individual declarator.
928
+ if (fieldNode)
929
+ this.extractDecoratorsFor(node, fieldNode.id);
930
+ }
931
+ }
932
+ else {
933
+ // Fallback: try to find an identifier child directly
934
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name')
935
+ || node.namedChildren.find(c => c.type === 'identifier');
936
+ if (nameNode) {
937
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
938
+ this.createNode('field', name, node, {
939
+ docstring,
940
+ visibility,
941
+ isStatic,
942
+ });
943
+ }
944
+ }
945
+ }
946
+ /**
947
+ * Extract a variable declaration (const, let, var, etc.)
948
+ *
949
+ * Extracts top-level and module-level variable declarations.
950
+ * Captures the variable name and first 100 chars of initializer in signature for searchability.
951
+ */
952
+ extractVariable(node) {
953
+ if (!this.extractor)
954
+ return;
955
+ // Different languages have different variable declaration structures
956
+ // TypeScript/JavaScript: lexical_declaration contains variable_declarator children
957
+ // Python: assignment has left (identifier) and right (value)
958
+ // Go: var_declaration, short_var_declaration, const_declaration
959
+ const isConst = this.extractor.isConst?.(node) ?? false;
960
+ const kind = isConst ? 'constant' : 'variable';
961
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
962
+ const isExported = this.extractor.isExported?.(node, this.source) ?? false;
963
+ // Extract variable declarators based on language
964
+ if (this.language === 'typescript' || this.language === 'javascript' ||
965
+ this.language === 'tsx' || this.language === 'jsx') {
966
+ // Handle lexical_declaration and variable_declaration
967
+ // These contain one or more variable_declarator children
968
+ for (let i = 0; i < node.namedChildCount; i++) {
969
+ const child = node.namedChild(i);
970
+ if (child?.type === 'variable_declarator') {
971
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
972
+ const valueNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'value');
973
+ if (nameNode) {
974
+ // Skip destructured patterns (e.g., `let { x, y } = $props()` in Svelte)
975
+ // These produce ugly multi-line names like "{ class: className }"
976
+ if (nameNode.type === 'object_pattern' || nameNode.type === 'array_pattern') {
977
+ continue;
978
+ }
979
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
980
+ // Arrow functions / function expressions: extract as function instead of variable
981
+ if (valueNode && (valueNode.type === 'arrow_function' || valueNode.type === 'function_expression')) {
982
+ this.extractFunction(valueNode);
983
+ continue;
984
+ }
985
+ // Capture first 100 chars of initializer for context (stored in signature for searchability)
986
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
987
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
988
+ const varNode = this.createNode(kind, name, child, {
989
+ docstring,
990
+ signature: initSignature,
991
+ isExported,
992
+ });
993
+ // Extract type annotation references (e.g., const x: ITextModel = ...)
994
+ if (varNode) {
995
+ this.extractVariableTypeAnnotation(child, varNode.id);
996
+ }
997
+ }
998
+ }
999
+ }
1000
+ }
1001
+ else if (this.language === 'python' || this.language === 'ruby') {
1002
+ // Python/Ruby assignment: left = right
1003
+ const left = (0, tree_sitter_helpers_1.getChildByField)(node, 'left') || node.namedChild(0);
1004
+ const right = (0, tree_sitter_helpers_1.getChildByField)(node, 'right') || node.namedChild(1);
1005
+ if (left && left.type === 'identifier') {
1006
+ const name = (0, tree_sitter_helpers_1.getNodeText)(left, this.source);
1007
+ // Skip if name starts with lowercase and looks like a function call result
1008
+ // Python constants are usually UPPER_CASE
1009
+ const initValue = right ? (0, tree_sitter_helpers_1.getNodeText)(right, this.source).slice(0, 100) : undefined;
1010
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1011
+ this.createNode(kind, name, node, {
1012
+ docstring,
1013
+ signature: initSignature,
1014
+ });
1015
+ }
1016
+ }
1017
+ else if (this.language === 'go') {
1018
+ // Go: var_declaration, short_var_declaration, const_declaration
1019
+ // These can have multiple identifiers on the left
1020
+ const specs = node.namedChildren.filter(c => c.type === 'var_spec' || c.type === 'const_spec');
1021
+ for (const spec of specs) {
1022
+ const nameNode = spec.namedChild(0);
1023
+ if (nameNode && nameNode.type === 'identifier') {
1024
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1025
+ const valueNode = spec.namedChildCount > 1 ? spec.namedChild(spec.namedChildCount - 1) : null;
1026
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
1027
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1028
+ this.createNode(node.type === 'const_declaration' ? 'constant' : 'variable', name, spec, {
1029
+ docstring,
1030
+ signature: initSignature,
1031
+ });
1032
+ }
1033
+ }
1034
+ // Handle short_var_declaration (:=)
1035
+ if (node.type === 'short_var_declaration') {
1036
+ const left = (0, tree_sitter_helpers_1.getChildByField)(node, 'left');
1037
+ const right = (0, tree_sitter_helpers_1.getChildByField)(node, 'right');
1038
+ if (left) {
1039
+ // Can be expression_list with multiple identifiers
1040
+ const identifiers = left.type === 'expression_list'
1041
+ ? left.namedChildren.filter(c => c.type === 'identifier')
1042
+ : [left];
1043
+ for (const id of identifiers) {
1044
+ const name = (0, tree_sitter_helpers_1.getNodeText)(id, this.source);
1045
+ const initValue = right ? (0, tree_sitter_helpers_1.getNodeText)(right, this.source).slice(0, 100) : undefined;
1046
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1047
+ this.createNode('variable', name, node, {
1048
+ docstring,
1049
+ signature: initSignature,
1050
+ });
1051
+ }
1052
+ }
1053
+ }
1054
+ }
1055
+ else if (this.language === 'lua' || this.language === 'luau') {
1056
+ // Lua/Luau: variable_declaration → assignment_statement → variable_list
1057
+ // (name: identifier...) = expression_list. `local x, y = 1, 2`
1058
+ // declares multiple names; only plain identifiers are locals.
1059
+ const assign = node.namedChildren.find((c) => c.type === 'assignment_statement') ?? node;
1060
+ const varList = assign.namedChildren.find((c) => c.type === 'variable_list');
1061
+ const exprList = assign.namedChildren.find((c) => c.type === 'expression_list');
1062
+ const values = exprList ? exprList.namedChildren : [];
1063
+ const names = varList ? varList.namedChildren.filter((c) => c.type === 'identifier') : [];
1064
+ names.forEach((nameNode, i) => {
1065
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
1066
+ if (!name)
1067
+ return;
1068
+ const valueNode = values[i];
1069
+ const initValue = valueNode ? (0, tree_sitter_helpers_1.getNodeText)(valueNode, this.source).slice(0, 100) : undefined;
1070
+ const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
1071
+ this.createNode(kind, name, nameNode, { docstring, signature: initSignature, isExported });
1072
+ });
1073
+ }
1074
+ else {
1075
+ // Generic fallback for other languages
1076
+ // Try to find identifier children
1077
+ for (let i = 0; i < node.namedChildCount; i++) {
1078
+ const child = node.namedChild(i);
1079
+ if (child?.type === 'identifier' || child?.type === 'variable_declarator') {
1080
+ const name = child.type === 'identifier'
1081
+ ? (0, tree_sitter_helpers_1.getNodeText)(child, this.source)
1082
+ : extractName(child, this.source, this.extractor);
1083
+ if (name && name !== '<anonymous>') {
1084
+ this.createNode(kind, name, child, {
1085
+ docstring,
1086
+ isExported,
1087
+ });
1088
+ }
1089
+ }
1090
+ }
1091
+ }
1092
+ }
1093
+ /**
1094
+ * Extract a type alias (e.g. `export type X = ...` in TypeScript).
1095
+ * For languages like Go, resolveTypeAliasKind detects when the type_spec
1096
+ * wraps a struct or interface definition and creates the correct node kind.
1097
+ * Returns true if children should be skipped (struct/interface handled body visiting).
1098
+ */
1099
+ extractTypeAlias(node) {
1100
+ if (!this.extractor)
1101
+ return false;
1102
+ const name = extractName(node, this.source, this.extractor);
1103
+ if (name === '<anonymous>')
1104
+ return false;
1105
+ const docstring = (0, tree_sitter_helpers_1.getPrecedingDocstring)(node, this.source);
1106
+ const isExported = this.extractor.isExported?.(node, this.source);
1107
+ // Check if this type alias is actually a struct or interface definition
1108
+ // (e.g. Go: `type Foo struct { ... }` is a type_spec wrapping struct_type)
1109
+ const resolvedKind = this.extractor.resolveTypeAliasKind?.(node, this.source);
1110
+ if (resolvedKind === 'struct') {
1111
+ const structNode = this.createNode('struct', name, node, { docstring, isExported });
1112
+ if (!structNode)
1113
+ return true;
1114
+ // Visit body children for field extraction
1115
+ this.nodeStack.push(structNode.id);
1116
+ // Try Go-style 'type' field first, then find inner struct child (C typedef struct)
1117
+ const typeChild = (0, tree_sitter_helpers_1.getChildByField)(node, 'type')
1118
+ || this.findChildByTypes(node, this.extractor.structTypes);
1119
+ if (typeChild) {
1120
+ // Extract struct embedding (e.g. Go: `type DB struct { *Head; Queryable }`)
1121
+ this.extractInheritance(typeChild, structNode.id);
1122
+ const body = (0, tree_sitter_helpers_1.getChildByField)(typeChild, this.extractor.bodyField) || typeChild;
1123
+ for (let i = 0; i < body.namedChildCount; i++) {
1124
+ const child = body.namedChild(i);
1125
+ if (child)
1126
+ this.visitNode(child);
1127
+ }
1128
+ }
1129
+ this.nodeStack.pop();
1130
+ return true;
1131
+ }
1132
+ if (resolvedKind === 'enum') {
1133
+ const enumNode = this.createNode('enum', name, node, { docstring, isExported });
1134
+ if (!enumNode)
1135
+ return true;
1136
+ this.nodeStack.push(enumNode.id);
1137
+ // Find the inner enum type child (e.g. C: typedef enum { ... } name)
1138
+ const innerEnum = this.findChildByTypes(node, this.extractor.enumTypes);
1139
+ if (innerEnum) {
1140
+ this.extractInheritance(innerEnum, enumNode.id);
1141
+ const body = this.extractor.resolveBody?.(innerEnum, this.extractor.bodyField)
1142
+ ?? (0, tree_sitter_helpers_1.getChildByField)(innerEnum, this.extractor.bodyField);
1143
+ if (body) {
1144
+ const memberTypes = this.extractor.enumMemberTypes;
1145
+ for (let i = 0; i < body.namedChildCount; i++) {
1146
+ const child = body.namedChild(i);
1147
+ if (!child)
1148
+ continue;
1149
+ if (memberTypes?.includes(child.type)) {
1150
+ this.extractEnumMembers(child);
1151
+ }
1152
+ else {
1153
+ this.visitNode(child);
1154
+ }
1155
+ }
1156
+ }
1157
+ }
1158
+ this.nodeStack.pop();
1159
+ return true;
1160
+ }
1161
+ if (resolvedKind === 'interface') {
1162
+ const kind = this.extractor.interfaceKind ?? 'interface';
1163
+ const interfaceNode = this.createNode(kind, name, node, { docstring, isExported });
1164
+ if (!interfaceNode)
1165
+ return true;
1166
+ // Extract interface inheritance from the inner type node
1167
+ const typeChild = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
1168
+ if (typeChild)
1169
+ this.extractInheritance(typeChild, interfaceNode.id);
1170
+ return true;
1171
+ }
1172
+ const typeAliasNode = this.createNode('type_alias', name, node, {
1173
+ docstring,
1174
+ isExported,
1175
+ });
1176
+ // Extract type references from the alias value (e.g., `type X = ITextModel | null`)
1177
+ if (typeAliasNode && this.TYPE_ANNOTATION_LANGUAGES.has(this.language)) {
1178
+ // The value is everything after the `=`, which is typically the last named child
1179
+ // In tree-sitter TS: type_alias_declaration has name + value children
1180
+ const value = (0, tree_sitter_helpers_1.getChildByField)(node, 'value');
1181
+ if (value) {
1182
+ this.extractTypeRefsFromSubtree(value, typeAliasNode.id);
1183
+ }
1184
+ }
1185
+ return false;
1186
+ }
1187
+ // extractExportedVariables removed — the walker now descends into
1188
+ // export_statement children and the inner declaration's dedicated
1189
+ // extractor (extractVariable, extractFunction, extractClass, etc.)
1190
+ // handles the symbol with isExported=true via parent-walk in the
1191
+ // language extractor's isExported predicate.
1192
+ /**
1193
+ * Extract an import
1194
+ *
1195
+ * Creates an import node with the full import statement stored in signature for searchability.
1196
+ * Also creates unresolved references for resolution purposes.
1197
+ */
1198
+ extractImport(node) {
1199
+ if (!this.extractor)
1200
+ return;
1201
+ const importText = (0, tree_sitter_helpers_1.getNodeText)(node, this.source).trim();
1202
+ // Try language-specific hook first
1203
+ if (this.extractor.extractImport) {
1204
+ const info = this.extractor.extractImport(node, this.source);
1205
+ if (info) {
1206
+ this.createNode('import', info.moduleName, node, {
1207
+ signature: info.signature,
1208
+ });
1209
+ // Create unresolved reference unless the hook handled it
1210
+ if (!info.handledRefs && info.moduleName && this.nodeStack.length > 0) {
1211
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
1212
+ if (parentId) {
1213
+ this.unresolvedReferences.push({
1214
+ fromNodeId: parentId,
1215
+ referenceName: info.moduleName,
1216
+ referenceKind: 'imports',
1217
+ line: node.startPosition.row + 1,
1218
+ column: node.startPosition.column,
1219
+ });
1220
+ }
1221
+ }
1222
+ return;
1223
+ }
1224
+ // Hook returned null — fall through to multi-import inline handlers only
1225
+ // (hook returning null means "I didn't handle this" for multi-import cases,
1226
+ // NOT "use generic fallback" — the hook already declined)
1227
+ }
1228
+ // Multi-import cases that create multiple nodes (can't be expressed with single-return hook)
1229
+ // Python import_statement: import os, sys (creates one import per module)
1230
+ if (this.language === 'python' && node.type === 'import_statement') {
1231
+ for (let i = 0; i < node.namedChildCount; i++) {
1232
+ const child = node.namedChild(i);
1233
+ if (child?.type === 'dotted_name') {
1234
+ this.createNode('import', (0, tree_sitter_helpers_1.getNodeText)(child, this.source), node, {
1235
+ signature: importText,
1236
+ });
1237
+ }
1238
+ else if (child?.type === 'aliased_import') {
1239
+ const dottedName = child.namedChildren.find(c => c.type === 'dotted_name');
1240
+ if (dottedName) {
1241
+ this.createNode('import', (0, tree_sitter_helpers_1.getNodeText)(dottedName, this.source), node, {
1242
+ signature: importText,
1243
+ });
1244
+ }
1245
+ }
1246
+ }
1247
+ return;
1248
+ }
1249
+ // Go imports: single or grouped (creates one import per spec)
1250
+ if (this.language === 'go') {
1251
+ const parentId = this.nodeStack.length > 0 ? this.nodeStack[this.nodeStack.length - 1] : null;
1252
+ const extractFromSpec = (spec) => {
1253
+ const stringLiteral = spec.namedChildren.find(c => c.type === 'interpreted_string_literal');
1254
+ if (stringLiteral) {
1255
+ const importPath = (0, tree_sitter_helpers_1.getNodeText)(stringLiteral, this.source).replace(/['"]/g, '');
1256
+ if (importPath) {
1257
+ this.createNode('import', importPath, spec, {
1258
+ signature: (0, tree_sitter_helpers_1.getNodeText)(spec, this.source).trim(),
1259
+ });
1260
+ // Create unresolved reference so the resolver can create imports edges
1261
+ if (parentId) {
1262
+ this.unresolvedReferences.push({
1263
+ fromNodeId: parentId,
1264
+ referenceName: importPath,
1265
+ referenceKind: 'imports',
1266
+ line: spec.startPosition.row + 1,
1267
+ column: spec.startPosition.column,
1268
+ });
1269
+ }
1270
+ }
1271
+ }
1272
+ };
1273
+ const importSpecList = node.namedChildren.find(c => c.type === 'import_spec_list');
1274
+ if (importSpecList) {
1275
+ for (const spec of importSpecList.namedChildren.filter(c => c.type === 'import_spec')) {
1276
+ extractFromSpec(spec);
1277
+ }
1278
+ }
1279
+ else {
1280
+ const importSpec = node.namedChildren.find(c => c.type === 'import_spec');
1281
+ if (importSpec) {
1282
+ extractFromSpec(importSpec);
1283
+ }
1284
+ }
1285
+ return;
1286
+ }
1287
+ // PHP grouped imports: use X\{A, B} (creates one import per item)
1288
+ if (this.language === 'php') {
1289
+ const namespacePrefix = node.namedChildren.find(c => c.type === 'namespace_name');
1290
+ const useGroup = node.namedChildren.find(c => c.type === 'namespace_use_group');
1291
+ if (namespacePrefix && useGroup) {
1292
+ const prefix = (0, tree_sitter_helpers_1.getNodeText)(namespacePrefix, this.source);
1293
+ const useClauses = useGroup.namedChildren.filter((c) => c.type === 'namespace_use_group_clause' || c.type === 'namespace_use_clause');
1294
+ for (const clause of useClauses) {
1295
+ const nsName = clause.namedChildren.find((c) => c.type === 'namespace_name');
1296
+ const name = nsName
1297
+ ? nsName.namedChildren.find((c) => c.type === 'name')
1298
+ : clause.namedChildren.find((c) => c.type === 'name');
1299
+ if (name) {
1300
+ const fullPath = `${prefix}\\${(0, tree_sitter_helpers_1.getNodeText)(name, this.source)}`;
1301
+ this.createNode('import', fullPath, node, {
1302
+ signature: importText,
1303
+ });
1304
+ }
1305
+ }
1306
+ return;
1307
+ }
1308
+ }
1309
+ // If a hook exists but returned null, it intentionally declined this node — don't create fallback
1310
+ if (this.extractor.extractImport)
1311
+ return;
1312
+ // Generic fallback for languages without hooks
1313
+ this.createNode('import', importText, node, {
1314
+ signature: importText,
1315
+ });
1316
+ }
1317
+ /**
1318
+ * Extract a function call
1319
+ */
1320
+ extractCall(node) {
1321
+ if (this.nodeStack.length === 0)
1322
+ return;
1323
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
1324
+ if (!callerId)
1325
+ return;
1326
+ // Get the function/method being called
1327
+ let calleeName = '';
1328
+ // Java/Kotlin method_invocation has 'object' + 'name' fields instead of 'function'
1329
+ // PHP member_call_expression has 'object' + 'name', scoped_call_expression has 'scope' + 'name'
1330
+ const nameField = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
1331
+ const objectField = (0, tree_sitter_helpers_1.getChildByField)(node, 'object') || (0, tree_sitter_helpers_1.getChildByField)(node, 'scope');
1332
+ if (nameField && objectField && (node.type === 'method_invocation' || node.type === 'member_call_expression' || node.type === 'scoped_call_expression')) {
1333
+ // Method call with explicit receiver: receiver.method() / $receiver->method() / ClassName::method()
1334
+ const methodName = (0, tree_sitter_helpers_1.getNodeText)(nameField, this.source);
1335
+ let receiverName = (0, tree_sitter_helpers_1.getNodeText)(objectField, this.source);
1336
+ // Strip PHP $ prefix from variable names
1337
+ receiverName = receiverName.replace(/^\$/, '');
1338
+ if (methodName) {
1339
+ // Skip self/this/parent/static receivers — they don't aid resolution
1340
+ const SKIP_RECEIVERS = new Set(['self', 'this', 'cls', 'super', 'parent', 'static']);
1341
+ if (SKIP_RECEIVERS.has(receiverName)) {
1342
+ calleeName = methodName;
1343
+ }
1344
+ else {
1345
+ calleeName = `${receiverName}.${methodName}`;
1346
+ }
1347
+ }
1348
+ }
1349
+ else {
1350
+ const func = (0, tree_sitter_helpers_1.getChildByField)(node, 'function') || node.namedChild(0);
1351
+ if (func) {
1352
+ if (func.type === 'member_expression' || func.type === 'attribute' || func.type === 'selector_expression' || func.type === 'navigation_expression') {
1353
+ // Method call: obj.method() or obj.field.method()
1354
+ // Go uses selector_expression with 'field', JS/TS uses member_expression with 'property'
1355
+ // Kotlin uses navigation_expression with navigation_suffix > simple_identifier
1356
+ let property = (0, tree_sitter_helpers_1.getChildByField)(func, 'property') || (0, tree_sitter_helpers_1.getChildByField)(func, 'field');
1357
+ if (!property) {
1358
+ const child1 = func.namedChild(1);
1359
+ // Kotlin: navigation_suffix wraps the method name — extract simple_identifier from it
1360
+ if (child1?.type === 'navigation_suffix') {
1361
+ property = child1.namedChildren.find((c) => c.type === 'simple_identifier') ?? child1;
1362
+ }
1363
+ else {
1364
+ property = child1;
1365
+ }
1366
+ }
1367
+ if (property) {
1368
+ const methodName = (0, tree_sitter_helpers_1.getNodeText)(property, this.source);
1369
+ // Include receiver name for qualified resolution (e.g., console.print → "console.print")
1370
+ // This helps the resolver distinguish method calls from bare function calls
1371
+ // (e.g., Python's console.print() vs builtin print())
1372
+ // Skip self/this/cls as they don't aid resolution
1373
+ const receiver = (0, tree_sitter_helpers_1.getChildByField)(func, 'object') || (0, tree_sitter_helpers_1.getChildByField)(func, 'operand') || func.namedChild(0);
1374
+ const SKIP_RECEIVERS = new Set(['self', 'this', 'cls', 'super']);
1375
+ if (receiver && (receiver.type === 'identifier' || receiver.type === 'simple_identifier')) {
1376
+ const receiverName = (0, tree_sitter_helpers_1.getNodeText)(receiver, this.source);
1377
+ if (!SKIP_RECEIVERS.has(receiverName)) {
1378
+ calleeName = `${receiverName}.${methodName}`;
1379
+ }
1380
+ else {
1381
+ calleeName = methodName;
1382
+ }
1383
+ }
1384
+ else {
1385
+ calleeName = methodName;
1386
+ }
1387
+ }
1388
+ }
1389
+ else if (func.type === 'scoped_identifier' || func.type === 'scoped_call_expression') {
1390
+ // Scoped call: Module::function()
1391
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(func, this.source);
1392
+ }
1393
+ else {
1394
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(func, this.source);
1395
+ }
1396
+ }
1397
+ }
1398
+ if (calleeName) {
1399
+ this.unresolvedReferences.push({
1400
+ fromNodeId: callerId,
1401
+ referenceName: calleeName,
1402
+ referenceKind: 'calls',
1403
+ line: node.startPosition.row + 1,
1404
+ column: node.startPosition.column,
1405
+ });
1406
+ }
1407
+ }
1408
+ /**
1409
+ * `new Foo(...)` / `Foo::new(...)` / object_creation_expression —
1410
+ * emit an `instantiates` reference to the class name. The resolver
1411
+ * then links it to the class node, producing the `instantiates`
1412
+ * edge that powers "what creates instances of X" queries.
1413
+ *
1414
+ * Children are still walked so nested calls inside the constructor
1415
+ * arguments (`new Foo(bar())`) get their own `calls` references.
1416
+ */
1417
+ extractInstantiation(node) {
1418
+ if (this.nodeStack.length === 0)
1419
+ return;
1420
+ const fromId = this.nodeStack[this.nodeStack.length - 1];
1421
+ if (!fromId)
1422
+ return;
1423
+ // The class name is in the `constructor`/`type`/first-named-child
1424
+ // depending on grammar.
1425
+ const ctor = (0, tree_sitter_helpers_1.getChildByField)(node, 'constructor') ||
1426
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'type') ||
1427
+ (0, tree_sitter_helpers_1.getChildByField)(node, 'name') ||
1428
+ node.namedChild(0);
1429
+ if (!ctor)
1430
+ return;
1431
+ let className = (0, tree_sitter_helpers_1.getNodeText)(ctor, this.source);
1432
+ // Strip type-argument suffix first: `new Map<K, V>()` would
1433
+ // otherwise produce className 'Map<K, V>' (the constructor
1434
+ // field is a `generic_type` node) and resolution would fail
1435
+ // because no class is named with the angle-bracket suffix.
1436
+ const ltIdx = className.indexOf('<');
1437
+ if (ltIdx > 0)
1438
+ className = className.slice(0, ltIdx);
1439
+ // For namespaced/qualified constructors (`new ns.Foo()`,
1440
+ // `new ns::Foo()`) keep the trailing identifier — that's what
1441
+ // matches a class node in the index.
1442
+ const lastDot = Math.max(className.lastIndexOf('.'), className.lastIndexOf('::'));
1443
+ if (lastDot >= 0)
1444
+ className = className.slice(lastDot + 1).replace(/^[:.]/, '');
1445
+ className = className.trim();
1446
+ if (className) {
1447
+ this.unresolvedReferences.push({
1448
+ fromNodeId: fromId,
1449
+ referenceName: className,
1450
+ referenceKind: 'instantiates',
1451
+ line: node.startPosition.row + 1,
1452
+ column: node.startPosition.column,
1453
+ });
1454
+ }
1455
+ }
1456
+ /**
1457
+ * Scan `declNode` and its preceding siblings (within the parent's
1458
+ * named children) for decorator nodes, emitting a `decorates`
1459
+ * reference from `decoratedId` to each decorator's function name.
1460
+ *
1461
+ * Why preceding siblings: in TypeScript, `@Foo class Bar {}` parses
1462
+ * as an `export_statement` (or top-level wrapper) with the
1463
+ * `decorator` as a child *before* the `class_declaration` — so the
1464
+ * decorator isn't a child of the class itself. For methods/
1465
+ * properties, the decorator IS a direct child of the declaration,
1466
+ * so we also scan declNode.namedChildren.
1467
+ *
1468
+ * Idempotent across grammars: if neither location yields decorators
1469
+ * (most non-decorator-using languages), the function is a no-op.
1470
+ */
1471
+ extractDecoratorsFor(declNode, decoratedId) {
1472
+ const consider = (n) => {
1473
+ if (!n)
1474
+ return;
1475
+ // `marker_annotation` is Java's grammar for arg-less annotations
1476
+ // (`@Override`, `@Deprecated`); without including it, every
1477
+ // such Java annotation would be silently skipped.
1478
+ if (n.type !== 'decorator' &&
1479
+ n.type !== 'annotation' &&
1480
+ n.type !== 'marker_annotation') {
1481
+ return;
1482
+ }
1483
+ // Find the leading identifier: skip the `@` punct, unwrap
1484
+ // a call_expression if the decorator is invoked with args.
1485
+ let target = null;
1486
+ for (let i = 0; i < n.namedChildCount; i++) {
1487
+ const child = n.namedChild(i);
1488
+ if (!child)
1489
+ continue;
1490
+ if (child.type === 'call_expression') {
1491
+ const fn = (0, tree_sitter_helpers_1.getChildByField)(child, 'function') ?? child.namedChild(0);
1492
+ if (fn)
1493
+ target = fn;
1494
+ if (target)
1495
+ break;
1496
+ }
1497
+ if (child.type === 'identifier' ||
1498
+ child.type === 'member_expression' ||
1499
+ child.type === 'scoped_identifier' ||
1500
+ child.type === 'navigation_expression') {
1501
+ target = child;
1502
+ break;
1503
+ }
1504
+ }
1505
+ if (!target)
1506
+ return;
1507
+ let name = (0, tree_sitter_helpers_1.getNodeText)(target, this.source);
1508
+ const lastDot = Math.max(name.lastIndexOf('.'), name.lastIndexOf('::'));
1509
+ if (lastDot >= 0)
1510
+ name = name.slice(lastDot + 1).replace(/^[:.]/, '');
1511
+ if (!name)
1512
+ return;
1513
+ this.unresolvedReferences.push({
1514
+ fromNodeId: decoratedId,
1515
+ referenceName: name,
1516
+ referenceKind: 'decorates',
1517
+ line: n.startPosition.row + 1,
1518
+ column: n.startPosition.column,
1519
+ });
1520
+ };
1521
+ // 1. Decorators that are direct children of the declaration
1522
+ // (method/property style, also some grammars for class).
1523
+ for (let i = 0; i < declNode.namedChildCount; i++) {
1524
+ consider(declNode.namedChild(i));
1525
+ }
1526
+ // 2. Decorators that are PRECEDING siblings of the declaration
1527
+ // inside the parent's children (TypeScript class style).
1528
+ // Walk BACKWARDS from the declaration and stop at the first
1529
+ // non-decorator sibling — without that stop, decorators
1530
+ // belonging to an EARLIER unrelated declaration leak in
1531
+ // (e.g. `@A class Foo {} @B class Bar {}` would otherwise
1532
+ // attribute @A to Bar).
1533
+ //
1534
+ // Note on identity: tree-sitter web bindings return fresh JS
1535
+ // wrapper objects from `parent`/`namedChild` navigation, so
1536
+ // `sibling === declNode` is unreliable — `startIndex` does
1537
+ // the matching instead.
1538
+ const parent = declNode.parent;
1539
+ if (parent) {
1540
+ const declStart = declNode.startIndex;
1541
+ let declIdx = -1;
1542
+ for (let i = 0; i < parent.namedChildCount; i++) {
1543
+ const sibling = parent.namedChild(i);
1544
+ if (sibling && sibling.startIndex === declStart) {
1545
+ declIdx = i;
1546
+ break;
1547
+ }
1548
+ }
1549
+ if (declIdx > 0) {
1550
+ for (let j = declIdx - 1; j >= 0; j--) {
1551
+ const sibling = parent.namedChild(j);
1552
+ if (!sibling)
1553
+ continue;
1554
+ if (sibling.type !== 'decorator' && sibling.type !== 'annotation' && sibling.type !== 'marker_annotation') {
1555
+ break; // non-decorator separator → stop consuming
1556
+ }
1557
+ consider(sibling);
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ /**
1563
+ * Visit function body and extract calls (and structural nodes).
1564
+ *
1565
+ * In addition to call expressions, this also detects class/struct/enum
1566
+ * definitions inside function bodies. This handles two cases:
1567
+ * 1. Local class/struct/enum definitions (valid in C++, Java, etc.)
1568
+ * 2. C++ macro misparsing — macros like NLOHMANN_JSON_NAMESPACE_BEGIN cause
1569
+ * tree-sitter to interpret the namespace block as a function_definition,
1570
+ * hiding real class/struct/enum nodes inside the "function body".
1571
+ */
1572
+ visitFunctionBody(body, _functionId) {
1573
+ if (!this.extractor)
1574
+ return;
1575
+ const visitForCallsAndStructure = (node) => {
1576
+ const nodeType = node.type;
1577
+ if (this.extractor.callTypes.includes(nodeType)) {
1578
+ this.extractCall(node);
1579
+ }
1580
+ else if (INSTANTIATION_KINDS.has(nodeType)) {
1581
+ // `new Foo()` inside a function body — emit an `instantiates`
1582
+ // reference. Without this branch the body walker only knew
1583
+ // about `call_expression`, so constructor invocations
1584
+ // produced no graph edges at all.
1585
+ this.extractInstantiation(node);
1586
+ }
1587
+ else if (this.extractor.extractBareCall) {
1588
+ const calleeName = this.extractor.extractBareCall(node, this.source);
1589
+ if (calleeName && this.nodeStack.length > 0) {
1590
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
1591
+ if (callerId) {
1592
+ this.unresolvedReferences.push({
1593
+ fromNodeId: callerId,
1594
+ referenceName: calleeName,
1595
+ referenceKind: 'calls',
1596
+ line: node.startPosition.row + 1,
1597
+ column: node.startPosition.column,
1598
+ });
1599
+ }
1600
+ }
1601
+ }
1602
+ // Extract structural nodes found inside function bodies.
1603
+ // Each extract method visits its own children, so we return after extracting.
1604
+ if (this.extractor.classTypes.includes(nodeType)) {
1605
+ const classification = this.extractor.classifyClassNode?.(node) ?? 'class';
1606
+ if (classification === 'struct')
1607
+ this.extractStruct(node);
1608
+ else if (classification === 'enum')
1609
+ this.extractEnum(node);
1610
+ else if (classification === 'interface')
1611
+ this.extractInterface(node);
1612
+ else if (classification === 'trait')
1613
+ this.extractClass(node, 'trait');
1614
+ else
1615
+ this.extractClass(node);
1616
+ return;
1617
+ }
1618
+ if (this.extractor.structTypes.includes(nodeType)) {
1619
+ this.extractStruct(node);
1620
+ return;
1621
+ }
1622
+ if (this.extractor.enumTypes.includes(nodeType)) {
1623
+ this.extractEnum(node);
1624
+ return;
1625
+ }
1626
+ if (this.extractor.interfaceTypes.includes(nodeType)) {
1627
+ this.extractInterface(node);
1628
+ return;
1629
+ }
1630
+ for (let i = 0; i < node.namedChildCount; i++) {
1631
+ const child = node.namedChild(i);
1632
+ if (child) {
1633
+ visitForCallsAndStructure(child);
1634
+ }
1635
+ }
1636
+ };
1637
+ visitForCallsAndStructure(body);
1638
+ }
1639
+ /**
1640
+ * Extract inheritance relationships
1641
+ */
1642
+ extractInheritance(node, classId) {
1643
+ // Look for extends/implements clauses
1644
+ for (let i = 0; i < node.namedChildCount; i++) {
1645
+ const child = node.namedChild(i);
1646
+ if (!child)
1647
+ continue;
1648
+ if (child.type === 'extends_clause' ||
1649
+ child.type === 'superclass' ||
1650
+ child.type === 'base_clause' || // PHP class extends
1651
+ child.type === 'extends_interfaces' // Java interface extends
1652
+ ) {
1653
+ // Extract parent class/interface names
1654
+ // Java uses type_list wrapper: superclass -> type_identifier, extends_interfaces -> type_list -> type_identifier
1655
+ const typeList = child.namedChildren.find((c) => c.type === 'type_list');
1656
+ const targets = typeList ? typeList.namedChildren : [child.namedChild(0)];
1657
+ for (const target of targets) {
1658
+ if (target) {
1659
+ const name = (0, tree_sitter_helpers_1.getNodeText)(target, this.source);
1660
+ this.unresolvedReferences.push({
1661
+ fromNodeId: classId,
1662
+ referenceName: name,
1663
+ referenceKind: 'extends',
1664
+ line: target.startPosition.row + 1,
1665
+ column: target.startPosition.column,
1666
+ });
1667
+ }
1668
+ }
1669
+ }
1670
+ if (child.type === 'implements_clause' ||
1671
+ child.type === 'class_interface_clause' ||
1672
+ child.type === 'super_interfaces' || // Java class implements
1673
+ child.type === 'interfaces' // Dart
1674
+ ) {
1675
+ // Extract implemented interfaces
1676
+ // Java uses type_list wrapper: super_interfaces -> type_list -> type_identifier
1677
+ const typeList = child.namedChildren.find((c) => c.type === 'type_list');
1678
+ const targets = typeList ? typeList.namedChildren : child.namedChildren;
1679
+ for (const iface of targets) {
1680
+ if (iface) {
1681
+ const name = (0, tree_sitter_helpers_1.getNodeText)(iface, this.source);
1682
+ this.unresolvedReferences.push({
1683
+ fromNodeId: classId,
1684
+ referenceName: name,
1685
+ referenceKind: 'implements',
1686
+ line: iface.startPosition.row + 1,
1687
+ column: iface.startPosition.column,
1688
+ });
1689
+ }
1690
+ }
1691
+ }
1692
+ // Python superclass list: `class Flask(Scaffold, Mixin):`
1693
+ // argument_list contains identifier children for each parent class
1694
+ if (child.type === 'argument_list' && node.type === 'class_definition') {
1695
+ for (const arg of child.namedChildren) {
1696
+ if (arg.type === 'identifier' || arg.type === 'attribute') {
1697
+ const name = (0, tree_sitter_helpers_1.getNodeText)(arg, this.source);
1698
+ this.unresolvedReferences.push({
1699
+ fromNodeId: classId,
1700
+ referenceName: name,
1701
+ referenceKind: 'extends',
1702
+ line: arg.startPosition.row + 1,
1703
+ column: arg.startPosition.column,
1704
+ });
1705
+ }
1706
+ }
1707
+ }
1708
+ // Go interface embedding: `type Querier interface { LabelQuerier; ... }`
1709
+ // constraint_elem wraps the embedded interface type identifier
1710
+ if (child.type === 'constraint_elem') {
1711
+ const typeId = child.namedChildren.find((c) => c.type === 'type_identifier');
1712
+ if (typeId) {
1713
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
1714
+ this.unresolvedReferences.push({
1715
+ fromNodeId: classId,
1716
+ referenceName: name,
1717
+ referenceKind: 'extends',
1718
+ line: typeId.startPosition.row + 1,
1719
+ column: typeId.startPosition.column,
1720
+ });
1721
+ }
1722
+ }
1723
+ // Go struct embedding: field_declaration without field_identifier
1724
+ // e.g. `type DB struct { *Head; Queryable }` — no field name means embedded type
1725
+ if (child.type === 'field_declaration') {
1726
+ const hasFieldIdentifier = child.namedChildren.some((c) => c.type === 'field_identifier');
1727
+ if (!hasFieldIdentifier) {
1728
+ const typeId = child.namedChildren.find((c) => c.type === 'type_identifier');
1729
+ if (typeId) {
1730
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
1731
+ this.unresolvedReferences.push({
1732
+ fromNodeId: classId,
1733
+ referenceName: name,
1734
+ referenceKind: 'extends',
1735
+ line: typeId.startPosition.row + 1,
1736
+ column: typeId.startPosition.column,
1737
+ });
1738
+ }
1739
+ }
1740
+ }
1741
+ // Rust trait supertraits: `trait SubTrait: SuperTrait + Display { ... }`
1742
+ // trait_bounds contains type_identifier, generic_type, or higher_ranked_trait_bound children
1743
+ if (child.type === 'trait_bounds') {
1744
+ for (const bound of child.namedChildren) {
1745
+ let typeName;
1746
+ let posNode;
1747
+ if (bound.type === 'type_identifier') {
1748
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(bound, this.source);
1749
+ posNode = bound;
1750
+ }
1751
+ else if (bound.type === 'generic_type') {
1752
+ // e.g. `Deserialize<'de>`
1753
+ const inner = bound.namedChildren.find((c) => c.type === 'type_identifier');
1754
+ if (inner) {
1755
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(inner, this.source);
1756
+ posNode = inner;
1757
+ }
1758
+ }
1759
+ else if (bound.type === 'higher_ranked_trait_bound') {
1760
+ // e.g. `for<'de> Deserialize<'de>`
1761
+ const generic = bound.namedChildren.find((c) => c.type === 'generic_type');
1762
+ const typeId = generic?.namedChildren.find((c) => c.type === 'type_identifier')
1763
+ ?? bound.namedChildren.find((c) => c.type === 'type_identifier');
1764
+ if (typeId) {
1765
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
1766
+ posNode = typeId;
1767
+ }
1768
+ }
1769
+ if (typeName && posNode) {
1770
+ this.unresolvedReferences.push({
1771
+ fromNodeId: classId,
1772
+ referenceName: typeName,
1773
+ referenceKind: 'extends',
1774
+ line: posNode.startPosition.row + 1,
1775
+ column: posNode.startPosition.column,
1776
+ });
1777
+ }
1778
+ }
1779
+ }
1780
+ // C#: `class Movie : BaseItem, IPlugin` → base_list with identifier children
1781
+ // base_list combines both base class and interfaces in a single colon-separated list.
1782
+ // We emit all as 'extends' since the syntax doesn't distinguish them.
1783
+ if (child.type === 'base_list') {
1784
+ for (const baseType of child.namedChildren) {
1785
+ if (baseType) {
1786
+ // For generic base types like `ClientBase<T>`, extract just the type name
1787
+ const name = baseType.type === 'generic_name'
1788
+ ? (0, tree_sitter_helpers_1.getNodeText)(baseType.namedChildren.find((c) => c.type === 'identifier') ?? baseType, this.source)
1789
+ : (0, tree_sitter_helpers_1.getNodeText)(baseType, this.source);
1790
+ this.unresolvedReferences.push({
1791
+ fromNodeId: classId,
1792
+ referenceName: name,
1793
+ referenceKind: 'extends',
1794
+ line: baseType.startPosition.row + 1,
1795
+ column: baseType.startPosition.column,
1796
+ });
1797
+ }
1798
+ }
1799
+ }
1800
+ // Kotlin: `class Foo : Bar, Baz` → delegation_specifier > user_type > type_identifier
1801
+ // Also handles `class Foo : Bar()` → delegation_specifier > constructor_invocation > user_type
1802
+ if (child.type === 'delegation_specifier') {
1803
+ const userType = child.namedChildren.find((c) => c.type === 'user_type');
1804
+ const constructorInvocation = child.namedChildren.find((c) => c.type === 'constructor_invocation');
1805
+ const target = userType ?? constructorInvocation;
1806
+ if (target) {
1807
+ const typeId = target.type === 'user_type'
1808
+ ? target.namedChildren.find((c) => c.type === 'type_identifier') ?? target
1809
+ : target.namedChildren.find((c) => c.type === 'user_type')?.namedChildren.find((c) => c.type === 'type_identifier')
1810
+ ?? target.namedChildren.find((c) => c.type === 'user_type') ?? target;
1811
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
1812
+ this.unresolvedReferences.push({
1813
+ fromNodeId: classId,
1814
+ referenceName: name,
1815
+ referenceKind: 'extends',
1816
+ line: typeId.startPosition.row + 1,
1817
+ column: typeId.startPosition.column,
1818
+ });
1819
+ }
1820
+ }
1821
+ // Swift: inheritance_specifier > user_type > type_identifier
1822
+ // Used for class inheritance, protocol conformance, and protocol inheritance
1823
+ if (child.type === 'inheritance_specifier') {
1824
+ const userType = child.namedChildren.find((c) => c.type === 'user_type');
1825
+ const typeId = userType?.namedChildren.find((c) => c.type === 'type_identifier');
1826
+ if (typeId) {
1827
+ const name = (0, tree_sitter_helpers_1.getNodeText)(typeId, this.source);
1828
+ this.unresolvedReferences.push({
1829
+ fromNodeId: classId,
1830
+ referenceName: name,
1831
+ referenceKind: 'extends',
1832
+ line: typeId.startPosition.row + 1,
1833
+ column: typeId.startPosition.column,
1834
+ });
1835
+ }
1836
+ }
1837
+ // JavaScript class_heritage has bare identifier without extends_clause wrapper
1838
+ // e.g. `class Foo extends Bar {}` → class_heritage → identifier("Bar")
1839
+ if ((child.type === 'identifier' || child.type === 'type_identifier') &&
1840
+ node.type === 'class_heritage') {
1841
+ const name = (0, tree_sitter_helpers_1.getNodeText)(child, this.source);
1842
+ this.unresolvedReferences.push({
1843
+ fromNodeId: classId,
1844
+ referenceName: name,
1845
+ referenceKind: 'extends',
1846
+ line: child.startPosition.row + 1,
1847
+ column: child.startPosition.column,
1848
+ });
1849
+ }
1850
+ // Recurse into container nodes (e.g. field_declaration_list in Go structs,
1851
+ // class_heritage in TypeScript which wraps extends_clause/implements_clause)
1852
+ if (child.type === 'field_declaration_list' || child.type === 'class_heritage') {
1853
+ this.extractInheritance(child, classId);
1854
+ }
1855
+ }
1856
+ }
1857
+ /**
1858
+ * Rust `impl Trait for Type` — creates an implements edge from Type to Trait.
1859
+ * For plain `impl Type { ... }` (no trait), no inheritance edge is needed.
1860
+ */
1861
+ extractRustImplItem(node) {
1862
+ // Check if this is `impl Trait for Type` by looking for a `for` keyword
1863
+ const hasFor = node.children.some((c) => c.type === 'for' && !c.isNamed);
1864
+ if (!hasFor)
1865
+ return;
1866
+ // In `impl Trait for Type`, the type_identifiers are:
1867
+ // first = Trait name, last = implementing Type name
1868
+ // Also handle generic types like `impl<T> Trait for MyStruct<T>`
1869
+ const typeIdents = node.namedChildren.filter((c) => c.type === 'type_identifier' || c.type === 'generic_type' || c.type === 'scoped_type_identifier');
1870
+ if (typeIdents.length < 2)
1871
+ return;
1872
+ const traitNode = typeIdents[0];
1873
+ const typeNode = typeIdents[typeIdents.length - 1];
1874
+ // Get the trait name (handle scoped paths like std::fmt::Display)
1875
+ const traitName = traitNode.type === 'scoped_type_identifier'
1876
+ ? this.source.substring(traitNode.startIndex, traitNode.endIndex)
1877
+ : (0, tree_sitter_helpers_1.getNodeText)(traitNode, this.source);
1878
+ // Get the implementing type name (extract inner type_identifier for generics)
1879
+ let typeName;
1880
+ if (typeNode.type === 'generic_type') {
1881
+ const inner = typeNode.namedChildren.find((c) => c.type === 'type_identifier');
1882
+ typeName = inner ? (0, tree_sitter_helpers_1.getNodeText)(inner, this.source) : (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source);
1883
+ }
1884
+ else {
1885
+ typeName = (0, tree_sitter_helpers_1.getNodeText)(typeNode, this.source);
1886
+ }
1887
+ // Find the struct/type node for the implementing type
1888
+ const typeNodeId = this.findNodeByName(typeName);
1889
+ if (typeNodeId) {
1890
+ this.unresolvedReferences.push({
1891
+ fromNodeId: typeNodeId,
1892
+ referenceName: traitName,
1893
+ referenceKind: 'implements',
1894
+ line: traitNode.startPosition.row + 1,
1895
+ column: traitNode.startPosition.column,
1896
+ });
1897
+ }
1898
+ }
1899
+ /**
1900
+ * Find a previously-extracted node by name (used for back-references like impl blocks)
1901
+ */
1902
+ findNodeByName(name) {
1903
+ for (const node of this.nodes) {
1904
+ if (node.name === name && (node.kind === 'struct' || node.kind === 'enum' || node.kind === 'class')) {
1905
+ return node.id;
1906
+ }
1907
+ }
1908
+ return undefined;
1909
+ }
1910
+ /**
1911
+ * Languages that support type annotations (TypeScript, etc.)
1912
+ */
1913
+ TYPE_ANNOTATION_LANGUAGES = new Set([
1914
+ 'typescript', 'tsx', 'dart', 'kotlin', 'swift', 'rust', 'go', 'java', 'csharp',
1915
+ ]);
1916
+ /**
1917
+ * Built-in/primitive type names that shouldn't create references
1918
+ */
1919
+ BUILTIN_TYPES = new Set([
1920
+ 'string', 'number', 'boolean', 'void', 'null', 'undefined', 'never', 'any', 'unknown',
1921
+ 'object', 'symbol', 'bigint', 'true', 'false',
1922
+ // Rust
1923
+ 'str', 'bool', 'i8', 'i16', 'i32', 'i64', 'i128', 'isize',
1924
+ 'u8', 'u16', 'u32', 'u64', 'u128', 'usize', 'f32', 'f64', 'char',
1925
+ // Java/C#
1926
+ 'int', 'long', 'short', 'byte', 'float', 'double', 'char',
1927
+ // Go
1928
+ 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64',
1929
+ 'float32', 'float64', 'complex64', 'complex128', 'rune', 'error',
1930
+ ]);
1931
+ /**
1932
+ * Extract type references from type annotations on a function/method/field node.
1933
+ * Creates 'references' edges for parameter types, return types, and field types.
1934
+ */
1935
+ extractTypeAnnotations(node, nodeId) {
1936
+ if (!this.extractor)
1937
+ return;
1938
+ if (!this.TYPE_ANNOTATION_LANGUAGES.has(this.language))
1939
+ return;
1940
+ // Extract parameter type annotations
1941
+ const params = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.paramsField || 'parameters');
1942
+ if (params) {
1943
+ this.extractTypeRefsFromSubtree(params, nodeId);
1944
+ }
1945
+ // Extract return type annotation
1946
+ const returnType = (0, tree_sitter_helpers_1.getChildByField)(node, this.extractor.returnField || 'return_type');
1947
+ if (returnType) {
1948
+ this.extractTypeRefsFromSubtree(returnType, nodeId);
1949
+ }
1950
+ // Extract direct type annotation (for class fields like `model: ITextModel`)
1951
+ const typeAnnotation = node.namedChildren.find((c) => c.type === 'type_annotation');
1952
+ if (typeAnnotation) {
1953
+ this.extractTypeRefsFromSubtree(typeAnnotation, nodeId);
1954
+ }
1955
+ }
1956
+ /**
1957
+ * Extract type references from a variable's type annotation.
1958
+ */
1959
+ extractVariableTypeAnnotation(node, nodeId) {
1960
+ if (!this.TYPE_ANNOTATION_LANGUAGES.has(this.language))
1961
+ return;
1962
+ // Find type_annotation child (covers TS `: Type`, Rust `: Type`, etc.)
1963
+ const typeAnnotation = node.namedChildren.find((c) => c.type === 'type_annotation');
1964
+ if (typeAnnotation) {
1965
+ this.extractTypeRefsFromSubtree(typeAnnotation, nodeId);
1966
+ }
1967
+ }
1968
+ /**
1969
+ * Recursively walk a subtree and extract all type_identifier references.
1970
+ * Handles unions, intersections, generics, arrays, etc.
1971
+ */
1972
+ extractTypeRefsFromSubtree(node, fromNodeId) {
1973
+ if (node.type === 'type_identifier') {
1974
+ const typeName = (0, tree_sitter_helpers_1.getNodeText)(node, this.source);
1975
+ if (typeName && !this.BUILTIN_TYPES.has(typeName)) {
1976
+ this.unresolvedReferences.push({
1977
+ fromNodeId,
1978
+ referenceName: typeName,
1979
+ referenceKind: 'references',
1980
+ line: node.startPosition.row + 1,
1981
+ column: node.startPosition.column,
1982
+ });
1983
+ }
1984
+ return; // type_identifier is a leaf
1985
+ }
1986
+ // Recurse into children (handles union_type, intersection_type, generic_type, etc.)
1987
+ for (let i = 0; i < node.namedChildCount; i++) {
1988
+ const child = node.namedChild(i);
1989
+ if (child) {
1990
+ this.extractTypeRefsFromSubtree(child, fromNodeId);
1991
+ }
1992
+ }
1993
+ }
1994
+ /**
1995
+ * Handle Pascal-specific AST structures.
1996
+ * Returns true if the node was fully handled and children should be skipped.
1997
+ */
1998
+ visitPascalNode(node) {
1999
+ const nodeType = node.type;
2000
+ // Unit/Program/Library → module node
2001
+ if (nodeType === 'unit' || nodeType === 'program' || nodeType === 'library') {
2002
+ const moduleNameNode = node.namedChildren.find((c) => c.type === 'moduleName');
2003
+ const name = moduleNameNode ? (0, tree_sitter_helpers_1.getNodeText)(moduleNameNode, this.source) : '';
2004
+ // Fallback to filename without extension if module name is empty
2005
+ const moduleName = name || path.basename(this.filePath).replace(/\.[^.]+$/, '');
2006
+ this.createNode('module', moduleName, node);
2007
+ // Continue visiting children (interface/implementation sections)
2008
+ for (let i = 0; i < node.namedChildCount; i++) {
2009
+ const child = node.namedChild(i);
2010
+ if (child)
2011
+ this.visitNode(child);
2012
+ }
2013
+ return true;
2014
+ }
2015
+ // declType wraps declClass/declIntf/declEnum/type-alias
2016
+ // The name lives on declType, the inner node determines the kind
2017
+ if (nodeType === 'declType') {
2018
+ this.extractPascalDeclType(node);
2019
+ return true;
2020
+ }
2021
+ // declUses → import nodes for each unit name
2022
+ if (nodeType === 'declUses') {
2023
+ this.extractPascalUses(node);
2024
+ return true;
2025
+ }
2026
+ // declConsts → container; visit children for individual declConst
2027
+ if (nodeType === 'declConsts') {
2028
+ for (let i = 0; i < node.namedChildCount; i++) {
2029
+ const child = node.namedChild(i);
2030
+ if (child?.type === 'declConst') {
2031
+ this.extractPascalConst(child);
2032
+ }
2033
+ }
2034
+ return true;
2035
+ }
2036
+ // declConst at top level (outside declConsts)
2037
+ if (nodeType === 'declConst') {
2038
+ this.extractPascalConst(node);
2039
+ return true;
2040
+ }
2041
+ // declTypes → container for type declarations
2042
+ if (nodeType === 'declTypes') {
2043
+ for (let i = 0; i < node.namedChildCount; i++) {
2044
+ const child = node.namedChild(i);
2045
+ if (child)
2046
+ this.visitNode(child);
2047
+ }
2048
+ return true;
2049
+ }
2050
+ // declVars → container for variable declarations
2051
+ if (nodeType === 'declVars') {
2052
+ for (let i = 0; i < node.namedChildCount; i++) {
2053
+ const child = node.namedChild(i);
2054
+ if (child?.type === 'declVar') {
2055
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
2056
+ if (nameNode) {
2057
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2058
+ this.createNode('variable', name, child);
2059
+ }
2060
+ }
2061
+ }
2062
+ return true;
2063
+ }
2064
+ // defProc in implementation section → extract calls but don't create duplicate nodes
2065
+ if (nodeType === 'defProc') {
2066
+ this.extractPascalDefProc(node);
2067
+ return true;
2068
+ }
2069
+ // declProp → property node
2070
+ if (nodeType === 'declProp') {
2071
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2072
+ if (nameNode) {
2073
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2074
+ const visibility = this.extractor.getVisibility?.(node);
2075
+ this.createNode('property', name, node, { visibility });
2076
+ }
2077
+ return true;
2078
+ }
2079
+ // declField → field node
2080
+ if (nodeType === 'declField') {
2081
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2082
+ if (nameNode) {
2083
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2084
+ const visibility = this.extractor.getVisibility?.(node);
2085
+ this.createNode('field', name, node, { visibility });
2086
+ }
2087
+ return true;
2088
+ }
2089
+ // declSection → visit children (propagates visibility via getVisibility)
2090
+ if (nodeType === 'declSection') {
2091
+ for (let i = 0; i < node.namedChildCount; i++) {
2092
+ const child = node.namedChild(i);
2093
+ if (child)
2094
+ this.visitNode(child);
2095
+ }
2096
+ return true;
2097
+ }
2098
+ // exprCall → extract function call reference
2099
+ if (nodeType === 'exprCall') {
2100
+ this.extractPascalCall(node);
2101
+ return true;
2102
+ }
2103
+ // interface/implementation sections → visit children
2104
+ if (nodeType === 'interface' || nodeType === 'implementation') {
2105
+ for (let i = 0; i < node.namedChildCount; i++) {
2106
+ const child = node.namedChild(i);
2107
+ if (child)
2108
+ this.visitNode(child);
2109
+ }
2110
+ return true;
2111
+ }
2112
+ // block (begin..end) → visit for calls
2113
+ if (nodeType === 'block') {
2114
+ this.visitPascalBlock(node);
2115
+ return true;
2116
+ }
2117
+ return false;
2118
+ }
2119
+ /**
2120
+ * Extract a Pascal declType node (class, interface, enum, or type alias)
2121
+ */
2122
+ extractPascalDeclType(node) {
2123
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2124
+ if (!nameNode)
2125
+ return;
2126
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2127
+ // Find the inner type declaration
2128
+ const declClass = node.namedChildren.find((c) => c.type === 'declClass');
2129
+ const declIntf = node.namedChildren.find((c) => c.type === 'declIntf');
2130
+ const typeChild = node.namedChildren.find((c) => c.type === 'type');
2131
+ if (declClass) {
2132
+ const classNode = this.createNode('class', name, node);
2133
+ if (classNode) {
2134
+ // Extract inheritance from typeref children of declClass
2135
+ this.extractPascalInheritance(declClass, classNode.id);
2136
+ // Visit class body
2137
+ this.nodeStack.push(classNode.id);
2138
+ for (let i = 0; i < declClass.namedChildCount; i++) {
2139
+ const child = declClass.namedChild(i);
2140
+ if (child)
2141
+ this.visitNode(child);
2142
+ }
2143
+ this.nodeStack.pop();
2144
+ }
2145
+ }
2146
+ else if (declIntf) {
2147
+ const ifaceNode = this.createNode('interface', name, node);
2148
+ if (ifaceNode) {
2149
+ // Visit interface members
2150
+ this.nodeStack.push(ifaceNode.id);
2151
+ for (let i = 0; i < declIntf.namedChildCount; i++) {
2152
+ const child = declIntf.namedChild(i);
2153
+ if (child)
2154
+ this.visitNode(child);
2155
+ }
2156
+ this.nodeStack.pop();
2157
+ }
2158
+ }
2159
+ else if (typeChild) {
2160
+ // Check if it contains a declEnum
2161
+ const declEnum = typeChild.namedChildren.find((c) => c.type === 'declEnum');
2162
+ if (declEnum) {
2163
+ const enumNode = this.createNode('enum', name, node);
2164
+ if (enumNode) {
2165
+ // Extract enum members
2166
+ this.nodeStack.push(enumNode.id);
2167
+ for (let i = 0; i < declEnum.namedChildCount; i++) {
2168
+ const child = declEnum.namedChild(i);
2169
+ if (child?.type === 'declEnumValue') {
2170
+ const memberName = (0, tree_sitter_helpers_1.getChildByField)(child, 'name');
2171
+ if (memberName) {
2172
+ this.createNode('enum_member', (0, tree_sitter_helpers_1.getNodeText)(memberName, this.source), child);
2173
+ }
2174
+ }
2175
+ }
2176
+ this.nodeStack.pop();
2177
+ }
2178
+ }
2179
+ else {
2180
+ // Simple type alias: type TFoo = string / type TFoo = Integer
2181
+ this.createNode('type_alias', name, node);
2182
+ }
2183
+ }
2184
+ else {
2185
+ // Fallback: could be a forward declaration or simple alias
2186
+ this.createNode('type_alias', name, node);
2187
+ }
2188
+ }
2189
+ /**
2190
+ * Extract Pascal uses clause into individual import nodes
2191
+ */
2192
+ extractPascalUses(node) {
2193
+ const importText = (0, tree_sitter_helpers_1.getNodeText)(node, this.source).trim();
2194
+ for (let i = 0; i < node.namedChildCount; i++) {
2195
+ const child = node.namedChild(i);
2196
+ if (child?.type === 'moduleName') {
2197
+ const unitName = (0, tree_sitter_helpers_1.getNodeText)(child, this.source);
2198
+ this.createNode('import', unitName, child, {
2199
+ signature: importText,
2200
+ });
2201
+ // Create unresolved reference for resolution
2202
+ if (this.nodeStack.length > 0) {
2203
+ const parentId = this.nodeStack[this.nodeStack.length - 1];
2204
+ if (parentId) {
2205
+ this.unresolvedReferences.push({
2206
+ fromNodeId: parentId,
2207
+ referenceName: unitName,
2208
+ referenceKind: 'imports',
2209
+ line: child.startPosition.row + 1,
2210
+ column: child.startPosition.column,
2211
+ });
2212
+ }
2213
+ }
2214
+ }
2215
+ }
2216
+ }
2217
+ /**
2218
+ * Extract a Pascal constant declaration
2219
+ */
2220
+ extractPascalConst(node) {
2221
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'name');
2222
+ if (!nameNode)
2223
+ return;
2224
+ const name = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source);
2225
+ const defaultValue = node.namedChildren.find((c) => c.type === 'defaultValue');
2226
+ const sig = defaultValue ? (0, tree_sitter_helpers_1.getNodeText)(defaultValue, this.source) : undefined;
2227
+ this.createNode('constant', name, node, { signature: sig });
2228
+ }
2229
+ /**
2230
+ * Extract Pascal inheritance (extends/implements) from declClass typeref children
2231
+ */
2232
+ extractPascalInheritance(declClass, classId) {
2233
+ const typerefs = declClass.namedChildren.filter((c) => c.type === 'typeref');
2234
+ for (let i = 0; i < typerefs.length; i++) {
2235
+ const ref = typerefs[i];
2236
+ const name = (0, tree_sitter_helpers_1.getNodeText)(ref, this.source);
2237
+ this.unresolvedReferences.push({
2238
+ fromNodeId: classId,
2239
+ referenceName: name,
2240
+ referenceKind: i === 0 ? 'extends' : 'implements',
2241
+ line: ref.startPosition.row + 1,
2242
+ column: ref.startPosition.column,
2243
+ });
2244
+ }
2245
+ }
2246
+ /**
2247
+ * Extract calls and resolve method context from a Pascal defProc (implementation body).
2248
+ * Does not create a new node — the declaration was already captured from the interface section.
2249
+ */
2250
+ extractPascalDefProc(node) {
2251
+ // Find the matching declaration node by name to use as call parent
2252
+ const declProc = node.namedChildren.find((c) => c.type === 'declProc');
2253
+ if (!declProc)
2254
+ return;
2255
+ const nameNode = (0, tree_sitter_helpers_1.getChildByField)(declProc, 'name');
2256
+ if (!nameNode)
2257
+ return;
2258
+ const fullName = (0, tree_sitter_helpers_1.getNodeText)(nameNode, this.source).trim();
2259
+ // fullName is like "TAuthService.Create"
2260
+ const shortName = fullName.includes('.') ? fullName.split('.').pop() : fullName;
2261
+ const fullNameKey = fullName.toLowerCase();
2262
+ const shortNameKey = shortName.toLowerCase();
2263
+ // Build method index on first use (O(n) once, then O(1) per lookup)
2264
+ if (!this.methodIndex) {
2265
+ this.methodIndex = new Map();
2266
+ for (const n of this.nodes) {
2267
+ if (n.kind === 'method' || n.kind === 'function') {
2268
+ const nameKey = n.name.toLowerCase();
2269
+ // Keep first seen short-name mapping to avoid silently overwriting earlier entries.
2270
+ if (!this.methodIndex.has(nameKey)) {
2271
+ this.methodIndex.set(nameKey, n.id);
2272
+ }
2273
+ // For Pascal methods, also index qualified forms (e.g. TAuthService.Create).
2274
+ if (n.kind === 'method') {
2275
+ const qualifiedParts = n.qualifiedName.split('::');
2276
+ if (qualifiedParts.length >= 2) {
2277
+ // Create suffix keys so both "Module.Class.Method" and "Class.Method" can resolve.
2278
+ for (let i = 0; i < qualifiedParts.length - 1; i++) {
2279
+ const scopedName = qualifiedParts.slice(i).join('.').toLowerCase();
2280
+ this.methodIndex.set(scopedName, n.id);
2281
+ }
2282
+ }
2283
+ }
2284
+ }
2285
+ }
2286
+ }
2287
+ const parentId = this.methodIndex.get(fullNameKey) ||
2288
+ this.methodIndex.get(shortNameKey) ||
2289
+ this.nodeStack[this.nodeStack.length - 1];
2290
+ if (!parentId)
2291
+ return;
2292
+ // Visit the block for calls
2293
+ const block = node.namedChildren.find((c) => c.type === 'block');
2294
+ if (block) {
2295
+ this.nodeStack.push(parentId);
2296
+ this.visitPascalBlock(block);
2297
+ this.nodeStack.pop();
2298
+ }
2299
+ }
2300
+ /**
2301
+ * Extract function calls from a Pascal expression
2302
+ */
2303
+ extractPascalCall(node) {
2304
+ if (this.nodeStack.length === 0)
2305
+ return;
2306
+ const callerId = this.nodeStack[this.nodeStack.length - 1];
2307
+ if (!callerId)
2308
+ return;
2309
+ // Get the callee name — first child is typically the identifier or exprDot
2310
+ const firstChild = node.namedChild(0);
2311
+ if (!firstChild)
2312
+ return;
2313
+ let calleeName = '';
2314
+ if (firstChild.type === 'exprDot') {
2315
+ // Qualified call: Obj.Method(...)
2316
+ const identifiers = firstChild.namedChildren.filter((c) => c.type === 'identifier');
2317
+ if (identifiers.length > 0) {
2318
+ calleeName = identifiers.map((id) => (0, tree_sitter_helpers_1.getNodeText)(id, this.source)).join('.');
2319
+ }
2320
+ }
2321
+ else if (firstChild.type === 'identifier') {
2322
+ calleeName = (0, tree_sitter_helpers_1.getNodeText)(firstChild, this.source);
2323
+ }
2324
+ if (calleeName) {
2325
+ this.unresolvedReferences.push({
2326
+ fromNodeId: callerId,
2327
+ referenceName: calleeName,
2328
+ referenceKind: 'calls',
2329
+ line: node.startPosition.row + 1,
2330
+ column: node.startPosition.column,
2331
+ });
2332
+ }
2333
+ // Also visit arguments for nested calls
2334
+ const args = node.namedChildren.find((c) => c.type === 'exprArgs');
2335
+ if (args) {
2336
+ this.visitPascalBlock(args);
2337
+ }
2338
+ }
2339
+ /**
2340
+ * Recursively visit a Pascal block/statement tree for call expressions
2341
+ */
2342
+ visitPascalBlock(node) {
2343
+ for (let i = 0; i < node.namedChildCount; i++) {
2344
+ const child = node.namedChild(i);
2345
+ if (!child)
2346
+ continue;
2347
+ if (child.type === 'exprCall') {
2348
+ this.extractPascalCall(child);
2349
+ }
2350
+ else if (child.type === 'exprDot') {
2351
+ // Check if exprDot contains an exprCall
2352
+ for (let j = 0; j < child.namedChildCount; j++) {
2353
+ const grandchild = child.namedChild(j);
2354
+ if (grandchild?.type === 'exprCall') {
2355
+ this.extractPascalCall(grandchild);
2356
+ }
2357
+ }
2358
+ }
2359
+ else {
2360
+ this.visitPascalBlock(child);
2361
+ }
2362
+ }
2363
+ }
2364
+ }
2365
+ exports.TreeSitterExtractor = TreeSitterExtractor;
2366
+ /**
2367
+ * Extract nodes and edges from source code.
2368
+ *
2369
+ * If `frameworkNames` is provided, framework-specific extractors matching
2370
+ * those names and the file's language are run after the tree-sitter pass.
2371
+ * Their nodes/references/errors are merged into the returned result.
2372
+ */
2373
+ function extractFromSource(filePath, source, language, frameworkNames) {
2374
+ const detectedLanguage = language || (0, grammars_1.detectLanguage)(filePath, source);
2375
+ const fileExtension = path.extname(filePath).toLowerCase();
2376
+ let result;
2377
+ // Use custom extractor for Svelte
2378
+ if (detectedLanguage === 'svelte') {
2379
+ const extractor = new svelte_extractor_1.SvelteExtractor(filePath, source);
2380
+ result = extractor.extract();
2381
+ }
2382
+ else if (detectedLanguage === 'vue') {
2383
+ // Use custom extractor for Vue
2384
+ const extractor = new vue_extractor_1.VueExtractor(filePath, source);
2385
+ result = extractor.extract();
2386
+ }
2387
+ else if (detectedLanguage === 'liquid') {
2388
+ // Use custom extractor for Liquid
2389
+ const extractor = new liquid_extractor_1.LiquidExtractor(filePath, source);
2390
+ result = extractor.extract();
2391
+ }
2392
+ else if (detectedLanguage === 'pascal' &&
2393
+ (fileExtension === '.dfm' || fileExtension === '.fmx')) {
2394
+ // Use custom extractor for DFM/FMX form files
2395
+ const extractor = new dfm_extractor_1.DfmExtractor(filePath, source);
2396
+ result = extractor.extract();
2397
+ }
2398
+ else {
2399
+ const extractor = new TreeSitterExtractor(filePath, source, detectedLanguage);
2400
+ result = extractor.extract();
2401
+ }
2402
+ // Framework-specific extraction (routes, middleware, etc.)
2403
+ if (frameworkNames && frameworkNames.length > 0) {
2404
+ const allResolvers = (0, frameworks_1.getAllFrameworkResolvers)();
2405
+ const applicable = (0, frameworks_1.getApplicableFrameworks)(allResolvers.filter((r) => frameworkNames.includes(r.name)), detectedLanguage);
2406
+ for (const fw of applicable) {
2407
+ if (!fw.extract)
2408
+ continue;
2409
+ try {
2410
+ const fwResult = fw.extract(filePath, source);
2411
+ result.nodes.push(...fwResult.nodes);
2412
+ result.unresolvedReferences.push(...fwResult.references);
2413
+ }
2414
+ catch (err) {
2415
+ result.errors.push({
2416
+ message: `Framework extractor '${fw.name}' failed: ${err instanceof Error ? err.message : String(err)}`,
2417
+ filePath,
2418
+ severity: 'warning',
2419
+ });
2420
+ }
2421
+ }
2422
+ }
2423
+ return result;
2424
+ }
2425
+ //# sourceMappingURL=tree-sitter.js.map