@flyingrobots/graft 0.11.1 → 0.13.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 (244) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/README.md +7 -0
  3. package/dist/adapters/fake-echo-kernel-transport.d.ts.map +1 -1
  4. package/dist/adapters/fake-echo-kernel-transport.js +12 -0
  5. package/dist/adapters/fake-echo-kernel-transport.js.map +1 -1
  6. package/dist/adapters/node-fs.d.ts.map +1 -1
  7. package/dist/adapters/node-fs.js +6 -0
  8. package/dist/adapters/node-fs.js.map +1 -1
  9. package/dist/api/index.d.ts +2 -2
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/api/index.js +2 -2
  12. package/dist/api/index.js.map +1 -1
  13. package/dist/api/repo-workspace.d.ts.map +1 -1
  14. package/dist/api/repo-workspace.js +3 -0
  15. package/dist/api/repo-workspace.js.map +1 -1
  16. package/dist/cli/cli-error.d.ts.map +1 -1
  17. package/dist/cli/cli-error.js +4 -1
  18. package/dist/cli/cli-error.js.map +1 -1
  19. package/dist/cli/command-parser.d.ts.map +1 -1
  20. package/dist/cli/command-parser.js +5 -0
  21. package/dist/cli/command-parser.js.map +1 -1
  22. package/dist/cli/structural-review-render.d.ts.map +1 -1
  23. package/dist/cli/structural-review-render.js +5 -0
  24. package/dist/cli/structural-review-render.js.map +1 -1
  25. package/dist/contracts/capabilities.d.ts +12 -5
  26. package/dist/contracts/capabilities.d.ts.map +1 -1
  27. package/dist/contracts/capabilities.js +38 -0
  28. package/dist/contracts/capabilities.js.map +1 -1
  29. package/dist/contracts/output-schema-cli.d.ts +56 -0
  30. package/dist/contracts/output-schema-cli.d.ts.map +1 -1
  31. package/dist/contracts/output-schema-cli.js +1 -0
  32. package/dist/contracts/output-schema-cli.js.map +1 -1
  33. package/dist/contracts/output-schema-mcp.d.ts +79 -1
  34. package/dist/contracts/output-schema-mcp.d.ts.map +1 -1
  35. package/dist/contracts/output-schema-mcp.js +27 -0
  36. package/dist/contracts/output-schema-mcp.js.map +1 -1
  37. package/dist/contracts/output-schema-meta.d.ts +18 -4
  38. package/dist/contracts/output-schema-meta.d.ts.map +1 -1
  39. package/dist/contracts/output-schema-meta.js +35 -5
  40. package/dist/contracts/output-schema-meta.js.map +1 -1
  41. package/dist/contracts/output-schemas.d.ts +3 -5
  42. package/dist/contracts/output-schemas.d.ts.map +1 -1
  43. package/dist/contracts/output-schemas.js +21 -37
  44. package/dist/contracts/output-schemas.js.map +1 -1
  45. package/dist/echo/structural-history-client.d.ts.map +1 -1
  46. package/dist/echo/structural-history-client.js +12 -0
  47. package/dist/echo/structural-history-client.js.map +1 -1
  48. package/dist/echo/structural-reading-adapter.d.ts.map +1 -1
  49. package/dist/echo/structural-reading-adapter.js +55 -2
  50. package/dist/echo/structural-reading-adapter.js.map +1 -1
  51. package/dist/echo/structural-reading-generated-model.d.ts.map +1 -1
  52. package/dist/echo/structural-reading-generated-model.js +7 -3
  53. package/dist/echo/structural-reading-generated-model.js.map +1 -1
  54. package/dist/mcp/burden.d.ts.map +1 -1
  55. package/dist/mcp/burden.js +1 -0
  56. package/dist/mcp/burden.js.map +1 -1
  57. package/dist/mcp/daemon-control-plane.d.ts.map +1 -1
  58. package/dist/mcp/daemon-control-plane.js +6 -1
  59. package/dist/mcp/daemon-control-plane.js.map +1 -1
  60. package/dist/mcp/daemon-scheduler-config.d.ts +53 -0
  61. package/dist/mcp/daemon-scheduler-config.d.ts.map +1 -0
  62. package/dist/mcp/daemon-scheduler-config.js +33 -0
  63. package/dist/mcp/daemon-scheduler-config.js.map +1 -0
  64. package/dist/mcp/daemon-server.d.ts.map +1 -1
  65. package/dist/mcp/daemon-server.js +2 -1
  66. package/dist/mcp/daemon-server.js.map +1 -1
  67. package/dist/mcp/receipt.d.ts +3 -0
  68. package/dist/mcp/receipt.d.ts.map +1 -1
  69. package/dist/mcp/receipt.js +4 -0
  70. package/dist/mcp/receipt.js.map +1 -1
  71. package/dist/mcp/repo-tool-job.d.ts +2 -1
  72. package/dist/mcp/repo-tool-job.d.ts.map +1 -1
  73. package/dist/mcp/repo-tool-job.js.map +1 -1
  74. package/dist/mcp/repo-tool-worker-context.d.ts.map +1 -1
  75. package/dist/mcp/repo-tool-worker-context.js +1 -0
  76. package/dist/mcp/repo-tool-worker-context.js.map +1 -1
  77. package/dist/mcp/repo-workspace.d.ts.map +1 -1
  78. package/dist/mcp/repo-workspace.js +5 -1
  79. package/dist/mcp/repo-workspace.js.map +1 -1
  80. package/dist/mcp/server-invocation.d.ts.map +1 -1
  81. package/dist/mcp/server-invocation.js +52 -11
  82. package/dist/mcp/server-invocation.js.map +1 -1
  83. package/dist/mcp/server-tool-access.d.ts +2 -0
  84. package/dist/mcp/server-tool-access.d.ts.map +1 -1
  85. package/dist/mcp/server-tool-access.js +6 -11
  86. package/dist/mcp/server-tool-access.js.map +1 -1
  87. package/dist/mcp/server.d.ts.map +1 -1
  88. package/dist/mcp/server.js +3 -1
  89. package/dist/mcp/server.js.map +1 -1
  90. package/dist/mcp/tool-registry.d.ts.map +1 -1
  91. package/dist/mcp/tool-registry.js +2 -0
  92. package/dist/mcp/tool-registry.js.map +1 -1
  93. package/dist/mcp/tools/changed-since.d.ts.map +1 -1
  94. package/dist/mcp/tools/changed-since.js +8 -63
  95. package/dist/mcp/tools/changed-since.js.map +1 -1
  96. package/dist/mcp/tools/code-find.d.ts.map +1 -1
  97. package/dist/mcp/tools/code-find.js +1 -0
  98. package/dist/mcp/tools/code-find.js.map +1 -1
  99. package/dist/mcp/tools/code-refs.d.ts.map +1 -1
  100. package/dist/mcp/tools/code-refs.js +1 -0
  101. package/dist/mcp/tools/code-refs.js.map +1 -1
  102. package/dist/mcp/tools/code-show.d.ts.map +1 -1
  103. package/dist/mcp/tools/code-show.js +17 -10
  104. package/dist/mcp/tools/code-show.js.map +1 -1
  105. package/dist/mcp/tools/file-outline.d.ts.map +1 -1
  106. package/dist/mcp/tools/file-outline.js +18 -39
  107. package/dist/mcp/tools/file-outline.js.map +1 -1
  108. package/dist/mcp/tools/graft-diff.js +1 -1
  109. package/dist/mcp/tools/graft-diff.js.map +1 -1
  110. package/dist/mcp/tools/import-diagnostics.d.ts +3 -0
  111. package/dist/mcp/tools/import-diagnostics.d.ts.map +1 -0
  112. package/dist/mcp/tools/import-diagnostics.js +25 -0
  113. package/dist/mcp/tools/import-diagnostics.js.map +1 -0
  114. package/dist/mcp/tools/map.d.ts.map +1 -1
  115. package/dist/mcp/tools/map.js +1 -0
  116. package/dist/mcp/tools/map.js.map +1 -1
  117. package/dist/mcp/tools/precision-live.d.ts +8 -0
  118. package/dist/mcp/tools/precision-live.d.ts.map +1 -1
  119. package/dist/mcp/tools/precision-live.js +16 -3
  120. package/dist/mcp/tools/precision-live.js.map +1 -1
  121. package/dist/mcp/tools/precision.d.ts +1 -1
  122. package/dist/mcp/tools/precision.d.ts.map +1 -1
  123. package/dist/mcp/tools/precision.js +1 -1
  124. package/dist/mcp/tools/precision.js.map +1 -1
  125. package/dist/mcp/tools/read-range.d.ts.map +1 -1
  126. package/dist/mcp/tools/read-range.js +23 -8
  127. package/dist/mcp/tools/read-range.js.map +1 -1
  128. package/dist/mcp/tools/safe-read.js +1 -1
  129. package/dist/mcp/tools/safe-read.js.map +1 -1
  130. package/dist/mcp/tools/since.d.ts.map +1 -1
  131. package/dist/mcp/tools/since.js +1 -0
  132. package/dist/mcp/tools/since.js.map +1 -1
  133. package/dist/mcp/tools/structural-review.d.ts.map +1 -1
  134. package/dist/mcp/tools/structural-review.js +16 -13
  135. package/dist/mcp/tools/structural-review.js.map +1 -1
  136. package/dist/mcp/workspace-read-observation-model.d.ts +1 -0
  137. package/dist/mcp/workspace-read-observation-model.d.ts.map +1 -1
  138. package/dist/mcp/workspace-read-observation-model.js +1 -0
  139. package/dist/mcp/workspace-read-observation-model.js.map +1 -1
  140. package/dist/mcp/workspace-read-observation.d.ts.map +1 -1
  141. package/dist/mcp/workspace-read-observation.js +3 -1
  142. package/dist/mcp/workspace-read-observation.js.map +1 -1
  143. package/dist/mcp/workspace-router-model.d.ts +16 -0
  144. package/dist/mcp/workspace-router-model.d.ts.map +1 -1
  145. package/dist/mcp/workspace-router-model.js +15 -0
  146. package/dist/mcp/workspace-router-model.js.map +1 -1
  147. package/dist/mcp/workspace-router-resolution.d.ts.map +1 -1
  148. package/dist/mcp/workspace-router-resolution.js +19 -1
  149. package/dist/mcp/workspace-router-resolution.js.map +1 -1
  150. package/dist/mcp/workspace-router.d.ts +8 -1
  151. package/dist/mcp/workspace-router.d.ts.map +1 -1
  152. package/dist/mcp/workspace-router.js +89 -2
  153. package/dist/mcp/workspace-router.js.map +1 -1
  154. package/dist/operations/file-outline.d.ts +13 -4
  155. package/dist/operations/file-outline.d.ts.map +1 -1
  156. package/dist/operations/file-outline.js +12 -7
  157. package/dist/operations/file-outline.js.map +1 -1
  158. package/dist/operations/read-range.d.ts +9 -4
  159. package/dist/operations/read-range.d.ts.map +1 -1
  160. package/dist/operations/read-range.js +12 -7
  161. package/dist/operations/read-range.js.map +1 -1
  162. package/dist/operations/repo-workspace.d.ts +53 -3
  163. package/dist/operations/repo-workspace.d.ts.map +1 -1
  164. package/dist/operations/repo-workspace.js +125 -65
  165. package/dist/operations/repo-workspace.js.map +1 -1
  166. package/dist/operations/safe-read.d.ts +8 -5
  167. package/dist/operations/safe-read.d.ts.map +1 -1
  168. package/dist/operations/safe-read.js +34 -26
  169. package/dist/operations/safe-read.js.map +1 -1
  170. package/dist/operations/structural-review.d.ts +7 -1
  171. package/dist/operations/structural-review.d.ts.map +1 -1
  172. package/dist/operations/structural-review.js +13 -2
  173. package/dist/operations/structural-review.js.map +1 -1
  174. package/dist/operations/workspace-read-view.d.ts +208 -0
  175. package/dist/operations/workspace-read-view.d.ts.map +1 -0
  176. package/dist/operations/workspace-read-view.js +302 -0
  177. package/dist/operations/workspace-read-view.js.map +1 -0
  178. package/dist/ports/echo-kernel-transport.d.ts.map +1 -1
  179. package/dist/ports/echo-kernel-transport.js +12 -0
  180. package/dist/ports/echo-kernel-transport.js.map +1 -1
  181. package/dist/ports/filesystem.d.ts +2 -0
  182. package/dist/ports/filesystem.d.ts.map +1 -1
  183. package/dist/ports/structural-reading.d.ts +21 -1
  184. package/dist/ports/structural-reading.d.ts.map +1 -1
  185. package/dist/ports/structural-reading.js.map +1 -1
  186. package/dist/warp/ast-emitter.d.ts +4 -0
  187. package/dist/warp/ast-emitter.d.ts.map +1 -1
  188. package/dist/warp/ast-emitter.js +16 -10
  189. package/dist/warp/ast-emitter.js.map +1 -1
  190. package/dist/warp/ast-import-resolver.d.ts +7 -0
  191. package/dist/warp/ast-import-resolver.d.ts.map +1 -1
  192. package/dist/warp/ast-import-resolver.js +41 -20
  193. package/dist/warp/ast-import-resolver.js.map +1 -1
  194. package/dist/warp/committed-reference-scan.d.ts +38 -0
  195. package/dist/warp/committed-reference-scan.d.ts.map +1 -0
  196. package/dist/warp/committed-reference-scan.js +346 -0
  197. package/dist/warp/committed-reference-scan.js.map +1 -0
  198. package/dist/warp/go-reference-context.d.ts +8 -0
  199. package/dist/warp/go-reference-context.d.ts.map +1 -0
  200. package/dist/warp/go-reference-context.js +209 -0
  201. package/dist/warp/go-reference-context.js.map +1 -0
  202. package/dist/warp/import-diagnostic.d.ts +17 -0
  203. package/dist/warp/import-diagnostic.d.ts.map +1 -0
  204. package/dist/warp/import-diagnostic.js +2 -0
  205. package/dist/warp/import-diagnostic.js.map +1 -0
  206. package/dist/warp/index-head.d.ts.map +1 -1
  207. package/dist/warp/index-head.js +34 -8
  208. package/dist/warp/index-head.js.map +1 -1
  209. package/dist/warp/python-import-resolver.d.ts +10 -0
  210. package/dist/warp/python-import-resolver.d.ts.map +1 -0
  211. package/dist/warp/python-import-resolver.js +100 -0
  212. package/dist/warp/python-import-resolver.js.map +1 -0
  213. package/dist/warp/qualified-reference-bindings.d.ts +11 -0
  214. package/dist/warp/qualified-reference-bindings.d.ts.map +1 -0
  215. package/dist/warp/qualified-reference-bindings.js +483 -0
  216. package/dist/warp/qualified-reference-bindings.js.map +1 -0
  217. package/dist/warp/qualified-reference-contract.d.ts +76 -0
  218. package/dist/warp/qualified-reference-contract.d.ts.map +1 -0
  219. package/dist/warp/qualified-reference-contract.js +2 -0
  220. package/dist/warp/qualified-reference-contract.js.map +1 -0
  221. package/dist/warp/qualified-reference-language-adapters.d.ts +4 -0
  222. package/dist/warp/qualified-reference-language-adapters.d.ts.map +1 -0
  223. package/dist/warp/qualified-reference-language-adapters.js +148 -0
  224. package/dist/warp/qualified-reference-language-adapters.js.map +1 -0
  225. package/dist/warp/qualified-reference-resolver.d.ts +10 -0
  226. package/dist/warp/qualified-reference-resolver.d.ts.map +1 -0
  227. package/dist/warp/qualified-reference-resolver.js +222 -0
  228. package/dist/warp/qualified-reference-resolver.js.map +1 -0
  229. package/dist/warp/qualified-reference-shadows.d.ts +5 -0
  230. package/dist/warp/qualified-reference-shadows.d.ts.map +1 -0
  231. package/dist/warp/qualified-reference-shadows.js +601 -0
  232. package/dist/warp/qualified-reference-shadows.js.map +1 -0
  233. package/dist/warp/structural-reading-adapter.d.ts +2 -1
  234. package/dist/warp/structural-reading-adapter.d.ts.map +1 -1
  235. package/dist/warp/structural-reading-adapter.js +79 -27
  236. package/dist/warp/structural-reading-adapter.js.map +1 -1
  237. package/docs/CLI.md +10 -1
  238. package/docs/MCP.md +23 -1
  239. package/docs/SETUP.md +34 -0
  240. package/package.json +12 -7
  241. package/dist/operations/import-reference-impact.d.ts +0 -13
  242. package/dist/operations/import-reference-impact.d.ts.map +0 -1
  243. package/dist/operations/import-reference-impact.js +0 -101
  244. package/dist/operations/import-reference-impact.js.map +0 -1
