codegraphcontext-rust 0.9.24__cp314-cp314-win_amd64.whl

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 (112) hide show
  1. codegraphcontext/__init__.py +2 -0
  2. codegraphcontext/__main__.py +5 -0
  3. codegraphcontext/_cgc_rust.cp314-win_amd64.pyd +4 -0
  4. codegraphcontext/cli/__init__.py +1 -0
  5. codegraphcontext/cli/cli_helpers.py +774 -0
  6. codegraphcontext/cli/config_manager.py +1051 -0
  7. codegraphcontext/cli/entry.py +21 -0
  8. codegraphcontext/cli/main.py +2386 -0
  9. codegraphcontext/cli/registry_commands.py +404 -0
  10. codegraphcontext/cli/setup_macos.py +93 -0
  11. codegraphcontext/cli/setup_wizard.py +991 -0
  12. codegraphcontext/cli/visualizer.py +50 -0
  13. codegraphcontext/core/__init__.py +165 -0
  14. codegraphcontext/core/bundle_registry.py +181 -0
  15. codegraphcontext/core/cgc_bundle.py +858 -0
  16. codegraphcontext/core/cgcignore.py +118 -0
  17. codegraphcontext/core/database.py +273 -0
  18. codegraphcontext/core/database_falkordb.py +480 -0
  19. codegraphcontext/core/database_falkordb_remote.py +199 -0
  20. codegraphcontext/core/database_kuzu.py +636 -0
  21. codegraphcontext/core/falkor_worker.py +132 -0
  22. codegraphcontext/core/jobs.py +132 -0
  23. codegraphcontext/core/watcher.py +260 -0
  24. codegraphcontext/prompts.py +125 -0
  25. codegraphcontext/server.py +471 -0
  26. codegraphcontext/tool_definitions.py +220 -0
  27. codegraphcontext/tools/__init__.py +0 -0
  28. codegraphcontext/tools/advanced_language_query_tool.py +103 -0
  29. codegraphcontext/tools/code_finder.py +1160 -0
  30. codegraphcontext/tools/graph_builder.py +337 -0
  31. codegraphcontext/tools/handlers/analysis_handlers.py +114 -0
  32. codegraphcontext/tools/handlers/indexing_handlers.py +116 -0
  33. codegraphcontext/tools/handlers/management_handlers.py +339 -0
  34. codegraphcontext/tools/handlers/query_handlers.py +83 -0
  35. codegraphcontext/tools/handlers/watcher_handlers.py +83 -0
  36. codegraphcontext/tools/indexing/__init__.py +1 -0
  37. codegraphcontext/tools/indexing/angular_routes.py +396 -0
  38. codegraphcontext/tools/indexing/cgc_wiki_cli.py +1334 -0
  39. codegraphcontext/tools/indexing/constants.py +70 -0
  40. codegraphcontext/tools/indexing/context_generator.py +461 -0
  41. codegraphcontext/tools/indexing/discovery.py +64 -0
  42. codegraphcontext/tools/indexing/engine.py +114 -0
  43. codegraphcontext/tools/indexing/execution_flows.py +355 -0
  44. codegraphcontext/tools/indexing/module_grouping.py +551 -0
  45. codegraphcontext/tools/indexing/noise_filter.py +131 -0
  46. codegraphcontext/tools/indexing/op_param_extraction.py +287 -0
  47. codegraphcontext/tools/indexing/persistence/__init__.py +3 -0
  48. codegraphcontext/tools/indexing/persistence/duckdb_writer.py +1116 -0
  49. codegraphcontext/tools/indexing/persistence/parquet_loader.py +643 -0
  50. codegraphcontext/tools/indexing/persistence/writer.py +1562 -0
  51. codegraphcontext/tools/indexing/pipeline.py +171 -0
  52. codegraphcontext/tools/indexing/pre_scan.py +105 -0
  53. codegraphcontext/tools/indexing/rationale_extraction.py +154 -0
  54. codegraphcontext/tools/indexing/resolution/__init__.py +8 -0
  55. codegraphcontext/tools/indexing/resolution/calls.py +253 -0
  56. codegraphcontext/tools/indexing/resolution/inheritance.py +91 -0
  57. codegraphcontext/tools/indexing/route_extraction.py +659 -0
  58. codegraphcontext/tools/indexing/sanitize.py +41 -0
  59. codegraphcontext/tools/indexing/schema.py +79 -0
  60. codegraphcontext/tools/indexing/schema_contract.py +44 -0
  61. codegraphcontext/tools/indexing/scip_pipeline.py +140 -0
  62. codegraphcontext/tools/languages/c.py +563 -0
  63. codegraphcontext/tools/languages/cpp.py +616 -0
  64. codegraphcontext/tools/languages/csharp.py +551 -0
  65. codegraphcontext/tools/languages/dart.py +378 -0
  66. codegraphcontext/tools/languages/elixir.py +460 -0
  67. codegraphcontext/tools/languages/go.py +499 -0
  68. codegraphcontext/tools/languages/haskell.py +426 -0
  69. codegraphcontext/tools/languages/java.py +500 -0
  70. codegraphcontext/tools/languages/javascript.py +589 -0
  71. codegraphcontext/tools/languages/kotlin.py +640 -0
  72. codegraphcontext/tools/languages/perl.py +260 -0
  73. codegraphcontext/tools/languages/php.py +519 -0
  74. codegraphcontext/tools/languages/python.py +578 -0
  75. codegraphcontext/tools/languages/ruby.py +537 -0
  76. codegraphcontext/tools/languages/rust.py +295 -0
  77. codegraphcontext/tools/languages/scala.py +519 -0
  78. codegraphcontext/tools/languages/swift.py +491 -0
  79. codegraphcontext/tools/languages/typescript.py +606 -0
  80. codegraphcontext/tools/languages/typescriptjsx.py +151 -0
  81. codegraphcontext/tools/package_resolver.py +472 -0
  82. codegraphcontext/tools/query_tool_languages/c_toolkit.py +5 -0
  83. codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +87 -0
  84. codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +5 -0
  85. codegraphcontext/tools/query_tool_languages/dart_toolkit.py +5 -0
  86. codegraphcontext/tools/query_tool_languages/go_toolkit.py +5 -0
  87. codegraphcontext/tools/query_tool_languages/haskell_toolkit.py +5 -0
  88. codegraphcontext/tools/query_tool_languages/java_toolkit.py +5 -0
  89. codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +5 -0
  90. codegraphcontext/tools/query_tool_languages/perl_toolkit.py +5 -0
  91. codegraphcontext/tools/query_tool_languages/python_toolkit.py +5 -0
  92. codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +5 -0
  93. codegraphcontext/tools/query_tool_languages/rust_toolkit.py +5 -0
  94. codegraphcontext/tools/query_tool_languages/scala_toolkit.py +5 -0
  95. codegraphcontext/tools/query_tool_languages/swift_toolkit.py +5 -0
  96. codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +5 -0
  97. codegraphcontext/tools/scip_indexer.py +467 -0
  98. codegraphcontext/tools/scip_pb2.py +2455 -0
  99. codegraphcontext/tools/system.py +133 -0
  100. codegraphcontext/tools/tree_sitter_parser.py +103 -0
  101. codegraphcontext/utils/debug_log.py +90 -0
  102. codegraphcontext/utils/path_ignore.py +55 -0
  103. codegraphcontext/utils/repo_path.py +27 -0
  104. codegraphcontext/utils/tree_sitter_manager.py +285 -0
  105. codegraphcontext/utils/visualize_graph.py +0 -0
  106. codegraphcontext/viz/server.py +282 -0
  107. codegraphcontext_rust-0.9.24.dist-info/METADATA +543 -0
  108. codegraphcontext_rust-0.9.24.dist-info/RECORD +112 -0
  109. codegraphcontext_rust-0.9.24.dist-info/WHEEL +4 -0
  110. codegraphcontext_rust-0.9.24.dist-info/entry_points.txt +4 -0
  111. codegraphcontext_rust-0.9.24.dist-info/licenses/LICENSE +21 -0
  112. codegraphcontext_rust-0.9.24.dist-info/sboms/cgc-python.cyclonedx.json +2302 -0
