mulle-roam-code 0.0.1__py3-none-any.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 (257) hide show
  1. mulle_roam_code-0.0.1.dist-info/METADATA +1590 -0
  2. mulle_roam_code-0.0.1.dist-info/RECORD +257 -0
  3. mulle_roam_code-0.0.1.dist-info/WHEEL +5 -0
  4. mulle_roam_code-0.0.1.dist-info/entry_points.txt +3 -0
  5. mulle_roam_code-0.0.1.dist-info/licenses/LICENSE +21 -0
  6. mulle_roam_code-0.0.1.dist-info/top_level.txt +1 -0
  7. roam/__init__.py +8 -0
  8. roam/__main__.py +5 -0
  9. roam/analysis/__init__.py +1 -0
  10. roam/analysis/effects.py +639 -0
  11. roam/analysis/taint.py +689 -0
  12. roam/api.py +238 -0
  13. roam/bridges/__init__.py +3 -0
  14. roam/bridges/base.py +49 -0
  15. roam/bridges/bridge_config.py +218 -0
  16. roam/bridges/bridge_protobuf.py +352 -0
  17. roam/bridges/bridge_rest_api.py +242 -0
  18. roam/bridges/bridge_salesforce.py +198 -0
  19. roam/bridges/bridge_template.py +247 -0
  20. roam/bridges/registry.py +51 -0
  21. roam/catalog/__init__.py +0 -0
  22. roam/catalog/detectors.py +2242 -0
  23. roam/catalog/fixes.py +86 -0
  24. roam/catalog/smells.py +599 -0
  25. roam/catalog/tasks.py +1260 -0
  26. roam/cli.py +548 -0
  27. roam/commands/__init__.py +0 -0
  28. roam/commands/changed_files.py +139 -0
  29. roam/commands/cmd_adversarial.py +699 -0
  30. roam/commands/cmd_affected.py +432 -0
  31. roam/commands/cmd_affected_tests.py +375 -0
  32. roam/commands/cmd_agent_context.py +168 -0
  33. roam/commands/cmd_agent_export.py +890 -0
  34. roam/commands/cmd_agent_plan.py +315 -0
  35. roam/commands/cmd_ai_ratio.py +765 -0
  36. roam/commands/cmd_ai_readiness.py +775 -0
  37. roam/commands/cmd_alerts.py +409 -0
  38. roam/commands/cmd_annotate.py +210 -0
  39. roam/commands/cmd_api_changes.py +796 -0
  40. roam/commands/cmd_api_drift.py +781 -0
  41. roam/commands/cmd_attest.py +913 -0
  42. roam/commands/cmd_auth_gaps.py +799 -0
  43. roam/commands/cmd_bisect.py +216 -0
  44. roam/commands/cmd_breaking.py +464 -0
  45. roam/commands/cmd_budget.py +413 -0
  46. roam/commands/cmd_bus_factor.py +403 -0
  47. roam/commands/cmd_capsule.py +275 -0
  48. roam/commands/cmd_check_rules.py +574 -0
  49. roam/commands/cmd_clean.py +147 -0
  50. roam/commands/cmd_closure.py +294 -0
  51. roam/commands/cmd_clusters.py +457 -0
  52. roam/commands/cmd_codeowners.py +600 -0
  53. roam/commands/cmd_complexity.py +364 -0
  54. roam/commands/cmd_config.py +310 -0
  55. roam/commands/cmd_context.py +1151 -0
  56. roam/commands/cmd_conventions.py +697 -0
  57. roam/commands/cmd_coupling.py +462 -0
  58. roam/commands/cmd_coverage_gaps.py +638 -0
  59. roam/commands/cmd_cut.py +235 -0
  60. roam/commands/cmd_dark_matter.py +127 -0
  61. roam/commands/cmd_dashboard.py +365 -0
  62. roam/commands/cmd_dead.py +1585 -0
  63. roam/commands/cmd_debt.py +731 -0
  64. roam/commands/cmd_deps.py +121 -0
  65. roam/commands/cmd_describe.py +959 -0
  66. roam/commands/cmd_dev_profile.py +580 -0
  67. roam/commands/cmd_diagnose.py +377 -0
  68. roam/commands/cmd_diff.py +633 -0
  69. roam/commands/cmd_digest.py +214 -0
  70. roam/commands/cmd_doc_staleness.py +334 -0
  71. roam/commands/cmd_docs_coverage.py +193 -0
  72. roam/commands/cmd_doctor.py +319 -0
  73. roam/commands/cmd_drift.py +377 -0
  74. roam/commands/cmd_duplicates.py +559 -0
  75. roam/commands/cmd_effects.py +362 -0
  76. roam/commands/cmd_endpoints.py +768 -0
  77. roam/commands/cmd_entry_points.py +358 -0
  78. roam/commands/cmd_fan.py +311 -0
  79. roam/commands/cmd_file.py +334 -0
  80. roam/commands/cmd_fingerprint.py +172 -0
  81. roam/commands/cmd_fitness.py +723 -0
  82. roam/commands/cmd_fn_coupling.py +295 -0
  83. roam/commands/cmd_forecast.py +366 -0
  84. roam/commands/cmd_grep.py +282 -0
  85. roam/commands/cmd_guard.py +434 -0
  86. roam/commands/cmd_health.py +922 -0
  87. roam/commands/cmd_hooks.py +458 -0
  88. roam/commands/cmd_hotspots.py +606 -0
  89. roam/commands/cmd_impact.py +228 -0
  90. roam/commands/cmd_index.py +102 -0
  91. roam/commands/cmd_ingest_trace.py +143 -0
  92. roam/commands/cmd_init.py +166 -0
  93. roam/commands/cmd_intent.py +459 -0
  94. roam/commands/cmd_invariants.py +301 -0
  95. roam/commands/cmd_layers.py +387 -0
  96. roam/commands/cmd_map.py +275 -0
  97. roam/commands/cmd_math.py +213 -0
  98. roam/commands/cmd_mcp_setup.py +135 -0
  99. roam/commands/cmd_metrics.py +663 -0
  100. roam/commands/cmd_migration_safety.py +712 -0
  101. roam/commands/cmd_minimap.py +519 -0
  102. roam/commands/cmd_missing_index.py +885 -0
  103. roam/commands/cmd_module.py +204 -0
  104. roam/commands/cmd_mutate.py +400 -0
  105. roam/commands/cmd_n1.py +967 -0
  106. roam/commands/cmd_onboard.py +740 -0
  107. roam/commands/cmd_orchestrate.py +180 -0
  108. roam/commands/cmd_orphan_routes.py +754 -0
  109. roam/commands/cmd_over_fetch.py +633 -0
  110. roam/commands/cmd_owner.py +299 -0
  111. roam/commands/cmd_partition.py +714 -0
  112. roam/commands/cmd_path_coverage.py +564 -0
  113. roam/commands/cmd_patterns.py +689 -0
  114. roam/commands/cmd_plan.py +616 -0
  115. roam/commands/cmd_plan_refactor.py +432 -0
  116. roam/commands/cmd_pr_diff.py +292 -0
  117. roam/commands/cmd_pr_risk.py +677 -0
  118. roam/commands/cmd_preflight.py +706 -0
  119. roam/commands/cmd_relate.py +405 -0
  120. roam/commands/cmd_report.py +304 -0
  121. roam/commands/cmd_reset.py +117 -0
  122. roam/commands/cmd_risk.py +533 -0
  123. roam/commands/cmd_rules.py +319 -0
  124. roam/commands/cmd_safe_delete.py +224 -0
  125. roam/commands/cmd_safe_zones.py +295 -0
  126. roam/commands/cmd_schema.py +166 -0
  127. roam/commands/cmd_search.py +295 -0
  128. roam/commands/cmd_search_semantic.py +101 -0
  129. roam/commands/cmd_secrets.py +636 -0
  130. roam/commands/cmd_semantic_diff.py +538 -0
  131. roam/commands/cmd_simulate.py +296 -0
  132. roam/commands/cmd_simulate_departure.py +632 -0
  133. roam/commands/cmd_sketch.py +160 -0
  134. roam/commands/cmd_smells.py +179 -0
  135. roam/commands/cmd_snapshot.py +50 -0
  136. roam/commands/cmd_spectral.py +183 -0
  137. roam/commands/cmd_split.py +432 -0
  138. roam/commands/cmd_suggest_refactoring.py +486 -0
  139. roam/commands/cmd_suggest_reviewers.py +491 -0
  140. roam/commands/cmd_supply_chain.py +831 -0
  141. roam/commands/cmd_symbol.py +135 -0
  142. roam/commands/cmd_syntax_check.py +301 -0
  143. roam/commands/cmd_test_gaps.py +574 -0
  144. roam/commands/cmd_testmap.py +308 -0
  145. roam/commands/cmd_tour.py +377 -0
  146. roam/commands/cmd_trace.py +304 -0
  147. roam/commands/cmd_trend.py +461 -0
  148. roam/commands/cmd_trends.py +929 -0
  149. roam/commands/cmd_understand.py +763 -0
  150. roam/commands/cmd_uses.py +170 -0
  151. roam/commands/cmd_verify.py +812 -0
  152. roam/commands/cmd_verify_imports.py +435 -0
  153. roam/commands/cmd_vibe_check.py +932 -0
  154. roam/commands/cmd_visualize.py +361 -0
  155. roam/commands/cmd_vuln_map.py +139 -0
  156. roam/commands/cmd_vuln_reach.py +289 -0
  157. roam/commands/cmd_vulns.py +414 -0
  158. roam/commands/cmd_watch.py +759 -0
  159. roam/commands/cmd_weather.py +118 -0
  160. roam/commands/cmd_why.py +325 -0
  161. roam/commands/cmd_ws.py +755 -0
  162. roam/commands/cmd_xlang.py +170 -0
  163. roam/commands/context_helpers.py +1137 -0
  164. roam/commands/gate_presets.py +222 -0
  165. roam/commands/graph_helpers.py +93 -0
  166. roam/commands/metrics_history.py +298 -0
  167. roam/commands/next_steps.py +107 -0
  168. roam/commands/resolve.py +302 -0
  169. roam/competitor_site_data.py +2229 -0
  170. roam/coverage_reports.py +462 -0
  171. roam/db/__init__.py +0 -0
  172. roam/db/connection.py +359 -0
  173. roam/db/queries.py +151 -0
  174. roam/db/schema.py +335 -0
  175. roam/exit_codes.py +100 -0
  176. roam/graph/__init__.py +43 -0
  177. roam/graph/anomaly.py +493 -0
  178. roam/graph/builder.py +61 -0
  179. roam/graph/clusters.py +286 -0
  180. roam/graph/cycles.py +210 -0
  181. roam/graph/dark_matter.py +207 -0
  182. roam/graph/diff.py +467 -0
  183. roam/graph/fingerprint.py +297 -0
  184. roam/graph/layers.py +134 -0
  185. roam/graph/pagerank.py +171 -0
  186. roam/graph/partition.py +437 -0
  187. roam/graph/pathfinding.py +119 -0
  188. roam/graph/propagation.py +208 -0
  189. roam/graph/simulate.py +286 -0
  190. roam/graph/spectral.py +260 -0
  191. roam/index/__init__.py +5 -0
  192. roam/index/complexity.py +1108 -0
  193. roam/index/discovery.py +338 -0
  194. roam/index/file_roles.py +586 -0
  195. roam/index/git_stats.py +577 -0
  196. roam/index/incremental.py +75 -0
  197. roam/index/indexer.py +1191 -0
  198. roam/index/parser.py +461 -0
  199. roam/index/relations.py +537 -0
  200. roam/index/symbols.py +71 -0
  201. roam/index/test_conventions.py +508 -0
  202. roam/languages/__init__.py +21 -0
  203. roam/languages/apex_lang.py +241 -0
  204. roam/languages/aura_lang.py +228 -0
  205. roam/languages/base.py +111 -0
  206. roam/languages/c_lang.py +458 -0
  207. roam/languages/csharp_lang.py +1215 -0
  208. roam/languages/foxpro_lang.py +1554 -0
  209. roam/languages/generic_lang.py +702 -0
  210. roam/languages/go_lang.py +392 -0
  211. roam/languages/hcl_lang.py +398 -0
  212. roam/languages/java_lang.py +418 -0
  213. roam/languages/javascript_lang.py +799 -0
  214. roam/languages/kotlin_lang.py +147 -0
  215. roam/languages/objc_lang.py +401 -0
  216. roam/languages/php_lang.py +696 -0
  217. roam/languages/python_lang.py +850 -0
  218. roam/languages/registry.py +283 -0
  219. roam/languages/ruby_lang.py +429 -0
  220. roam/languages/rust_lang.py +545 -0
  221. roam/languages/sfxml_lang.py +276 -0
  222. roam/languages/swift_lang.py +173 -0
  223. roam/languages/typescript_lang.py +323 -0
  224. roam/languages/visualforce_lang.py +151 -0
  225. roam/languages/yaml_lang.py +566 -0
  226. roam/mcp_server.py +4794 -0
  227. roam/output/__init__.py +0 -0
  228. roam/output/formatter.py +557 -0
  229. roam/output/mermaid.py +62 -0
  230. roam/output/sarif.py +897 -0
  231. roam/output/schema_registry.py +57 -0
  232. roam/plugins.py +208 -0
  233. roam/refactor/__init__.py +0 -0
  234. roam/refactor/codegen.py +106 -0
  235. roam/refactor/transforms.py +711 -0
  236. roam/rules/__init__.py +0 -0
  237. roam/rules/ast_match.py +238 -0
  238. roam/rules/builtin.py +617 -0
  239. roam/rules/dataflow.py +515 -0
  240. roam/rules/engine.py +943 -0
  241. roam/runtime/__init__.py +3 -0
  242. roam/runtime/hotspots.py +138 -0
  243. roam/runtime/trace_ingest.py +535 -0
  244. roam/search/__init__.py +1 -0
  245. roam/search/framework_packs.py +673 -0
  246. roam/search/index_embeddings.py +732 -0
  247. roam/search/onnx_embeddings.py +233 -0
  248. roam/search/tfidf.py +355 -0
  249. roam/security/__init__.py +1 -0
  250. roam/security/vuln_reach.py +246 -0
  251. roam/security/vuln_store.py +334 -0
  252. roam/surface_counts.py +158 -0
  253. roam/workspace/__init__.py +3 -0
  254. roam/workspace/aggregator.py +426 -0
  255. roam/workspace/api_scanner.py +538 -0
  256. roam/workspace/config.py +95 -0
  257. roam/workspace/db.py +136 -0