@@ -0,0 +1,601 @@
1
+ import { goTargetDirectoryPath } from "./qualified-reference-bindings.js";
2
+ function walk(node, visit) {
3
+ visit(node);
4
+ for (const child of node.namedChildren)
5
+ walk(child, visit);
6
+ }
7
+ function languageName(language) {
8
+ if (language === "ts" || language === "tsx")
9
+ return "typescript";
10
+ if (language === "js")
11
+ return "javascript";
12
+ return language;
13
+ }
14
+ function nearestAncestor(node, types) {
15
+ let cursor = node.parent;
16
+ while (cursor !== null) {
17
+ if (types.has(cursor.type))
18
+ return cursor;
19
+ cursor = cursor.parent;
20
+ }
21
+ return null;
22
+ }
23
+ function directMatchingIdentifier(node, bindings) {
24
+ if (node === null || node === undefined)
25
+ return [];
26
+ return ["identifier", "type_identifier", "package_identifier", "shorthand_property_identifier_pattern"].includes(node.type) && bindings.has(node.text)
27
+ ? [node]
28
+ : [];
29
+ }
30
+ function matchingBindingIdentifiers(language, node, bindings) {
31
+ const direct = directMatchingIdentifier(node, bindings);
32
+ if (direct.length > 0 || node === null || node === undefined)
33
+ return direct;
34
+ if (language === "python") {
35
+ if (node.type === "dotted_name" && node.namedChildren.length === 1) {
36
+ return directMatchingIdentifier(node.namedChildren[0], bindings);
37
+ }
38
+ if (["default_parameter", "typed_parameter", "typed_default_parameter"].includes(node.type)) {
39
+ return matchingBindingIdentifiers(language, node.childForFieldName("name") ?? node.childForFieldName("parameter") ?? node.namedChildren[0], bindings);
40
+ }
41
+ if (["parameters", "lambda_parameters", "case_pattern", "pattern_list", "tuple_pattern", "list_pattern", "dict_pattern", "union_pattern", "list_splat_pattern", "dictionary_splat_pattern", "as_pattern", "as_pattern_target"].includes(node.type)) {
42
+ return node.namedChildren.flatMap((child) => matchingBindingIdentifiers(language, child, bindings));
43
+ }
44
+ return [];
45
+ }
46
+ if (language === "ts" || language === "tsx" || language === "js") {
47
+ if (node.type === "pair_pattern") {
48
+ return matchingBindingIdentifiers(language, node.childForFieldName("value") ?? node.namedChildren.at(-1), bindings);
49
+ }
50
+ if (node.type === "assignment_pattern") {
51
+ return matchingBindingIdentifiers(language, node.childForFieldName("left") ?? node.namedChildren[0], bindings);
52
+ }
53
+ if (["required_parameter", "optional_parameter"].includes(node.type)) {
54
+ return matchingBindingIdentifiers(language, node.childForFieldName("pattern") ?? node.childForFieldName("name") ?? node.namedChildren[0], bindings);
55
+ }
56
+ if (node.type === "rest_pattern") {
57
+ return matchingBindingIdentifiers(language, node.childForFieldName("pattern") ?? node.namedChildren[0], bindings);
58
+ }
59
+ if (["formal_parameters", "object_pattern", "array_pattern"].includes(node.type)) {
60
+ return node.namedChildren.flatMap((child) => matchingBindingIdentifiers(language, child, bindings));
61
+ }
62
+ return [];
63
+ }
64
+ if (language === "rust") {
65
+ if (node.type === "parameter") {
66
+ return matchingBindingIdentifiers(language, node.childForFieldName("pattern") ?? node.namedChildren[0], bindings);
67
+ }
68
+ if (node.type === "tuple_struct_pattern" || node.type === "struct_pattern") {
69
+ const type = node.childForFieldName("type");
70
+ return node.namedChildren
71
+ .filter((child) => child.startIndex !== type?.startIndex)
72
+ .flatMap((child) => matchingBindingIdentifiers(language, child, bindings));
73
+ }
74
+ if (node.type === "field_pattern") {
75
+ return matchingBindingIdentifiers(language, node.childForFieldName("pattern") ?? node.childForFieldName("name") ?? node.namedChildren.at(-1), bindings);
76
+ }
77
+ if (["parameters", "closure_parameters", "match_pattern", "tuple_pattern", "slice_pattern", "reference_pattern", "mut_pattern", "or_pattern"].includes(node.type)) {
78
+ return node.namedChildren.flatMap((child) => matchingBindingIdentifiers(language, child, bindings));
79
+ }
80
+ return [];
81
+ }
82
+ if (["parameter_declaration", "variadic_parameter_declaration"].includes(node.type)) {
83
+ return node.namedChildren
84
+ .filter((child) => child.type === "identifier")
85
+ .flatMap((child) => directMatchingIdentifier(child, bindings));
86
+ }
87
+ if (node.type === "expression_list") {
88
+ return node.namedChildren.flatMap((child) => directMatchingIdentifier(child, bindings));
89
+ }
90
+ return [];
91
+ }
92
+ function pythonDeletionIdentifiers(node, bindings) {
93
+ if (node.type === "attribute" || node.type === "subscript")
94
+ return [];
95
+ const direct = directMatchingIdentifier(node, bindings);
96
+ if (direct.length > 0)
97
+ return direct;
98
+ return node.namedChildren.flatMap((child) => pythonDeletionIdentifiers(child, bindings));
99
+ }
100
+ function matchingRustUseBindingIdentifiers(node, bindings) {
101
+ if (node === null || node === undefined)
102
+ return [];
103
+ if (node.type === "use_as_clause") {
104
+ return directMatchingIdentifier(node.childForFieldName("alias") ?? node.namedChildren.at(-1), bindings);
105
+ }
106
+ if (node.type === "scoped_identifier") {
107
+ return directMatchingIdentifier(node.childForFieldName("name") ?? node.namedChildren.at(-1), bindings);
108
+ }
109
+ if (node.type === "identifier")
110
+ return directMatchingIdentifier(node, bindings);
111
+ if (node.type === "use_list" || node.type === "scoped_use_list") {
112
+ return node.namedChildren.flatMap((child) => matchingRustUseBindingIdentifiers(child, bindings));
113
+ }
114
+ return [];
115
+ }
116
+ function matchingRustTypeParameterIdentifiers(node, bindings) {
117
+ if (node.type === "type_identifier")
118
+ return directMatchingIdentifier(node, bindings);
119
+ if (node.type === "constrained_type_parameter" || node.type === "optional_type_parameter") {
120
+ const name = node.namedChildren[0];
121
+ return name === undefined ? [] : matchingRustTypeParameterIdentifiers(name, bindings);
122
+ }
123
+ if (node.type === "type_parameters") {
124
+ return node.namedChildren.flatMap((child) => matchingRustTypeParameterIdentifiers(child, bindings));
125
+ }
126
+ return [];
127
+ }
128
+ function matchingGoSpecIdentifiers(node, bindings) {
129
+ const identifiers = [];
130
+ for (const child of node.namedChildren) {
131
+ if (child.type !== "identifier")
132
+ break;
133
+ identifiers.push(...directMatchingIdentifier(child, bindings));
134
+ }
135
+ return identifiers;
136
+ }
137
+ function diagnosticFor(language, filePath, binding, targetFilePath, shadowKind, node) {
138
+ return {
139
+ code: "import_binding_shadowed",
140
+ severity: "warning",
141
+ language: languageName(language),
142
+ filePath,
143
+ range: {
144
+ startLine: node.startPosition.row + 1,
145
+ startColumn: node.startPosition.column + 1,
146
+ endLine: node.endPosition.row + 1,
147
+ endColumn: node.endPosition.column + 1,
148
+ },
149
+ binding,
150
+ targetFilePath,
151
+ shadowKind,
152
+ message: `Import binding '${binding}' is shadowed; affected qualified accesses were excluded from reference inference.`,
153
+ };
154
+ }
155
+ const PYTHON_LEXICAL_SCOPE_TYPES = new Set(["function_definition", "lambda", "class_definition"]);
156
+ const PYTHON_DECLARATION_SCOPE_TYPES = new Set(["function_definition", "class_definition"]);
157
+ const PYTHON_IMPORT_STATEMENT_TYPES = new Set(["import_statement", "import_from_statement"]);
158
+ const PYTHON_COMPREHENSION_TYPES = new Set(["list_comprehension", "set_comprehension", "dictionary_comprehension", "generator_expression"]);
159
+ const PYTHON_ASSIGNMENT_TYPES = new Set(["assignment", "augmented_assignment", "named_expression", "for_statement", "for_in_clause"]);
160
+ const TYPESCRIPT_FUNCTION_TYPES = new Set([
161
+ "function_declaration", "function_expression", "generator_function_declaration", "generator_function",
162
+ "arrow_function", "method_definition",
163
+ ]);
164
+ const TYPESCRIPT_BLOCK_TYPES = new Set(["statement_block", "switch_statement", "program"]);
165
+ const TYPESCRIPT_LOCAL_TYPES = new Set(["variable_declarator", "assignment_expression"]);
166
+ const TYPESCRIPT_LOOP_TYPES = new Set(["for_statement", "for_in_statement"]);
167
+ const TYPESCRIPT_DECLARATION_TYPES = new Set(["lexical_declaration", "variable_declaration"]);
168
+ const TYPESCRIPT_SCOPED_LOOP_TYPES = new Set(["for_in_statement", "for_of_statement"]);
169
+ const RUST_IMPORT_SCOPE_TYPES = new Set(["block", "declaration_list"]);
170
+ const RUST_USE_DECLARATION_TYPES = new Set(["use_declaration"]);
171
+ const RUST_DECLARATION_TYPES = new Set(["function_item", "struct_item", "enum_item", "type_item", "const_item", "static_item", "union_item", "trait_item", "mod_item"]);
172
+ const RUST_TYPE_NAMESPACE_DECLARATION_TYPES = new Set(["struct_item", "enum_item", "type_item", "union_item", "trait_item", "mod_item"]);
173
+ const GO_FUNCTION_TYPES = new Set(["function_declaration", "method_declaration", "func_literal"]);
174
+ const GO_BLOCK_TYPES = new Set(["block"]);
175
+ const GO_LEXICAL_SCOPE_TYPES = new Set([
176
+ "block", "expression_case", "type_case", "communication_case", "default_case",
177
+ ]);
178
+ const GO_LOCAL_TYPES = new Set(["short_var_declaration", "var_spec", "const_spec", "assignment_statement"]);
179
+ const GO_LOOP_TYPES = new Set(["for_statement"]);
180
+ const GO_CONTROL_TYPES = new Set(["if_statement", "expression_switch_statement", "type_switch_statement"]);
181
+ const GO_DECLARATION_TYPES = new Set(["function_declaration", "type_spec"]);
182
+ function containsIndex(node, index) {
183
+ return index >= node.startIndex && index < node.endIndex;
184
+ }
185
+ export function pythonClassNamespaceAppliesAtIndex(classScope, index) {
186
+ let cursor = classScope;
187
+ let child = cursor.namedChildren.find((candidate) => containsIndex(candidate, index));
188
+ while (child !== undefined) {
189
+ if (PYTHON_LEXICAL_SCOPE_TYPES.has(child.type)) {
190
+ const body = child.childForFieldName("body") ?? child;
191
+ if (containsIndex(body, index))
192
+ return false;
193
+ }
194
+ if (PYTHON_COMPREHENSION_TYPES.has(child.type)) {
195
+ const outermostForClause = child.namedChildren.find((candidate) => candidate.type === "for_in_clause");
196
+ const iterable = outermostForClause?.childForFieldName("right") ?? outermostForClause?.namedChildren.at(-1);
197
+ if (iterable === undefined || !containsIndex(iterable, index))
198
+ return false;
199
+ }
200
+ cursor = child;
201
+ child = cursor.namedChildren.find((candidate) => containsIndex(candidate, index));
202
+ }
203
+ return true;
204
+ }
205
+ function pythonClassScopeForBindingIdentifier(identifier) {
206
+ let scope = nearestAncestor(identifier, PYTHON_LEXICAL_SCOPE_TYPES);
207
+ if (scope !== null) {
208
+ const declarationName = scope.childForFieldName("name");
209
+ if (declarationName !== null && containsIndex(declarationName, identifier.startIndex)) {
210
+ scope = nearestAncestor(scope, PYTHON_LEXICAL_SCOPE_TYPES);
211
+ }
212
+ }
213
+ if (scope?.type !== "class_definition")
214
+ return undefined;
215
+ const comprehension = nearestAncestor(identifier, PYTHON_COMPREHENSION_TYPES);
216
+ if (comprehension !== null && containsIndex(scope, comprehension.startIndex))
217
+ return undefined;
218
+ return scope;
219
+ }
220
+ export function importBindingAppliesAtIndex(language, binding, index) {
221
+ if (language !== "python")
222
+ return true;
223
+ const importScope = nearestAncestor(binding.importNode, PYTHON_LEXICAL_SCOPE_TYPES);
224
+ if (importScope?.type !== "class_definition")
225
+ return true;
226
+ return pythonClassNamespaceAppliesAtIndex(importScope, index);
227
+ }
228
+ function createShadowCollector(language, filePath, root, bindings, context) {
229
+ const bindingNames = new Set(bindings.map((binding) => binding.name));
230
+ const targetForBinding = (binding) => {
231
+ const packageDirectory = binding.packageDirectory ?? "";
232
+ const packageDeclarations = context.go?.declarations.get(packageDirectory);
233
+ const goTarget = packageDeclarations === undefined
234
+ ? undefined
235
+ : [...packageDeclarations.values()].find((value) => value !== null) ??
236
+ context.go?.packageFiles.get(packageDirectory)?.[0];
237
+ const goDirectory = context.go === undefined
238
+ ? undefined
239
+ : goTargetDirectoryPath(context.go, packageDirectory, context.pathOps);
240
+ return binding.targetFilePath ?? goTarget ?? goDirectory ?? "";
241
+ };
242
+ const activeBinding = (bindingName, scopeStart) => bindings
243
+ .filter((binding) => binding.name === bindingName &&
244
+ scopeStart >= (binding.scopeStartIndex ?? root.startIndex) &&
245
+ scopeStart < (binding.scopeEndIndex ?? root.endIndex) &&
246
+ importBindingAppliesAtIndex(language, binding, scopeStart))
247
+ .sort((left, right) => (right.scopeStartIndex ?? root.startIndex) - (left.scopeStartIndex ?? root.startIndex) ||
248
+ right.importNode.startIndex - left.importNode.startIndex)[0];
249
+ const regions = [];
250
+ const resolvedImportDeclarationStarts = new Set(bindings.flatMap((binding) => {
251
+ if (binding.importNode.type === "mod_item")
252
+ return [binding.importNode.startIndex];
253
+ const declaration = nearestAncestor(binding.importNode, RUST_USE_DECLARATION_TYPES);
254
+ return declaration === null ? [] : [declaration.startIndex];
255
+ }));
256
+ return {
257
+ root,
258
+ bindings,
259
+ bindingNames,
260
+ regions,
261
+ resolvedImportDeclarationStarts,
262
+ addAll: (identifiers, kind, start, end, namespaces = new Set(["value", "type"])) => {
263
+ for (const identifier of identifiers) {
264
+ const binding = activeBinding(identifier.text, start);
265
+ if (binding === undefined)
266
+ continue;
267
+ const target = targetForBinding(binding);
268
+ const diagnostic = diagnosticFor(language, filePath, identifier.text, target, kind, identifier);
269
+ const pythonClassScope = language === "python"
270
+ ? pythonClassScopeForBindingIdentifier(identifier)
271
+ : undefined;
272
+ regions.push({
273
+ binding: identifier.text,
274
+ bindingImportStartIndex: binding.importNode.startIndex,
275
+ startIndex: start,
276
+ endIndex: end,
277
+ diagnostic,
278
+ namespaces,
279
+ ...(pythonClassScope !== undefined ? { pythonClassScope } : {}),
280
+ });
281
+ }
282
+ },
283
+ };
284
+ }
285
+ function collectPythonShadowRegions(collector) {
286
+ const { root, bindings, bindingNames, addAll } = collector;
287
+ const declaredOuterNames = new WeakMap();
288
+ const outerNamesForScope = (scope) => {
289
+ const existing = declaredOuterNames.get(scope);
290
+ if (existing !== undefined)
291
+ return existing;
292
+ const names = new Set();
293
+ const visit = (node) => {
294
+ if (node !== scope && PYTHON_LEXICAL_SCOPE_TYPES.has(node.type))
295
+ return;
296
+ if (node.type === "global_statement" || node.type === "nonlocal_statement") {
297
+ walk(node, (candidate) => {
298
+ if (candidate.type === "identifier" && bindingNames.has(candidate.text))
299
+ names.add(candidate.text);
300
+ });
301
+ return;
302
+ }
303
+ for (const child of node.namedChildren)
304
+ visit(child);
305
+ };
306
+ visit(scope);
307
+ declaredOuterNames.set(scope, names);
308
+ return names;
309
+ };
310
+ for (const binding of bindings) {
311
+ const statement = nearestAncestor(binding.importNode, PYTHON_IMPORT_STATEMENT_TYPES);
312
+ const scope = statement === null ? null : nearestAncestor(statement, PYTHON_LEXICAL_SCOPE_TYPES);
313
+ if (statement === null || (scope?.type !== "function_definition" && scope?.type !== "lambda"))
314
+ continue;
315
+ const body = scope.childForFieldName("body") ?? scope;
316
+ const alias = binding.importNode.type === "aliased_import"
317
+ ? binding.importNode.childForFieldName("alias") ?? binding.importNode.namedChildren.at(-1)
318
+ : binding.importNode.namedChildren.find((child) => child.type === "identifier" && child.text === binding.name);
319
+ addAll(directMatchingIdentifier(alias, bindingNames), "import_declaration", body.startIndex, statement.endIndex);
320
+ }
321
+ walk(root, (node) => {
322
+ if (node.type === "function_definition" || node.type === "lambda") {
323
+ const parameters = node.childForFieldName("parameters");
324
+ const body = node.childForFieldName("body") ?? node.namedChildren.at(-1);
325
+ if (body !== undefined)
326
+ addAll(matchingBindingIdentifiers("python", parameters, bindingNames), "parameter", body.startIndex, body.endIndex);
327
+ }
328
+ if (PYTHON_ASSIGNMENT_TYPES.has(node.type)) {
329
+ const left = node.childForFieldName("left") ?? node.childForFieldName("target") ?? node.namedChildren[0];
330
+ const identifiers = left?.type === "attribute" || left?.type === "subscript"
331
+ ? []
332
+ : matchingBindingIdentifiers("python", left, bindingNames);
333
+ if (identifiers.length > 0) {
334
+ const comprehension = nearestAncestor(node, PYTHON_COMPREHENSION_TYPES);
335
+ const scope = nearestAncestor(node, PYTHON_LEXICAL_SCOPE_TYPES);
336
+ const outerNames = scope === null ? new Set() : outerNamesForScope(scope);
337
+ const outerIdentifiers = identifiers.filter((identifier) => outerNames.has(identifier.text));
338
+ const localIdentifiers = identifiers.filter((identifier) => !outerNames.has(identifier.text));
339
+ const outermostForClause = comprehension?.namedChildren.find((child) => child.type === "for_in_clause");
340
+ const assignmentStart = node.type === "for_statement"
341
+ ? node.childForFieldName("right")?.endIndex ?? node.startIndex
342
+ : node.startIndex;
343
+ if (node.type === "named_expression") {
344
+ const body = scope?.childForFieldName("body") ?? scope;
345
+ const start = scope?.type === "function_definition" || scope?.type === "lambda"
346
+ ? body?.startIndex ?? scope.startIndex
347
+ : node.startIndex;
348
+ addAll(localIdentifiers, scope === null ? "assignment" : "local_binding", start, body?.endIndex ?? root.endIndex);
349
+ addAll(outerIdentifiers, "assignment", node.startIndex, body?.endIndex ?? root.endIndex);
350
+ }
351
+ else if (comprehension !== null && node.type === "for_in_clause" && node.startIndex === outermostForClause?.startIndex) {
352
+ const element = comprehension.namedChildren[0];
353
+ const iterable = node.childForFieldName("right") ?? node.namedChildren.at(-1);
354
+ if (element !== undefined) {
355
+ addAll(identifiers, "comprehension_binding", element.startIndex, element.endIndex);
356
+ }
357
+ addAll(identifiers, "comprehension_binding", iterable?.endIndex ?? node.endIndex, comprehension.endIndex);
358
+ }
359
+ else if (comprehension !== null) {
360
+ addAll(identifiers, "comprehension_binding", comprehension.startIndex, comprehension.endIndex);
361
+ }
362
+ else if (scope !== null) {
363
+ const body = scope.childForFieldName("body") ?? scope;
364
+ const start = scope.type === "function_definition" || scope.type === "lambda"
365
+ ? body.startIndex
366
+ : assignmentStart;
367
+ addAll(localIdentifiers, node.type === "for_statement" ? "loop_binding" : "local_binding", start, body.endIndex);
368
+ addAll(outerIdentifiers, "assignment", assignmentStart, body.endIndex);
369
+ }
370
+ else {
371
+ addAll(identifiers, node.type === "for_statement" ? "loop_binding" : "assignment", assignmentStart, root.endIndex);
372
+ }
373
+ }
374
+ }
375
+ if (node.type === "delete_statement") {
376
+ const scope = nearestAncestor(node, PYTHON_LEXICAL_SCOPE_TYPES);
377
+ if (scope?.type === "function_definition" || scope?.type === "lambda") {
378
+ const body = scope.childForFieldName("body") ?? scope;
379
+ addAll(pythonDeletionIdentifiers(node, bindingNames), "deletion", body.startIndex, body.endIndex);
380
+ }
381
+ }
382
+ if (node.type === "function_definition" || node.type === "class_definition") {
383
+ const identifiers = matchingBindingIdentifiers("python", node.childForFieldName("name"), bindingNames);
384
+ if (identifiers.length > 0) {
385
+ const scope = nearestAncestor(node, PYTHON_DECLARATION_SCOPE_TYPES);
386
+ const body = scope?.childForFieldName("body");
387
+ const start = scope?.type === "function_definition" ? body?.startIndex ?? scope.startIndex : node.startIndex;
388
+ addAll(identifiers, node.type === "class_definition" ? "class_declaration" : "function_declaration", start, body?.endIndex ?? root.endIndex);
389
+ }
390
+ }
391
+ if (node.type === "except_clause") {
392
+ const asPattern = node.namedChildren.find((child) => child.type === "as_pattern");
393
+ const target = asPattern?.namedChildren.find((child) => child.type === "as_pattern_target");
394
+ const scope = nearestAncestor(node, PYTHON_LEXICAL_SCOPE_TYPES);
395
+ const scopeBody = scope?.childForFieldName("body") ?? scope;
396
+ const start = scope?.type === "function_definition" || scope?.type === "lambda"
397
+ ? scopeBody?.startIndex ?? scope.startIndex
398
+ : target?.startIndex ?? node.startIndex;
399
+ addAll(matchingBindingIdentifiers("python", target, bindingNames), "except_binding", start, scopeBody?.endIndex ?? root.endIndex);
400
+ }
401
+ if (node.type === "with_item") {
402
+ const asPattern = node.namedChildren.find((child) => child.type === "as_pattern");
403
+ const alias = asPattern?.childForFieldName("alias") ?? asPattern?.namedChildren.find((child) => child.type === "as_pattern_target");
404
+ const identifiers = matchingBindingIdentifiers("python", alias, bindingNames);
405
+ if (identifiers.length > 0) {
406
+ const scope = nearestAncestor(node, PYTHON_LEXICAL_SCOPE_TYPES);
407
+ const body = scope?.childForFieldName("body") ?? scope;
408
+ const start = scope?.type === "function_definition" || scope?.type === "lambda" ? body?.startIndex ?? scope.startIndex : node.startIndex;
409
+ addAll(identifiers, "with_binding", start, body?.endIndex ?? root.endIndex);
410
+ }
411
+ }
412
+ if (node.type === "case_clause") {
413
+ const pattern = node.childForFieldName("pattern") ?? node.namedChildren[0];
414
+ const identifiers = matchingBindingIdentifiers("python", pattern, bindingNames);
415
+ if (identifiers.length > 0) {
416
+ const scope = nearestAncestor(node, PYTHON_LEXICAL_SCOPE_TYPES);
417
+ const body = scope?.childForFieldName("body") ?? scope;
418
+ const start = scope?.type === "function_definition" || scope?.type === "lambda" ? body?.startIndex ?? scope.startIndex : node.startIndex;
419
+ addAll(identifiers, "pattern_binding", start, body?.endIndex ?? root.endIndex);
420
+ }
421
+ }
422
+ });
423
+ }
424
+ function collectTypeScriptShadowRegions(language, collector) {
425
+ const { root, bindingNames, addAll } = collector;
426
+ const valueNamespace = new Set(["value"]);
427
+ const typeNamespace = new Set(["type"]);
428
+ const bothNamespaces = new Set(["value", "type"]);
429
+ walk(root, (node) => {
430
+ if (TYPESCRIPT_FUNCTION_TYPES.has(node.type)) {
431
+ const body = node.childForFieldName("body") ?? node.namedChildren.at(-1);
432
+ const parameters = node.childForFieldName("parameters") ?? node.childForFieldName("parameter");
433
+ if (body !== undefined) {
434
+ addAll(matchingBindingIdentifiers(language, parameters, bindingNames), "parameter", parameters?.startIndex ?? node.startIndex, body.endIndex, valueNamespace);
435
+ }
436
+ }
437
+ if (node.type === "function_expression" || node.type === "generator_function") {
438
+ const name = node.childForFieldName("name") ?? node.namedChildren.find((child) => child.type === "identifier");
439
+ const body = node.childForFieldName("body") ?? node.namedChildren.at(-1);
440
+ if (body !== undefined) {
441
+ addAll(matchingBindingIdentifiers(language, name, bindingNames), "function_declaration", body.startIndex, body.endIndex, valueNamespace);
442
+ }
443
+ }
444
+ if (node.type === "class") {
445
+ const name = node.childForFieldName("name") ?? node.namedChildren.find((child) => child.type === "type_identifier");
446
+ const body = node.childForFieldName("body") ?? node.namedChildren.find((child) => child.type === "class_body");
447
+ if (body !== undefined) {
448
+ addAll(matchingBindingIdentifiers(language, name, bindingNames), "type_declaration", body.startIndex, body.endIndex, bothNamespaces);
449
+ }
450
+ }
451
+ if (TYPESCRIPT_LOCAL_TYPES.has(node.type)) {
452
+ const identifiers = matchingBindingIdentifiers(language, node.childForFieldName("pattern") ?? node.childForFieldName("name") ?? node.childForFieldName("left") ?? node.namedChildren[0], bindingNames);
453
+ const enclosingLoop = nearestAncestor(node, TYPESCRIPT_LOOP_TYPES);
454
+ const loopBody = enclosingLoop?.childForFieldName("body");
455
+ const loop = enclosingLoop !== null && (loopBody === null || loopBody === undefined || node.startIndex < loopBody.startIndex) ? enclosingLoop : null;
456
+ let scope = loop ?? nearestAncestor(node, TYPESCRIPT_BLOCK_TYPES) ?? root;
457
+ if (node.type === "variable_declarator") {
458
+ const declaration = nearestAncestor(node, TYPESCRIPT_DECLARATION_TYPES);
459
+ if (declaration?.type === "variable_declaration") {
460
+ const functionNode = nearestAncestor(node, TYPESCRIPT_FUNCTION_TYPES);
461
+ const functionBody = functionNode?.childForFieldName("body") ?? functionNode?.namedChildren.at(-1);
462
+ scope = functionBody ?? root;
463
+ }
464
+ }
465
+ const declarationPoint = node.type === "assignment_expression" ? node.startIndex : scope.startIndex;
466
+ addAll(identifiers, loop === null ? "local_binding" : "loop_binding", declarationPoint, scope.endIndex, valueNamespace);
467
+ }
468
+ if (node.type === "catch_clause") {
469
+ const identifiers = matchingBindingIdentifiers(language, node.childForFieldName("parameter") ?? node.namedChildren[0], bindingNames);
470
+ const body = node.childForFieldName("body") ?? node;
471
+ addAll(identifiers, "catch_binding", body.startIndex, body.endIndex, valueNamespace);
472
+ }
473
+ if (TYPESCRIPT_SCOPED_LOOP_TYPES.has(node.type)) {
474
+ const identifiers = matchingBindingIdentifiers(language, node.childForFieldName("left") ?? node.namedChildren[0], bindingNames);
475
+ const body = node.childForFieldName("body") ?? node;
476
+ addAll(identifiers, "loop_binding", body.startIndex, body.endIndex, valueNamespace);
477
+ }
478
+ if (node.type === "function_declaration" || node.type === "generator_function_declaration" ||
479
+ node.type === "class_declaration" || node.type === "enum_declaration") {
480
+ const identifiers = matchingBindingIdentifiers(language, node.childForFieldName("name"), bindingNames);
481
+ const scope = nearestAncestor(node, TYPESCRIPT_BLOCK_TYPES) ?? root;
482
+ const kind = node.type === "class_declaration" || node.type === "enum_declaration"
483
+ ? "type_declaration"
484
+ : "function_declaration";
485
+ addAll(identifiers, kind, scope.startIndex, scope.endIndex, node.type === "class_declaration" || node.type === "enum_declaration" ? bothNamespaces : valueNamespace);
486
+ }
487
+ if (node.type === "interface_declaration" || node.type === "type_alias_declaration") {
488
+ const identifiers = matchingBindingIdentifiers(language, node.childForFieldName("name"), bindingNames);
489
+ const scope = nearestAncestor(node, TYPESCRIPT_BLOCK_TYPES) ?? root;
490
+ addAll(identifiers, "type_declaration", scope.startIndex, scope.endIndex, typeNamespace);
491
+ }
492
+ });
493
+ }
494
+ function collectRustShadowRegions(collector) {
495
+ const { root, bindings, bindingNames, resolvedImportDeclarationStarts, addAll } = collector;
496
+ const typeNamespace = new Set(["type"]);
497
+ walk(root, (node) => {
498
+ if (node.type === "type_parameters") {
499
+ const scope = nearestAncestor(node, RUST_DECLARATION_TYPES) ?? root;
500
+ addAll(matchingRustTypeParameterIdentifiers(node, bindingNames), "type_declaration", scope.startIndex, scope.endIndex, typeNamespace);
501
+ }
502
+ if (node.type === "use_declaration") {
503
+ const scope = nearestAncestor(node, RUST_IMPORT_SCOPE_TYPES);
504
+ if (scope !== null) {
505
+ const argument = node.childForFieldName("argument") ?? node.namedChildren[0];
506
+ const identifiers = matchingRustUseBindingIdentifiers(argument, bindingNames).filter((identifier) => !bindings.some((binding) => {
507
+ const declaration = nearestAncestor(binding.importNode, RUST_USE_DECLARATION_TYPES);
508
+ return declaration?.startIndex === node.startIndex &&
509
+ binding.name === identifier.text &&
510
+ identifier.startIndex >= binding.importNode.startIndex &&
511
+ identifier.endIndex <= binding.importNode.endIndex;
512
+ }));
513
+ addAll(identifiers, "import_declaration", scope.startIndex, scope.endIndex);
514
+ }
515
+ }
516
+ if (RUST_TYPE_NAMESPACE_DECLARATION_TYPES.has(node.type)) {
517
+ if (resolvedImportDeclarationStarts.has(node.startIndex))
518
+ return;
519
+ const identifiers = matchingBindingIdentifiers("rust", node.childForFieldName("name"), bindingNames);
520
+ const scope = nearestAncestor(node, RUST_IMPORT_SCOPE_TYPES) ?? root;
521
+ const kind = node.type === "mod_item" ? "module_declaration" : "type_declaration";
522
+ addAll(identifiers, kind, scope.startIndex, scope.endIndex, typeNamespace);
523
+ }
524
+ });
525
+ }
526
+ function collectGoShadowRegions(collector) {
527
+ const { root, bindingNames, addAll } = collector;
528
+ walk(root, (node) => {
529
+ if (node.type === "parameter_declaration" || node.type === "variadic_parameter_declaration") {
530
+ const functionNode = nearestAncestor(node, GO_FUNCTION_TYPES);
531
+ const functionBody = functionNode?.childForFieldName("body") ?? functionNode?.namedChildren.at(-1);
532
+ if (functionBody !== undefined) {
533
+ addAll(matchingBindingIdentifiers("go", node, bindingNames), "parameter", functionBody.startIndex, functionBody.endIndex);
534
+ }
535
+ }
536
+ if (GO_LOCAL_TYPES.has(node.type)) {
537
+ const identifiers = node.type === "var_spec" || node.type === "const_spec"
538
+ ? matchingGoSpecIdentifiers(node, bindingNames)
539
+ : matchingBindingIdentifiers("go", node.childForFieldName("pattern") ?? node.childForFieldName("name") ?? node.childForFieldName("left") ?? node.namedChildren[0], bindingNames);
540
+ const enclosingLoop = nearestAncestor(node, GO_LOOP_TYPES);
541
+ const loopBody = enclosingLoop?.childForFieldName("body");
542
+ const loop = enclosingLoop !== null && (loopBody === null || loopBody === undefined || node.startIndex < loopBody.startIndex) ? enclosingLoop : null;
543
+ const controlStatement = nearestAncestor(node, GO_CONTROL_TYPES);
544
+ const initializer = controlStatement?.childForFieldName("initializer");
545
+ const initializedControl = controlStatement !== null && initializer !== null && initializer !== undefined &&
546
+ node.startIndex >= initializer.startIndex && node.endIndex <= initializer.endIndex
547
+ ? controlStatement
548
+ : null;
549
+ const scope = loop ?? initializedControl ?? nearestAncestor(node, GO_LEXICAL_SCOPE_TYPES) ?? root;
550
+ addAll(identifiers, loop === null ? (node.type === "assignment_statement" ? "assignment" : "local_binding") : "loop_binding", node.endIndex, scope.endIndex);
551
+ }
552
+ if (node.type === "range_clause") {
553
+ const identifiers = matchingBindingIdentifiers("go", node.childForFieldName("left") ?? node.namedChildren[0], bindingNames);
554
+ const loop = nearestAncestor(node, GO_LOOP_TYPES);
555
+ const body = loop?.childForFieldName("body");
556
+ if (loop !== null)
557
+ addAll(identifiers, "range_binding", body?.startIndex ?? node.endIndex, loop.endIndex);
558
+ }
559
+ if (node.type === "receive_statement" && node.parent?.type === "communication_case") {
560
+ const identifiers = matchingBindingIdentifiers("go", node.childForFieldName("left") ?? node.namedChildren[0], bindingNames);
561
+ addAll(identifiers, "pattern_binding", node.endIndex, node.parent.endIndex);
562
+ }
563
+ if (node.type === "type_switch_statement") {
564
+ const alias = node.namedChildren.find((child) => child.type === "expression_list");
565
+ const firstCase = node.namedChildren.find((child) => child.type === "type_case" || child.type === "default_case");
566
+ if (firstCase !== undefined) {
567
+ addAll(matchingBindingIdentifiers("go", alias, bindingNames), "pattern_binding", firstCase.startIndex, node.endIndex);
568
+ }
569
+ }
570
+ if (GO_DECLARATION_TYPES.has(node.type)) {
571
+ const identifiers = matchingBindingIdentifiers("go", node.childForFieldName("name"), bindingNames);
572
+ const scope = nearestAncestor(node, GO_BLOCK_TYPES) ?? root;
573
+ addAll(identifiers, node.type === "type_spec" ? "type_declaration" : "function_declaration", node.startIndex, scope.endIndex);
574
+ }
575
+ });
576
+ }
577
+ export function collectShadowRegions(language, filePath, root, bindings, context) {
578
+ const collector = createShadowCollector(language, filePath, root, bindings, context);
579
+ if (language === "python")
580
+ collectPythonShadowRegions(collector);
581
+ else if (language === "rust")
582
+ collectRustShadowRegions(collector);
583
+ else if (language === "go")
584
+ collectGoShadowRegions(collector);
585
+ else
586
+ collectTypeScriptShadowRegions(language, collector);
587
+ const unique = new Map();
588
+ for (const region of collector.regions) {
589
+ const key = [
590
+ region.binding,
591
+ region.diagnostic.range.startLine,
592
+ region.diagnostic.range.startColumn,
593
+ region.diagnostic.shadowKind,
594
+ region.startIndex,
595
+ region.endIndex,
596
+ ].join(":");
597
+ unique.set(key, region);
598
+ }
599
+ return [...unique.values()];
600
+ }
601
+ //# sourceMappingURL=qualified-reference-shadows.js.map