@@ -0,0 +1,606 @@
1
+ from pathlib import Path
2
+ from typing import Dict
3
+ from codegraphcontext.utils.debug_log import debug_log, info_logger, error_logger, warning_logger, debug_logger
4
+ from codegraphcontext.utils.tree_sitter_manager import execute_query
5
+
6
+ TS_QUERIES = {
7
+ "functions": """
8
+ (function_declaration
9
+ name: (identifier) @name
10
+ parameters: (formal_parameters) @params
11
+ ) @function_node
12
+
13
+ (variable_declarator
14
+ name: (identifier) @name
15
+ value: (function_expression
16
+ parameters: (formal_parameters) @params
17
+ ) @function_node
18
+ )
19
+
20
+ (variable_declarator
21
+ name: (identifier) @name
22
+ value: (arrow_function
23
+ parameters: (formal_parameters) @params
24
+ ) @function_node
25
+ )
26
+
27
+ (variable_declarator
28
+ name: (identifier) @name
29
+ value: (arrow_function
30
+ parameter: (identifier) @single_param
31
+ ) @function_node
32
+ )
33
+
34
+ (method_definition
35
+ name: (property_identifier) @name
36
+ parameters: (formal_parameters) @params
37
+ ) @function_node
38
+
39
+ (assignment_expression
40
+ left: (member_expression
41
+ property: (property_identifier) @name
42
+ )
43
+ right: (function_expression
44
+ parameters: (formal_parameters) @params
45
+ ) @function_node
46
+ )
47
+
48
+ (assignment_expression
49
+ left: (member_expression
50
+ property: (property_identifier) @name
51
+ )
52
+ right: (arrow_function
53
+ parameters: (formal_parameters) @params
54
+ ) @function_node
55
+ )
56
+ """,
57
+ "classes": """
58
+ (class_declaration) @class
59
+ (abstract_class_declaration) @class
60
+ (class) @class
61
+ """,
62
+ "interfaces": """
63
+ (interface_declaration
64
+ name: (type_identifier) @name
65
+ ) @interface_node
66
+ """,
67
+ "type_aliases": """
68
+ (type_alias_declaration
69
+ name: (type_identifier) @name
70
+ ) @type_alias_node
71
+ """,
72
+ "imports": """
73
+ (import_statement) @import
74
+ (call_expression
75
+ function: (identifier) @require_call (#eq? @require_call "require")
76
+ ) @import
77
+ """,
78
+ "calls": """
79
+ (call_expression function: (identifier) @name)
80
+ (call_expression function: (member_expression property: (property_identifier) @name))
81
+ (new_expression constructor: (identifier) @name)
82
+ (new_expression constructor: (member_expression property: (property_identifier) @name))
83
+ """,
84
+ "variables": """
85
+ (variable_declarator name: (identifier) @name)
86
+ """,
87
+ "docstrings": """
88
+ (comment) @docstring_comment
89
+ """,
90
+ }
91
+
92
+ def is_typescript_file(path: Path) -> bool:
93
+ return path.suffix in {".ts", ".tsx"}
94
+
95
+ class TypescriptTreeSitterParser:
96
+ """A TypeScript-specific parser using tree-sitter, encapsulating language-specific logic."""
97
+
98
+ def __init__(self, generic_parser_wrapper):
99
+ self.generic_parser_wrapper = generic_parser_wrapper
100
+ self.language_name = generic_parser_wrapper.language_name
101
+ self.language = generic_parser_wrapper.language
102
+ self.parser = generic_parser_wrapper.parser
103
+
104
+ def _get_node_text(self, node) -> str:
105
+ return node.text.decode('utf-8')
106
+
107
+ def _get_parent_context(self, node, types=('function_declaration', 'class_declaration', 'method_definition', 'function_expression', 'arrow_function')):
108
+ curr = node.parent
109
+ while curr:
110
+ if curr.type in types:
111
+ name_node = curr.child_by_field_name('name')
112
+ if not name_node and curr.type in ('function_expression', 'arrow_function'):
113
+ # Try to find name from variable declaration
114
+ if curr.parent and curr.parent.type == 'variable_declarator':
115
+ name_node = curr.parent.child_by_field_name('name')
116
+ elif curr.parent and curr.parent.type == 'assignment_expression':
117
+ name_node = curr.parent.child_by_field_name('left')
118
+ elif curr.parent and curr.parent.type == 'pair': # property: function
119
+ name_node = curr.parent.child_by_field_name('key')
120
+
121
+ return self._get_node_text(name_node) if name_node else None, curr.type, curr.start_point[0] + 1
122
+ curr = curr.parent
123
+ return None, None, None
124
+
125
+ def _calculate_complexity(self, node):
126
+ complexity_nodes = {
127
+ "if_statement", "for_statement", "while_statement", "do_statement",
128
+ "switch_statement", "case_statement", "conditional_expression",
129
+ "logical_expression", "binary_expression", "catch_clause"
130
+ }
131
+ count = 1
132
+ def traverse(n):
133
+ nonlocal count
134
+ if n.type in complexity_nodes:
135
+ count += 1
136
+ for child in n.children:
137
+ traverse(child)
138
+ traverse(node)
139
+ return count
140
+
141
+ def _get_docstring(self, body_node):
142
+ return None
143
+
144
+ def _get_jsdoc(self, node) -> str | None:
145
+ """Extract JSDoc /** ... */ comment immediately preceding node."""
146
+ parent = node.parent
147
+ if not parent:
148
+ return None
149
+ siblings = list(parent.children)
150
+ try:
151
+ idx = siblings.index(node)
152
+ except ValueError:
153
+ return None
154
+ for i in range(idx - 1, -1, -1):
155
+ sib = siblings[i]
156
+ if sib.type == "comment":
157
+ raw = self._get_node_text(sib)
158
+ if raw.startswith("/**"):
159
+ lines = []
160
+ for line in raw.splitlines():
161
+ line = line.strip().lstrip("/*").strip()
162
+ if line.startswith("@"):
163
+ break
164
+ if line:
165
+ lines.append(line)
166
+ result = " ".join(lines).strip()
167
+ return result[:500] if result else None
168
+ elif raw.startswith("//"):
169
+ return raw.lstrip("/").strip()[:500]
170
+ elif sib.type not in ("\n", "newline"):
171
+ break
172
+ return None
173
+
174
+ def parse(self, path: Path, is_dependency: bool = False, index_source: bool = False) -> Dict:
175
+ self.index_source = index_source
176
+ with open(path, "r", encoding="utf-8") as f:
177
+ source_code = f.read()
178
+ tree = self.parser.parse(bytes(source_code, "utf8"))
179
+ root_node = tree.root_node
180
+
181
+ functions = self._find_functions(root_node)
182
+ classes = self._find_classes(root_node)
183
+ interfaces = self._find_interfaces(root_node)
184
+ type_aliases = self._find_type_aliases(root_node)
185
+ imports = self._find_imports(root_node)
186
+ function_calls = self._find_calls(root_node)
187
+ variables = self._find_variables(root_node)
188
+
189
+ return {
190
+ "path": str(path),
191
+ "functions": functions,
192
+ "classes": classes,
193
+ "interfaces": interfaces,
194
+ "type_aliases": type_aliases,
195
+ "variables": variables,
196
+ "imports": imports,
197
+ "function_calls": function_calls,
198
+ "is_dependency": is_dependency,
199
+ "lang": self.language_name,
200
+ }
201
+
202
+
203
+ def _find_functions(self, root_node):
204
+ functions = []
205
+ query_str = TS_QUERIES['functions']
206
+ def _fn_for_name(name_node):
207
+ current = name_node.parent
208
+ while current:
209
+ if current.type in ('function_declaration', 'function', 'arrow_function', 'method_definition'):
210
+ return current
211
+ elif current.type in ('variable_declarator', 'assignment_expression'):
212
+ for child in current.children:
213
+ if child.type in ('function', 'arrow_function'):
214
+ return child
215
+ current = current.parent
216
+ return None
217
+ def _fn_for_params(params_node):
218
+ current = params_node.parent
219
+ while current:
220
+ if current.type in ('function_declaration', 'function', 'arrow_function', 'method_definition'):
221
+ return current
222
+ current = current.parent
223
+ return None
224
+ def _key(n):
225
+ return (n.start_byte, n.end_byte, n.type)
226
+ captures_by_function = {}
227
+ def _bucket_for(node):
228
+ fid = _key(node)
229
+ return captures_by_function.setdefault(fid, {
230
+ 'node': node, 'name': None, 'params': None, 'single_param': None
231
+ })
232
+ for node, capture_name in execute_query(self.language, query_str, root_node):
233
+ if capture_name == 'function_node':
234
+ _bucket_for(node)
235
+ elif capture_name == 'name':
236
+ fn = _fn_for_name(node)
237
+ if fn:
238
+ b = _bucket_for(fn)
239
+ b['name'] = self._get_node_text(node)
240
+ elif capture_name == 'params':
241
+ fn = _fn_for_params(node)
242
+ if fn:
243
+ b = _bucket_for(fn)
244
+ b['params'] = node
245
+ elif capture_name == 'single_param':
246
+ fn = _fn_for_params(node)
247
+ if fn:
248
+ b = _bucket_for(fn)
249
+ b['single_param'] = node
250
+ for _, data in captures_by_function.items():
251
+ func_node = data['node']
252
+ name = data.get('name')
253
+ if not name and func_node.type == 'method_definition':
254
+ nm = func_node.child_by_field_name('name')
255
+ if nm:
256
+ name = self._get_node_text(nm)
257
+ if not name:
258
+ continue
259
+ args = []
260
+ if data.get('params'):
261
+ args = self._extract_parameters(data['params'])
262
+ elif data.get('single_param'):
263
+ args = [self._get_node_text(data['single_param'])]
264
+ context, context_type, _ = self._get_parent_context(func_node)
265
+ class_context = context if context_type == 'class_declaration' else None
266
+ func_data = {
267
+ "name": name,
268
+ "line_number": func_node.start_point[0] + 1,
269
+ "end_line": func_node.end_point[0] + 1,
270
+ "args": args,
271
+ "cyclomatic_complexity": self._calculate_complexity(func_node),
272
+ "context": context,
273
+ "context_type": context_type,
274
+ "class_context": class_context,
275
+ "decorators": [],
276
+ "lang": self.language_name,
277
+ "is_dependency": False,
278
+ # Always extract JSDoc (lightweight, no index_source needed)
279
+ "docstring": self._get_jsdoc(func_node),
280
+ }
281
+
282
+ if self.index_source:
283
+ func_data["source"] = self._get_node_text(func_node)
284
+ functions.append(func_data)
285
+ return functions
286
+
287
+ def _extract_parameters(self, params_node):
288
+ params = []
289
+ if params_node.type == 'formal_parameters':
290
+ for child in params_node.children:
291
+ if child.type == 'identifier':
292
+ params.append(self._get_node_text(child))
293
+ elif child.type == 'required_parameter':
294
+ # required_parameter -> pattern (identifier) + type_annotation
295
+ pattern = child.child_by_field_name('pattern')
296
+ if pattern:
297
+ params.append(self._get_node_text(pattern))
298
+ else:
299
+ # Fallback: first child that is an identifier or pattern
300
+ for sub in child.children:
301
+ if sub.type in ('identifier', 'object_pattern', 'array_pattern'):
302
+ params.append(self._get_node_text(sub))
303
+ break
304
+ elif child.type == 'optional_parameter':
305
+ pattern = child.child_by_field_name('pattern')
306
+ if pattern:
307
+ params.append(self._get_node_text(pattern))
308
+ elif child.type == 'assignment_pattern':
309
+ left_child = child.child_by_field_name('left')
310
+ if left_child and left_child.type == 'identifier':
311
+ params.append(self._get_node_text(left_child))
312
+ elif child.type == 'rest_pattern':
313
+ argument = child.child_by_field_name('argument')
314
+ if argument and argument.type == 'identifier':
315
+ params.append(f"...{self._get_node_text(argument)}")
316
+ return params
317
+
318
+ def _find_classes(self, root_node):
319
+ classes = []
320
+ query_str = TS_QUERIES['classes']
321
+ for class_node, capture_name in execute_query(self.language, query_str, root_node):
322
+ if capture_name == 'class':
323
+ name_node = class_node.child_by_field_name('name')
324
+ if not name_node: continue
325
+ name = self._get_node_text(name_node)
326
+ bases = []
327
+ heritage_node = next((child for child in class_node.children if child.type == 'class_heritage'), None)
328
+ if heritage_node:
329
+ for child in heritage_node.children:
330
+ if child.type == 'extends_clause':
331
+ # extends_clause -> extends identifier
332
+ for sub in child.children:
333
+ if sub.type in ('identifier', 'type_identifier', 'member_expression'):
334
+ bases.append(self._get_node_text(sub))
335
+ elif child.type == 'implements_clause':
336
+ # implements_clause -> implements identifier, identifier...
337
+ for sub in child.children:
338
+ if sub.type in ('identifier', 'type_identifier', 'member_expression'):
339
+ bases.append(self._get_node_text(sub))
340
+ class_data = {
341
+ "name": name,
342
+ "line_number": class_node.start_point[0] + 1,
343
+ "end_line": class_node.end_point[0] + 1,
344
+ "bases": bases,
345
+ "context": None,
346
+ "decorators": [],
347
+ "lang": self.language_name,
348
+ "is_dependency": False,
349
+ }
350
+ # Always extract JSDoc (lightweight, no index_source needed)
351
+ class_data["docstring"] = self._get_jsdoc(class_node)
352
+ if self.index_source:
353
+ class_data["source"] = self._get_node_text(class_node)
354
+ classes.append(class_data)
355
+ return classes
356
+
357
+ def _find_interfaces(self, root_node):
358
+ interfaces = []
359
+ query_str = TS_QUERIES['interfaces']
360
+ for node, capture_name in execute_query(self.language, query_str, root_node):
361
+ if capture_name == 'interface_node':
362
+ name_node = node.child_by_field_name('name')
363
+ if not name_node: continue
364
+
365
+ name = self._get_node_text(name_node)
366
+ interface_data = {
367
+ "name": name,
368
+ "line_number": node.start_point[0] + 1,
369
+ "end_line": node.end_point[0] + 1,
370
+ "end_line": node.end_point[0] + 1,
371
+ }
372
+ if self.index_source:
373
+ interface_data["source"] = self._get_node_text(node)
374
+ interfaces.append(interface_data)
375
+ return interfaces
376
+
377
+ def _find_type_aliases(self, root_node):
378
+ type_aliases = []
379
+ query_str = TS_QUERIES['type_aliases']
380
+ for node, capture_name in execute_query(self.language, query_str, root_node):
381
+ if capture_name == 'type_alias_node':
382
+ name_node = node.child_by_field_name('name')
383
+ if not name_node: continue
384
+
385
+ name = self._get_node_text(name_node)
386
+ type_alias_data = {
387
+ "name": name,
388
+ "line_number": node.start_point[0] + 1,
389
+ "end_line": node.end_point[0] + 1,
390
+ "end_line": node.end_point[0] + 1,
391
+ }
392
+ if self.index_source:
393
+ type_alias_data["source"] = self._get_node_text(node)
394
+ type_aliases.append(type_alias_data)
395
+ return type_aliases
396
+
397
+ def _find_imports(self, root_node):
398
+ imports = []
399
+ query_str = TS_QUERIES['imports']
400
+ for node, capture_name in execute_query(self.language, query_str, root_node):
401
+ if capture_name != 'import':
402
+ continue
403
+ line_number = node.start_point[0] + 1
404
+ if node.type == 'import_statement':
405
+ source = self._get_node_text(node.child_by_field_name('source')).strip('\'"')
406
+ import_clause = node.child_by_field_name('import')
407
+ if not import_clause:
408
+ imports.append({'name': source, 'source': source, 'alias': None, 'line_number': line_number,
409
+ 'lang': self.language_name})
410
+ continue
411
+ if import_clause.type == 'identifier':
412
+ alias = self._get_node_text(import_clause)
413
+ imports.append({'name': 'default', 'source': source, 'alias': alias, 'line_number': line_number,
414
+ 'lang': self.language_name})
415
+ elif import_clause.type == 'namespace_import':
416
+ alias_node = import_clause.child_by_field_name('alias')
417
+ if alias_node:
418
+ alias = self._get_node_text(alias_node)
419
+ imports.append({'name': '*', 'source': source, 'alias': alias, 'line_number': line_number,
420
+ 'lang': self.language_name})
421
+ elif import_clause.type == 'named_imports':
422
+ for specifier in import_clause.children:
423
+ if specifier.type == 'import_specifier':
424
+ name_node = specifier.child_by_field_name('name')
425
+ alias_node = specifier.child_by_field_name('alias')
426
+ original_name = self._get_node_text(name_node)
427
+ alias = self._get_node_text(alias_node) if alias_node else None
428
+ imports.append(
429
+ {'name': original_name, 'source': source, 'alias': alias, 'line_number': line_number,
430
+ 'lang': self.language_name})
431
+ elif node.type == 'call_expression':
432
+ args = node.child_by_field_name('arguments')
433
+ if not args or args.named_child_count == 0: continue
434
+ source_node = args.named_child(0)
435
+ if not source_node or source_node.type != 'string': continue
436
+ source = self._get_node_text(source_node).strip('\'"')
437
+ alias = None
438
+ if node.parent.type == 'variable_declarator':
439
+ alias_node = node.parent.child_by_field_name('name')
440
+ if alias_node:
441
+ alias = self._get_node_text(alias_node)
442
+ imports.append({'name': source, 'source': source, 'alias': alias, 'line_number': line_number,
443
+ 'lang': self.language_name})
444
+ return imports
445
+
446
+ def _find_calls(self, root_node):
447
+ calls = []
448
+ query_str = TS_QUERIES['calls']
449
+ for node, capture_name in execute_query(self.language, query_str, root_node):
450
+ if capture_name == 'name':
451
+ # Traverse up to find the call/new expression
452
+ call_node = node.parent
453
+ while call_node and call_node.type not in ('call_expression', 'new_expression') and call_node.type != 'program':
454
+ call_node = call_node.parent
455
+
456
+ name = self._get_node_text(node)
457
+
458
+ # Improved args extraction
459
+ args = []
460
+ arguments_node = None
461
+ if call_node and call_node.type in ('call_expression', 'new_expression'):
462
+ arguments_node = call_node.child_by_field_name('arguments')
463
+
464
+ if arguments_node:
465
+ for arg in arguments_node.children:
466
+ if arg.type not in ('(', ')', ','):
467
+ args.append(self._get_node_text(arg))
468
+
469
+ call_data = {
470
+ "name": name,
471
+ "full_name": self._get_node_text(call_node) if call_node else name,
472
+ "line_number": node.start_point[0] + 1,
473
+ "args": args,
474
+ "inferred_obj_type": None,
475
+ "context": self._get_parent_context(node),
476
+ "class_context": self._get_parent_context(node, types=('class_declaration', 'abstract_class_declaration')),
477
+ "lang": self.language_name,
478
+ "is_dependency": False,
479
+ }
480
+ calls.append(call_data)
481
+ return calls
482
+
483
+ def _find_variables(self, root_node):
484
+ variables = []
485
+ query_str = TS_QUERIES['variables']
486
+ for match in execute_query(self.language, query_str, root_node):
487
+ capture_name = match[1]
488
+ node = match[0]
489
+ if capture_name == 'name':
490
+ var_node = node.parent
491
+ name = self._get_node_text(node)
492
+ value = None
493
+ type_text = None
494
+
495
+ # Detect if variable assigned to a function
496
+ value_node = var_node.child_by_field_name("value") if var_node else None
497
+
498
+ if value_node:
499
+ value_type = value_node.type
500
+
501
+ # --- Skip variables that are assigned a function ---
502
+ if value_type in ("function_expression", "arrow_function"):
503
+ continue
504
+
505
+ if "function" in value_type or "arrow" in value_type:
506
+ continue
507
+
508
+ # --- Handle various assignment types ---
509
+ if value_type == "call_expression":
510
+ func_node = value_node.child_by_field_name("function")
511
+ value = self._get_node_text(func_node) if func_node else name
512
+ else:
513
+ value = self._get_node_text(value_node)
514
+
515
+ context, context_type, context_line = self._get_parent_context(node)
516
+ class_context = context if context_type == 'class_declaration' else None
517
+
518
+ variable_data = {
519
+ "name": name,
520
+ "line_number": node.start_point[0] + 1,
521
+ "value": value,
522
+ "type": type_text,
523
+ "context": context,
524
+ "class_context": class_context,
525
+ "lang": self.language_name,
526
+ "is_dependency": False,
527
+ }
528
+ variables.append(variable_data)
529
+ return variables
530
+
531
+ def pre_scan_typescript(files: list[Path], parser_wrapper) -> dict:
532
+ """Scans TypeScript files to create a map of class/function names to their file paths."""
533
+ imports_map = {}
534
+
535
+ # Simplified queries that capture the parent nodes, then extract names manually
536
+ query_strings = [
537
+ "(class_declaration) @class",
538
+ "(function_declaration) @function",
539
+ "(variable_declarator) @var_decl",
540
+ "(method_definition) @method",
541
+ "(interface_declaration) @interface",
542
+ "(type_alias_declaration) @type_alias",
543
+ ]
544
+
545
+ for path in files:
546
+ try:
547
+ with open(path, "r", encoding="utf-8") as f:
548
+ source_code = f.read()
549
+ tree = parser_wrapper.parser.parse(bytes(source_code, "utf8"))
550
+
551
+ # Run each query separately
552
+ for query_str in query_strings:
553
+ try:
554
+
555
+ for node, capture_name in execute_query(parser_wrapper.language, query_str, tree.root_node):
556
+ name = None
557
+
558
+ # Extract name based on node type
559
+ if capture_name == 'class':
560
+ name_node = node.child_by_field_name('name')
561
+ if name_node:
562
+ name = name_node.text.decode('utf-8')
563
+
564
+ elif capture_name == 'function':
565
+ name_node = node.child_by_field_name('name')
566
+ if name_node:
567
+ name = name_node.text.decode('utf-8')
568
+
569
+ elif capture_name == 'var_decl':
570
+ # Check if it's a function or arrow function
571
+ name_node = node.child_by_field_name('name')
572
+ value_node = node.child_by_field_name('value')
573
+ if name_node and value_node:
574
+ if value_node.type in ('function', 'arrow_function'):
575
+ name = name_node.text.decode('utf-8')
576
+
577
+ elif capture_name == 'method':
578
+ name_node = node.child_by_field_name('name')
579
+ if name_node:
580
+ name = name_node.text.decode('utf-8')
581
+
582
+ elif capture_name == 'interface':
583
+ name_node = node.child_by_field_name('name')
584
+ if name_node:
585
+ name = name_node.text.decode('utf-8')
586
+
587
+ elif capture_name == 'type_alias':
588
+ name_node = node.child_by_field_name('name')
589
+ if name_node:
590
+ name = name_node.text.decode('utf-8')
591
+
592
+ # Add to imports map if we found a name
593
+ if name:
594
+ if name not in imports_map:
595
+ imports_map[name] = []
596
+ file_path_str = str(path.resolve())
597
+ if file_path_str not in imports_map[name]:
598
+ imports_map[name].append(file_path_str)
599
+
600
+ except Exception as query_error:
601
+ warning_logger(f"Query failed for pattern '{query_str}': {query_error}")
602
+
603
+ except Exception as e:
604
+ warning_logger(f"Tree-sitter pre-scan failed for {path}: {e}")
605
+
606
+ return imports_map