@@ -0,0 +1,545 @@
1
+ from __future__ import annotations
2
+
3
+ from .base import LanguageExtractor
4
+
5
+
6
+ class RustExtractor(LanguageExtractor):
7
+ """Rust symbol and reference extractor."""
8
+
9
+ @property
10
+ def language_name(self) -> str:
11
+ return "rust"
12
+
13
+ @property
14
+ def file_extensions(self) -> list[str]:
15
+ return [".rs"]
16
+
17
+ def extract_symbols(self, tree, source: bytes, file_path: str) -> list[dict]:
18
+ symbols = []
19
+ self._walk_symbols(tree.root_node, source, symbols, parent_name=None)
20
+ return symbols
21
+
22
+ def extract_references(self, tree, source: bytes, file_path: str) -> list[dict]:
23
+ refs = []
24
+ self._walk_refs(tree.root_node, source, refs, scope_name=None)
25
+ return refs
26
+
27
+ def get_docstring(self, node, source: bytes) -> str | None:
28
+ """Rust doc comments: /// or //! lines before node."""
29
+ prev = node.prev_sibling
30
+ comments = []
31
+ while prev and prev.type in ("line_comment", "block_comment"):
32
+ text = self.node_text(prev, source).strip()
33
+ if text.startswith("///") or text.startswith("//!"):
34
+ text = text[3:].strip()
35
+ comments.insert(0, text)
36
+ elif text.startswith("/**"):
37
+ text = text[3:]
38
+ if text.endswith("*/"):
39
+ text = text[:-2]
40
+ comments.insert(0, text.strip())
41
+ else:
42
+ break
43
+ prev = prev.prev_sibling
44
+ return "\n".join(comments) if comments else None
45
+
46
+ def _visibility(self, node, source) -> str:
47
+ """Check for pub visibility modifier."""
48
+ for child in node.children:
49
+ if child.type == "visibility_modifier":
50
+ text = self.node_text(child, source)
51
+ if "crate" in text:
52
+ return "public"
53
+ if "super" in text:
54
+ return "private"
55
+ return "public"
56
+ return "private"
57
+
58
+ def _is_pub(self, node, source) -> bool:
59
+ return self._visibility(node, source) == "public"
60
+
61
+ # ---- Symbol extraction ----
62
+
63
+ def _walk_symbols(self, node, source, symbols, parent_name):
64
+ for child in node.children:
65
+ if child.type == "function_item":
66
+ self._extract_function(child, source, symbols, parent_name)
67
+ elif child.type == "struct_item":
68
+ self._extract_struct(child, source, symbols, parent_name)
69
+ elif child.type == "enum_item":
70
+ self._extract_enum(child, source, symbols, parent_name)
71
+ elif child.type == "trait_item":
72
+ self._extract_trait(child, source, symbols, parent_name)
73
+ elif child.type == "impl_item":
74
+ self._extract_impl(child, source, symbols, parent_name)
75
+ elif child.type == "mod_item":
76
+ self._extract_mod(child, source, symbols, parent_name)
77
+ elif child.type == "type_item":
78
+ self._extract_type_alias(child, source, symbols, parent_name)
79
+ elif child.type == "const_item":
80
+ self._extract_const(child, source, symbols, parent_name)
81
+ elif child.type == "static_item":
82
+ self._extract_static(child, source, symbols, parent_name)
83
+ elif child.type == "macro_definition":
84
+ self._extract_macro(child, source, symbols, parent_name)
85
+
86
+ def _extract_function(self, node, source, symbols, parent_name, kind="function"):
87
+ name_node = node.child_by_field_name("name")
88
+ if name_node is None:
89
+ return
90
+ name = self.node_text(name_node, source)
91
+ params = node.child_by_field_name("parameters")
92
+ sig = f"fn {name}({self.node_text(params, source) if params else ''})"
93
+
94
+ # Type parameters
95
+ type_params = node.child_by_field_name("type_parameters")
96
+ if type_params:
97
+ sig = f"fn {name}{self.node_text(type_params, source)}({self.node_text(params, source) if params else ''})"
98
+
99
+ # Return type
100
+ ret = node.child_by_field_name("return_type")
101
+ if ret:
102
+ sig += f" -> {self.node_text(ret, source)}"
103
+
104
+ vis = self._visibility(node, source)
105
+ if vis == "public":
106
+ sig = f"pub {sig}"
107
+
108
+ qualified = f"{parent_name}::{name}" if parent_name else name
109
+ symbols.append(
110
+ self._make_symbol(
111
+ name=name,
112
+ kind=kind,
113
+ line_start=node.start_point[0] + 1,
114
+ line_end=node.end_point[0] + 1,
115
+ qualified_name=qualified,
116
+ signature=sig,
117
+ docstring=self.get_docstring(node, source),
118
+ visibility=vis,
119
+ is_exported=self._is_pub(node, source),
120
+ parent_name=parent_name,
121
+ )
122
+ )
123
+
124
+ def _extract_struct(self, node, source, symbols, parent_name):
125
+ name_node = node.child_by_field_name("name")
126
+ if name_node is None:
127
+ return
128
+ name = self.node_text(name_node, source)
129
+ vis = self._visibility(node, source)
130
+ sig = f"{'pub ' if vis == 'public' else ''}struct {name}"
131
+
132
+ type_params = node.child_by_field_name("type_parameters")
133
+ if type_params:
134
+ sig += self.node_text(type_params, source)
135
+
136
+ qualified = f"{parent_name}::{name}" if parent_name else name
137
+ symbols.append(
138
+ self._make_symbol(
139
+ name=name,
140
+ kind="struct",
141
+ line_start=node.start_point[0] + 1,
142
+ line_end=node.end_point[0] + 1,
143
+ qualified_name=qualified,
144
+ signature=sig,
145
+ docstring=self.get_docstring(node, source),
146
+ visibility=vis,
147
+ is_exported=vis == "public",
148
+ parent_name=parent_name,
149
+ )
150
+ )
151
+
152
+ # Extract struct fields
153
+ body = node.child_by_field_name("body")
154
+ if body:
155
+ for child in body.children:
156
+ if child.type == "field_declaration":
157
+ fn = child.child_by_field_name("name")
158
+ if fn:
159
+ field_name = self.node_text(fn, source)
160
+ ftype = child.child_by_field_name("type")
161
+ fsig = field_name
162
+ if ftype:
163
+ fsig += f": {self.node_text(ftype, source)}"
164
+ fvis = self._visibility(child, source)
165
+ symbols.append(
166
+ self._make_symbol(
167
+ name=field_name,
168
+ kind="field",
169
+ line_start=child.start_point[0] + 1,
170
+ line_end=child.end_point[0] + 1,
171
+ qualified_name=f"{qualified}::{field_name}",
172
+ signature=fsig,
173
+ visibility=fvis,
174
+ is_exported=fvis == "public",
175
+ parent_name=qualified,
176
+ )
177
+ )
178
+
179
+ def _extract_enum(self, node, source, symbols, parent_name):
180
+ name_node = node.child_by_field_name("name")
181
+ if name_node is None:
182
+ return
183
+ name = self.node_text(name_node, source)
184
+ vis = self._visibility(node, source)
185
+ sig = f"{'pub ' if vis == 'public' else ''}enum {name}"
186
+
187
+ type_params = node.child_by_field_name("type_parameters")
188
+ if type_params:
189
+ sig += self.node_text(type_params, source)
190
+
191
+ qualified = f"{parent_name}::{name}" if parent_name else name
192
+ symbols.append(
193
+ self._make_symbol(
194
+ name=name,
195
+ kind="enum",
196
+ line_start=node.start_point[0] + 1,
197
+ line_end=node.end_point[0] + 1,
198
+ qualified_name=qualified,
199
+ signature=sig,
200
+ docstring=self.get_docstring(node, source),
201
+ visibility=vis,
202
+ is_exported=vis == "public",
203
+ parent_name=parent_name,
204
+ )
205
+ )
206
+
207
+ # Extract enum variants
208
+ body = node.child_by_field_name("body")
209
+ if body:
210
+ for child in body.children:
211
+ if child.type == "enum_variant":
212
+ vn = child.child_by_field_name("name")
213
+ if vn:
214
+ variant_name = self.node_text(vn, source)
215
+ symbols.append(
216
+ self._make_symbol(
217
+ name=variant_name,
218
+ kind="field",
219
+ line_start=child.start_point[0] + 1,
220
+ line_end=child.end_point[0] + 1,
221
+ qualified_name=f"{qualified}::{variant_name}",
222
+ parent_name=qualified,
223
+ visibility=vis,
224
+ is_exported=vis == "public",
225
+ )
226
+ )
227
+
228
+ def _extract_trait(self, node, source, symbols, parent_name):
229
+ name_node = node.child_by_field_name("name")
230
+ if name_node is None:
231
+ return
232
+ name = self.node_text(name_node, source)
233
+ vis = self._visibility(node, source)
234
+ sig = f"{'pub ' if vis == 'public' else ''}trait {name}"
235
+
236
+ type_params = node.child_by_field_name("type_parameters")
237
+ if type_params:
238
+ sig += self.node_text(type_params, source)
239
+
240
+ qualified = f"{parent_name}::{name}" if parent_name else name
241
+ symbols.append(
242
+ self._make_symbol(
243
+ name=name,
244
+ kind="trait",
245
+ line_start=node.start_point[0] + 1,
246
+ line_end=node.end_point[0] + 1,
247
+ qualified_name=qualified,
248
+ signature=sig,
249
+ docstring=self.get_docstring(node, source),
250
+ visibility=vis,
251
+ is_exported=vis == "public",
252
+ parent_name=parent_name,
253
+ )
254
+ )
255
+
256
+ # Extract trait methods
257
+ body = node.child_by_field_name("body")
258
+ if body:
259
+ for child in body.children:
260
+ if child.type == "function_item":
261
+ self._extract_function(child, source, symbols, qualified, kind="method")
262
+ elif child.type == "function_signature_item":
263
+ self._extract_fn_signature(child, source, symbols, qualified)
264
+
265
+ def _extract_fn_signature(self, node, source, symbols, parent_name):
266
+ """Extract function signature items (trait method declarations without body)."""
267
+ name_node = node.child_by_field_name("name")
268
+ if name_node is None:
269
+ return
270
+ name = self.node_text(name_node, source)
271
+ params = node.child_by_field_name("parameters")
272
+ sig = f"fn {name}({self.node_text(params, source) if params else ''})"
273
+ ret = node.child_by_field_name("return_type")
274
+ if ret:
275
+ sig += f" -> {self.node_text(ret, source)}"
276
+
277
+ symbols.append(
278
+ self._make_symbol(
279
+ name=name,
280
+ kind="method",
281
+ line_start=node.start_point[0] + 1,
282
+ line_end=node.end_point[0] + 1,
283
+ qualified_name=f"{parent_name}::{name}",
284
+ signature=sig,
285
+ docstring=self.get_docstring(node, source),
286
+ parent_name=parent_name,
287
+ )
288
+ )
289
+
290
+ def _extract_impl(self, node, source, symbols, parent_name):
291
+ """Extract impl block: associate methods with the implementing type."""
292
+ # Determine the type being implemented
293
+ type_node = node.child_by_field_name("type")
294
+ trait_node = node.child_by_field_name("trait")
295
+
296
+ if type_node is None:
297
+ return
298
+
299
+ type_name = self.node_text(type_node, source)
300
+ impl_name = type_name
301
+
302
+ if trait_node:
303
+ trait_name = self.node_text(trait_node, source)
304
+ impl_name = f"{type_name}::{trait_name}"
305
+
306
+ body = node.child_by_field_name("body")
307
+ if body:
308
+ for child in body.children:
309
+ if child.type == "function_item":
310
+ self._extract_function(child, source, symbols, impl_name, kind="method")
311
+ elif child.type == "type_item":
312
+ self._extract_type_alias(child, source, symbols, impl_name)
313
+ elif child.type == "const_item":
314
+ self._extract_const(child, source, symbols, impl_name)
315
+
316
+ def _extract_mod(self, node, source, symbols, parent_name):
317
+ name_node = node.child_by_field_name("name")
318
+ if name_node is None:
319
+ return
320
+ name = self.node_text(name_node, source)
321
+ vis = self._visibility(node, source)
322
+ sig = f"{'pub ' if vis == 'public' else ''}mod {name}"
323
+
324
+ qualified = f"{parent_name}::{name}" if parent_name else name
325
+ symbols.append(
326
+ self._make_symbol(
327
+ name=name,
328
+ kind="module",
329
+ line_start=node.start_point[0] + 1,
330
+ line_end=node.end_point[0] + 1,
331
+ qualified_name=qualified,
332
+ signature=sig,
333
+ visibility=vis,
334
+ is_exported=vis == "public",
335
+ parent_name=parent_name,
336
+ )
337
+ )
338
+
339
+ # Walk mod body if inline
340
+ body = node.child_by_field_name("body")
341
+ if body:
342
+ self._walk_symbols(body, source, symbols, qualified)
343
+
344
+ def _extract_type_alias(self, node, source, symbols, parent_name):
345
+ name_node = node.child_by_field_name("name")
346
+ if name_node is None:
347
+ return
348
+ name = self.node_text(name_node, source)
349
+ vis = self._visibility(node, source)
350
+ sig = f"{'pub ' if vis == 'public' else ''}type {name}"
351
+
352
+ type_params = node.child_by_field_name("type_parameters")
353
+ if type_params:
354
+ sig += self.node_text(type_params, source)
355
+
356
+ value = node.child_by_field_name("type")
357
+ if value:
358
+ val_text = self.node_text(value, source)
359
+ if len(val_text) <= 60:
360
+ sig += f" = {val_text}"
361
+
362
+ qualified = f"{parent_name}::{name}" if parent_name else name
363
+ symbols.append(
364
+ self._make_symbol(
365
+ name=name,
366
+ kind="type_alias",
367
+ line_start=node.start_point[0] + 1,
368
+ line_end=node.end_point[0] + 1,
369
+ qualified_name=qualified,
370
+ signature=sig,
371
+ visibility=vis,
372
+ is_exported=vis == "public",
373
+ parent_name=parent_name,
374
+ )
375
+ )
376
+
377
+ def _extract_const(self, node, source, symbols, parent_name):
378
+ name_node = node.child_by_field_name("name")
379
+ if name_node is None:
380
+ return
381
+ name = self.node_text(name_node, source)
382
+ vis = self._visibility(node, source)
383
+ type_n = node.child_by_field_name("type")
384
+ sig = f"{'pub ' if vis == 'public' else ''}const {name}"
385
+ if type_n:
386
+ sig += f": {self.node_text(type_n, source)}"
387
+
388
+ qualified = f"{parent_name}::{name}" if parent_name else name
389
+ symbols.append(
390
+ self._make_symbol(
391
+ name=name,
392
+ kind="constant",
393
+ line_start=node.start_point[0] + 1,
394
+ line_end=node.end_point[0] + 1,
395
+ qualified_name=qualified,
396
+ signature=sig,
397
+ visibility=vis,
398
+ is_exported=vis == "public",
399
+ parent_name=parent_name,
400
+ )
401
+ )
402
+
403
+ def _extract_static(self, node, source, symbols, parent_name):
404
+ name_node = node.child_by_field_name("name")
405
+ if name_node is None:
406
+ return
407
+ name = self.node_text(name_node, source)
408
+ vis = self._visibility(node, source)
409
+ type_n = node.child_by_field_name("type")
410
+ sig = f"{'pub ' if vis == 'public' else ''}static {name}"
411
+ if type_n:
412
+ sig += f": {self.node_text(type_n, source)}"
413
+
414
+ qualified = f"{parent_name}::{name}" if parent_name else name
415
+ symbols.append(
416
+ self._make_symbol(
417
+ name=name,
418
+ kind="variable",
419
+ line_start=node.start_point[0] + 1,
420
+ line_end=node.end_point[0] + 1,
421
+ qualified_name=qualified,
422
+ signature=sig,
423
+ visibility=vis,
424
+ is_exported=vis == "public",
425
+ parent_name=parent_name,
426
+ )
427
+ )
428
+
429
+ def _extract_macro(self, node, source, symbols, parent_name):
430
+ name_node = node.child_by_field_name("name")
431
+ if name_node is None:
432
+ return
433
+ name = self.node_text(name_node, source)
434
+ sig = f"macro_rules! {name}"
435
+ qualified = f"{parent_name}::{name}" if parent_name else name
436
+
437
+ symbols.append(
438
+ self._make_symbol(
439
+ name=name,
440
+ kind="function",
441
+ line_start=node.start_point[0] + 1,
442
+ line_end=node.end_point[0] + 1,
443
+ qualified_name=qualified,
444
+ signature=sig,
445
+ docstring=self.get_docstring(node, source),
446
+ is_exported=True,
447
+ parent_name=parent_name,
448
+ )
449
+ )
450
+
451
+ # ---- Reference extraction ----
452
+
453
+ def _walk_refs(self, node, source, refs, scope_name):
454
+ for child in node.children:
455
+ if child.type == "use_declaration":
456
+ self._extract_use(child, source, refs, scope_name)
457
+ elif child.type == "call_expression":
458
+ self._extract_call(child, source, refs, scope_name)
459
+ elif child.type == "macro_invocation":
460
+ self._extract_macro_call(child, source, refs, scope_name)
461
+ else:
462
+ new_scope = scope_name
463
+ if child.type == "function_item":
464
+ n = child.child_by_field_name("name")
465
+ if n:
466
+ fname = self.node_text(n, source)
467
+ new_scope = f"{scope_name}::{fname}" if scope_name else fname
468
+ elif child.type == "impl_item":
469
+ t = child.child_by_field_name("type")
470
+ if t:
471
+ new_scope = self.node_text(t, source)
472
+ self._walk_refs(child, source, refs, new_scope)
473
+
474
+ def _extract_use(self, node, source, refs, scope_name):
475
+ """Extract use declarations."""
476
+ # Get the full use path text
477
+ for child in node.children:
478
+ if child.type in (
479
+ "use_as_clause",
480
+ "use_list",
481
+ "scoped_use_list",
482
+ "scoped_identifier",
483
+ "identifier",
484
+ "use_wildcard",
485
+ ):
486
+ path = self.node_text(child, source)
487
+ # Clean up and extract the target name
488
+ target = path.rsplit("::", 1)[-1] if "::" in path else path
489
+ target = target.strip("{}*, ")
490
+ if target:
491
+ refs.append(
492
+ self._make_reference(
493
+ target_name=target,
494
+ kind="import",
495
+ line=node.start_point[0] + 1,
496
+ source_name=scope_name,
497
+ import_path=path,
498
+ )
499
+ )
500
+
501
+ def _extract_call(self, node, source, refs, scope_name):
502
+ func_node = node.child_by_field_name("function")
503
+ if func_node is None:
504
+ return
505
+
506
+ # Handle method calls: obj.method() -> extract "method"
507
+ if func_node.type == "field_expression":
508
+ field = func_node.child_by_field_name("field")
509
+ if field:
510
+ name = self.node_text(field, source)
511
+ else:
512
+ name = self.node_text(func_node, source)
513
+ else:
514
+ name = self.node_text(func_node, source)
515
+
516
+ refs.append(
517
+ self._make_reference(
518
+ target_name=name,
519
+ kind="call",
520
+ line=func_node.start_point[0] + 1,
521
+ source_name=scope_name,
522
+ )
523
+ )
524
+ args = node.child_by_field_name("arguments")
525
+ if args:
526
+ self._walk_refs(args, source, refs, scope_name)
527
+
528
+ def _extract_macro_call(self, node, source, refs, scope_name):
529
+ macro_node = node.child_by_field_name("macro")
530
+ if macro_node is None:
531
+ # Try first child as identifier
532
+ for child in node.children:
533
+ if child.type == "identifier" or child.type == "scoped_identifier":
534
+ macro_node = child
535
+ break
536
+ if macro_node:
537
+ name = self.node_text(macro_node, source)
538
+ refs.append(
539
+ self._make_reference(
540
+ target_name=f"{name}!",
541
+ kind="call",
542
+ line=node.start_point[0] + 1,
543
+ source_name=scope_name,
544
+ )
545
+ )