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