@colbymchenry/codegraph-darwin-x64 0.9.8 → 1.0.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 (301) hide show
  1. package/lib/dist/bin/codegraph.d.ts +1 -0
  2. package/lib/dist/bin/codegraph.d.ts.map +1 -1
  3. package/lib/dist/bin/codegraph.js +247 -39
  4. package/lib/dist/bin/codegraph.js.map +1 -1
  5. package/lib/dist/context/index.d.ts +9 -0
  6. package/lib/dist/context/index.d.ts.map +1 -1
  7. package/lib/dist/context/index.js +102 -6
  8. package/lib/dist/context/index.js.map +1 -1
  9. package/lib/dist/context/markers.d.ts +19 -0
  10. package/lib/dist/context/markers.d.ts.map +1 -0
  11. package/lib/dist/context/markers.js +22 -0
  12. package/lib/dist/context/markers.js.map +1 -0
  13. package/lib/dist/db/index.d.ts.map +1 -1
  14. package/lib/dist/db/index.js +2 -1
  15. package/lib/dist/db/index.js.map +1 -1
  16. package/lib/dist/db/migrations.d.ts +1 -1
  17. package/lib/dist/db/migrations.d.ts.map +1 -1
  18. package/lib/dist/db/migrations.js +10 -1
  19. package/lib/dist/db/migrations.js.map +1 -1
  20. package/lib/dist/db/queries.d.ts +43 -0
  21. package/lib/dist/db/queries.d.ts.map +1 -1
  22. package/lib/dist/db/queries.js +103 -7
  23. package/lib/dist/db/queries.js.map +1 -1
  24. package/lib/dist/db/schema.sql +1 -0
  25. package/lib/dist/db/sqlite-adapter.d.ts +7 -0
  26. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  27. package/lib/dist/db/sqlite-adapter.js +3 -0
  28. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  29. package/lib/dist/directory.d.ts +34 -2
  30. package/lib/dist/directory.d.ts.map +1 -1
  31. package/lib/dist/directory.js +129 -35
  32. package/lib/dist/directory.js.map +1 -1
  33. package/lib/dist/extraction/astro-extractor.d.ts +79 -0
  34. package/lib/dist/extraction/astro-extractor.d.ts.map +1 -0
  35. package/lib/dist/extraction/astro-extractor.js +320 -0
  36. package/lib/dist/extraction/astro-extractor.js.map +1 -0
  37. package/lib/dist/extraction/extraction-version.d.ts +25 -0
  38. package/lib/dist/extraction/extraction-version.d.ts.map +1 -0
  39. package/lib/dist/extraction/extraction-version.js +28 -0
  40. package/lib/dist/extraction/extraction-version.js.map +1 -0
  41. package/lib/dist/extraction/function-ref.d.ts +118 -0
  42. package/lib/dist/extraction/function-ref.d.ts.map +1 -0
  43. package/lib/dist/extraction/function-ref.js +727 -0
  44. package/lib/dist/extraction/function-ref.js.map +1 -0
  45. package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
  46. package/lib/dist/extraction/generated-detection.js +3 -0
  47. package/lib/dist/extraction/generated-detection.js.map +1 -1
  48. package/lib/dist/extraction/grammars.d.ts +7 -1
  49. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  50. package/lib/dist/extraction/grammars.js +52 -4
  51. package/lib/dist/extraction/grammars.js.map +1 -1
  52. package/lib/dist/extraction/index.d.ts +34 -0
  53. package/lib/dist/extraction/index.d.ts.map +1 -1
  54. package/lib/dist/extraction/index.js +346 -62
  55. package/lib/dist/extraction/index.js.map +1 -1
  56. package/lib/dist/extraction/languages/c-cpp.d.ts +8 -0
  57. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  58. package/lib/dist/extraction/languages/c-cpp.js +87 -28
  59. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  60. package/lib/dist/extraction/languages/csharp.d.ts +22 -0
  61. package/lib/dist/extraction/languages/csharp.d.ts.map +1 -1
  62. package/lib/dist/extraction/languages/csharp.js +84 -2
  63. package/lib/dist/extraction/languages/csharp.js.map +1 -1
  64. package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
  65. package/lib/dist/extraction/languages/dart.js +161 -1
  66. package/lib/dist/extraction/languages/dart.js.map +1 -1
  67. package/lib/dist/extraction/languages/go.d.ts.map +1 -1
  68. package/lib/dist/extraction/languages/go.js +43 -2
  69. package/lib/dist/extraction/languages/go.js.map +1 -1
  70. package/lib/dist/extraction/languages/index.d.ts.map +1 -1
  71. package/lib/dist/extraction/languages/index.js +2 -0
  72. package/lib/dist/extraction/languages/index.js.map +1 -1
  73. package/lib/dist/extraction/languages/java.d.ts.map +1 -1
  74. package/lib/dist/extraction/languages/java.js +42 -1
  75. package/lib/dist/extraction/languages/java.js.map +1 -1
  76. package/lib/dist/extraction/languages/javascript.d.ts.map +1 -1
  77. package/lib/dist/extraction/languages/javascript.js +16 -0
  78. package/lib/dist/extraction/languages/javascript.js.map +1 -1
  79. package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
  80. package/lib/dist/extraction/languages/kotlin.js +69 -0
  81. package/lib/dist/extraction/languages/kotlin.js.map +1 -1
  82. package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
  83. package/lib/dist/extraction/languages/objc.js +42 -0
  84. package/lib/dist/extraction/languages/objc.js.map +1 -1
  85. package/lib/dist/extraction/languages/pascal.d.ts.map +1 -1
  86. package/lib/dist/extraction/languages/pascal.js +11 -0
  87. package/lib/dist/extraction/languages/pascal.js.map +1 -1
  88. package/lib/dist/extraction/languages/php.d.ts.map +1 -1
  89. package/lib/dist/extraction/languages/php.js +90 -1
  90. package/lib/dist/extraction/languages/php.js.map +1 -1
  91. package/lib/dist/extraction/languages/r.d.ts +3 -0
  92. package/lib/dist/extraction/languages/r.d.ts.map +1 -0
  93. package/lib/dist/extraction/languages/r.js +314 -0
  94. package/lib/dist/extraction/languages/r.js.map +1 -0
  95. package/lib/dist/extraction/languages/ruby.d.ts.map +1 -1
  96. package/lib/dist/extraction/languages/ruby.js +35 -0
  97. package/lib/dist/extraction/languages/ruby.js.map +1 -1
  98. package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
  99. package/lib/dist/extraction/languages/rust.js +35 -2
  100. package/lib/dist/extraction/languages/rust.js.map +1 -1
  101. package/lib/dist/extraction/languages/scala.d.ts.map +1 -1
  102. package/lib/dist/extraction/languages/scala.js +61 -1
  103. package/lib/dist/extraction/languages/scala.js.map +1 -1
  104. package/lib/dist/extraction/languages/swift.d.ts.map +1 -1
  105. package/lib/dist/extraction/languages/swift.js +61 -0
  106. package/lib/dist/extraction/languages/swift.js.map +1 -1
  107. package/lib/dist/extraction/languages/typescript.d.ts +13 -0
  108. package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
  109. package/lib/dist/extraction/languages/typescript.js +38 -0
  110. package/lib/dist/extraction/languages/typescript.js.map +1 -1
  111. package/lib/dist/extraction/liquid-extractor.d.ts +7 -0
  112. package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
  113. package/lib/dist/extraction/liquid-extractor.js +53 -9
  114. package/lib/dist/extraction/liquid-extractor.js.map +1 -1
  115. package/lib/dist/extraction/razor-extractor.d.ts +42 -0
  116. package/lib/dist/extraction/razor-extractor.d.ts.map +1 -0
  117. package/lib/dist/extraction/razor-extractor.js +285 -0
  118. package/lib/dist/extraction/razor-extractor.js.map +1 -0
  119. package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -1
  120. package/lib/dist/extraction/svelte-extractor.js +6 -3
  121. package/lib/dist/extraction/svelte-extractor.js.map +1 -1
  122. package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
  123. package/lib/dist/extraction/tree-sitter-helpers.js +59 -10
  124. package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
  125. package/lib/dist/extraction/tree-sitter-types.d.ts +33 -0
  126. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  127. package/lib/dist/extraction/tree-sitter.d.ts +237 -0
  128. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  129. package/lib/dist/extraction/tree-sitter.js +1820 -68
  130. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  131. package/lib/dist/extraction/vue-extractor.d.ts +15 -0
  132. package/lib/dist/extraction/vue-extractor.d.ts.map +1 -1
  133. package/lib/dist/extraction/vue-extractor.js +94 -3
  134. package/lib/dist/extraction/vue-extractor.js.map +1 -1
  135. package/lib/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  136. package/lib/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
  137. package/lib/dist/graph/queries.d.ts.map +1 -1
  138. package/lib/dist/graph/queries.js +13 -40
  139. package/lib/dist/graph/queries.js.map +1 -1
  140. package/lib/dist/graph/traversal.d.ts.map +1 -1
  141. package/lib/dist/graph/traversal.js +16 -4
  142. package/lib/dist/graph/traversal.js.map +1 -1
  143. package/lib/dist/index.d.ts +41 -3
  144. package/lib/dist/index.d.ts.map +1 -1
  145. package/lib/dist/index.js +99 -9
  146. package/lib/dist/index.js.map +1 -1
  147. package/lib/dist/installer/index.d.ts.map +1 -1
  148. package/lib/dist/installer/index.js +52 -2
  149. package/lib/dist/installer/index.js.map +1 -1
  150. package/lib/dist/installer/instructions-template.d.ts +34 -11
  151. package/lib/dist/installer/instructions-template.d.ts.map +1 -1
  152. package/lib/dist/installer/instructions-template.js +44 -12
  153. package/lib/dist/installer/instructions-template.js.map +1 -1
  154. package/lib/dist/installer/targets/claude.d.ts.map +1 -1
  155. package/lib/dist/installer/targets/claude.js +6 -10
  156. package/lib/dist/installer/targets/claude.js.map +1 -1
  157. package/lib/dist/installer/targets/codex.js +4 -6
  158. package/lib/dist/installer/targets/codex.js.map +1 -1
  159. package/lib/dist/installer/targets/gemini.js +4 -6
  160. package/lib/dist/installer/targets/gemini.js.map +1 -1
  161. package/lib/dist/installer/targets/opencode.d.ts +9 -1
  162. package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
  163. package/lib/dist/installer/targets/opencode.js +91 -40
  164. package/lib/dist/installer/targets/opencode.js.map +1 -1
  165. package/lib/dist/installer/targets/shared.d.ts +14 -0
  166. package/lib/dist/installer/targets/shared.d.ts.map +1 -1
  167. package/lib/dist/installer/targets/shared.js +19 -2
  168. package/lib/dist/installer/targets/shared.js.map +1 -1
  169. package/lib/dist/mcp/daemon.d.ts +60 -1
  170. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  171. package/lib/dist/mcp/daemon.js +221 -8
  172. package/lib/dist/mcp/daemon.js.map +1 -1
  173. package/lib/dist/mcp/dynamic-boundaries.d.ts +41 -0
  174. package/lib/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
  175. package/lib/dist/mcp/dynamic-boundaries.js +359 -0
  176. package/lib/dist/mcp/dynamic-boundaries.js.map +1 -0
  177. package/lib/dist/mcp/index.d.ts.map +1 -1
  178. package/lib/dist/mcp/index.js +18 -9
  179. package/lib/dist/mcp/index.js.map +1 -1
  180. package/lib/dist/mcp/ppid-watchdog.d.ts +44 -0
  181. package/lib/dist/mcp/ppid-watchdog.d.ts.map +1 -0
  182. package/lib/dist/mcp/ppid-watchdog.js +27 -0
  183. package/lib/dist/mcp/ppid-watchdog.js.map +1 -0
  184. package/lib/dist/mcp/proxy.d.ts +6 -0
  185. package/lib/dist/mcp/proxy.d.ts.map +1 -1
  186. package/lib/dist/mcp/proxy.js +153 -24
  187. package/lib/dist/mcp/proxy.js.map +1 -1
  188. package/lib/dist/mcp/server-instructions.d.ts +12 -1
  189. package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
  190. package/lib/dist/mcp/server-instructions.js +58 -32
  191. package/lib/dist/mcp/server-instructions.js.map +1 -1
  192. package/lib/dist/mcp/session.d.ts +2 -0
  193. package/lib/dist/mcp/session.d.ts.map +1 -1
  194. package/lib/dist/mcp/session.js +49 -2
  195. package/lib/dist/mcp/session.js.map +1 -1
  196. package/lib/dist/mcp/stdin-teardown.d.ts +27 -0
  197. package/lib/dist/mcp/stdin-teardown.d.ts.map +1 -0
  198. package/lib/dist/mcp/stdin-teardown.js +49 -0
  199. package/lib/dist/mcp/stdin-teardown.js.map +1 -0
  200. package/lib/dist/mcp/tools.d.ts +110 -49
  201. package/lib/dist/mcp/tools.d.ts.map +1 -1
  202. package/lib/dist/mcp/tools.js +1222 -972
  203. package/lib/dist/mcp/tools.js.map +1 -1
  204. package/lib/dist/mcp/transport.d.ts.map +1 -1
  205. package/lib/dist/mcp/transport.js +18 -2
  206. package/lib/dist/mcp/transport.js.map +1 -1
  207. package/lib/dist/resolution/callback-synthesizer.d.ts +3 -3
  208. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  209. package/lib/dist/resolution/callback-synthesizer.js +549 -21
  210. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  211. package/lib/dist/resolution/frameworks/astro.d.ts +9 -0
  212. package/lib/dist/resolution/frameworks/astro.d.ts.map +1 -0
  213. package/lib/dist/resolution/frameworks/astro.js +169 -0
  214. package/lib/dist/resolution/frameworks/astro.js.map +1 -0
  215. package/lib/dist/resolution/frameworks/expo-modules.d.ts.map +1 -1
  216. package/lib/dist/resolution/frameworks/expo-modules.js +6 -1
  217. package/lib/dist/resolution/frameworks/expo-modules.js.map +1 -1
  218. package/lib/dist/resolution/frameworks/index.d.ts +1 -0
  219. package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
  220. package/lib/dist/resolution/frameworks/index.js +5 -1
  221. package/lib/dist/resolution/frameworks/index.js.map +1 -1
  222. package/lib/dist/resolution/frameworks/java.js +6 -1
  223. package/lib/dist/resolution/frameworks/java.js.map +1 -1
  224. package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
  225. package/lib/dist/resolution/frameworks/python.js +7 -3
  226. package/lib/dist/resolution/frameworks/python.js.map +1 -1
  227. package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
  228. package/lib/dist/resolution/frameworks/react-native.js +53 -3
  229. package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
  230. package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
  231. package/lib/dist/resolution/frameworks/react.js +15 -3
  232. package/lib/dist/resolution/frameworks/react.js.map +1 -1
  233. package/lib/dist/resolution/frameworks/svelte.js +5 -1
  234. package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
  235. package/lib/dist/resolution/frameworks/vue.js +24 -27
  236. package/lib/dist/resolution/frameworks/vue.js.map +1 -1
  237. package/lib/dist/resolution/import-resolver.d.ts +10 -0
  238. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  239. package/lib/dist/resolution/import-resolver.js +564 -2
  240. package/lib/dist/resolution/import-resolver.js.map +1 -1
  241. package/lib/dist/resolution/index.d.ts +80 -0
  242. package/lib/dist/resolution/index.d.ts.map +1 -1
  243. package/lib/dist/resolution/index.js +457 -7
  244. package/lib/dist/resolution/index.js.map +1 -1
  245. package/lib/dist/resolution/name-matcher.d.ts +61 -0
  246. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  247. package/lib/dist/resolution/name-matcher.js +590 -14
  248. package/lib/dist/resolution/name-matcher.js.map +1 -1
  249. package/lib/dist/resolution/types.d.ts +27 -3
  250. package/lib/dist/resolution/types.d.ts.map +1 -1
  251. package/lib/dist/resolution/workspace-packages.d.ts +48 -0
  252. package/lib/dist/resolution/workspace-packages.d.ts.map +1 -0
  253. package/lib/dist/resolution/workspace-packages.js +208 -0
  254. package/lib/dist/resolution/workspace-packages.js.map +1 -0
  255. package/lib/dist/search/query-utils.d.ts +35 -1
  256. package/lib/dist/search/query-utils.d.ts.map +1 -1
  257. package/lib/dist/search/query-utils.js +109 -10
  258. package/lib/dist/search/query-utils.js.map +1 -1
  259. package/lib/dist/sync/watcher.d.ts +124 -32
  260. package/lib/dist/sync/watcher.d.ts.map +1 -1
  261. package/lib/dist/sync/watcher.js +326 -111
  262. package/lib/dist/sync/watcher.js.map +1 -1
  263. package/lib/dist/telemetry/index.d.ts +146 -0
  264. package/lib/dist/telemetry/index.d.ts.map +1 -0
  265. package/lib/dist/telemetry/index.js +544 -0
  266. package/lib/dist/telemetry/index.js.map +1 -0
  267. package/lib/dist/types.d.ts +25 -2
  268. package/lib/dist/types.d.ts.map +1 -1
  269. package/lib/dist/types.js +3 -0
  270. package/lib/dist/types.js.map +1 -1
  271. package/lib/dist/upgrade/index.d.ts +132 -0
  272. package/lib/dist/upgrade/index.d.ts.map +1 -0
  273. package/lib/dist/upgrade/index.js +462 -0
  274. package/lib/dist/upgrade/index.js.map +1 -0
  275. package/lib/dist/utils.d.ts +30 -24
  276. package/lib/dist/utils.d.ts.map +1 -1
  277. package/lib/dist/utils.js +64 -48
  278. package/lib/dist/utils.js.map +1 -1
  279. package/lib/node_modules/.package-lock.json +1 -29
  280. package/lib/package.json +1 -2
  281. package/package.json +1 -1
  282. package/lib/node_modules/chokidar/LICENSE +0 -21
  283. package/lib/node_modules/chokidar/README.md +0 -305
  284. package/lib/node_modules/chokidar/esm/handler.d.ts +0 -90
  285. package/lib/node_modules/chokidar/esm/handler.js +0 -629
  286. package/lib/node_modules/chokidar/esm/index.d.ts +0 -215
  287. package/lib/node_modules/chokidar/esm/index.js +0 -798
  288. package/lib/node_modules/chokidar/esm/package.json +0 -1
  289. package/lib/node_modules/chokidar/handler.d.ts +0 -90
  290. package/lib/node_modules/chokidar/handler.js +0 -635
  291. package/lib/node_modules/chokidar/index.d.ts +0 -215
  292. package/lib/node_modules/chokidar/index.js +0 -804
  293. package/lib/node_modules/chokidar/package.json +0 -69
  294. package/lib/node_modules/readdirp/LICENSE +0 -21
  295. package/lib/node_modules/readdirp/README.md +0 -120
  296. package/lib/node_modules/readdirp/esm/index.d.ts +0 -108
  297. package/lib/node_modules/readdirp/esm/index.js +0 -257
  298. package/lib/node_modules/readdirp/esm/package.json +0 -1
  299. package/lib/node_modules/readdirp/index.d.ts +0 -108
  300. package/lib/node_modules/readdirp/index.js +0 -263
  301. package/lib/node_modules/readdirp/package.json +0 -70
@@ -6,8 +6,15 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.matchByFilePath = matchByFilePath;
9
+ exports.sameLanguageFamily = sameLanguageFamily;
10
+ exports.isKnownLanguageFamily = isKnownLanguageFamily;
11
+ exports.crossesKnownFamily = crossesKnownFamily;
12
+ exports.matchFunctionRef = matchFunctionRef;
9
13
  exports.matchByExactName = matchByExactName;
10
14
  exports.matchByQualifiedName = matchByQualifiedName;
15
+ exports.matchCppCallChain = matchCppCallChain;
16
+ exports.matchScopedCallChain = matchScopedCallChain;
17
+ exports.matchDottedCallChain = matchDottedCallChain;
11
18
  exports.matchMethodCall = matchMethodCall;
12
19
  exports.matchFuzzy = matchFuzzy;
13
20
  exports.matchReference = matchReference;
@@ -16,8 +23,13 @@ exports.matchReference = matchReference;
16
23
  * by matching the filename against file nodes.
17
24
  */
18
25
  function matchByFilePath(ref, context) {
19
- if (!ref.referenceName.includes('/'))
26
+ // Path-like (`a/b.liquid`) OR a bare filename ending in a short extension
27
+ // (`Foo.h` — an Objective-C `#import "Foo.h"`, resolved to the header by
28
+ // basename). A bare ref WITHOUT an extension is a symbol name, not a file, so
29
+ // leave it to the symbol-matching strategies.
30
+ if (!ref.referenceName.includes('/') && !/\.[A-Za-z][A-Za-z0-9]{0,3}$/.test(ref.referenceName)) {
20
31
  return null;
32
+ }
21
33
  // Extract the filename from the path
22
34
  const fileName = ref.referenceName.split('/').pop();
23
35
  if (!fileName)
@@ -37,12 +49,18 @@ function matchByFilePath(ref, context) {
37
49
  resolvedBy: 'file-path',
38
50
  };
39
51
  }
40
- // Fall back to suffix match (e.g., ref="snippets/foo.liquid" matches "src/snippets/foo.liquid")
41
- const suffixMatch = fileNodes.find(n => n.qualifiedName.endsWith(ref.referenceName) || n.filePath.endsWith(ref.referenceName));
42
- if (suffixMatch) {
52
+ // Fall back to suffix match (e.g., ref="snippets/foo.liquid" matches
53
+ // "src/snippets/foo.liquid"). When several files share the basename — a
54
+ // `#include "RNCAsyncStorage.h"` with a same-named header on another platform
55
+ // (windows/code/ vs apple/) — prefer the one in the includer's own directory,
56
+ // then by directory proximity / same language family. A C/C++ include (and any
57
+ // bare-filename import) resolves relative to the including file, not to an
58
+ // arbitrary same-named header elsewhere in the tree.
59
+ const suffixMatches = fileNodes.filter(n => n.qualifiedName.endsWith(ref.referenceName) || n.filePath.endsWith(ref.referenceName));
60
+ if (suffixMatches.length > 0) {
43
61
  return {
44
62
  original: ref,
45
- targetNodeId: suffixMatch.id,
63
+ targetNodeId: pickClosestFileNode(suffixMatches, ref).id,
46
64
  confidence: 0.85,
47
65
  resolvedBy: 'file-path',
48
66
  };
@@ -58,11 +76,231 @@ function matchByFilePath(ref, context) {
58
76
  }
59
77
  return null;
60
78
  }
79
+ /**
80
+ * Among several file nodes that all match a bare include/import by basename,
81
+ * pick the one closest to the referencing file: same directory first, then by
82
+ * directory-tree proximity, with the same language family as a tiebreak. A
83
+ * C/C++ `#include "X.h"` (and any bare-filename import) resolves relative to the
84
+ * including file — not to an arbitrary same-named header on another platform.
85
+ */
86
+ function pickClosestFileNode(candidates, ref) {
87
+ const dirOf = (p) => {
88
+ const i = p.lastIndexOf('/');
89
+ return i >= 0 ? p.slice(0, i) : '';
90
+ };
91
+ const refDir = dirOf(ref.filePath);
92
+ const sameDir = candidates.filter((c) => dirOf(c.filePath) === refDir);
93
+ const pool = sameDir.length > 0 ? sameDir : candidates;
94
+ let best = pool[0];
95
+ let bestScore = -Infinity;
96
+ for (const c of pool) {
97
+ const score = computePathProximity(ref.filePath, c.filePath) +
98
+ (sameLanguageFamily(c.language, ref.language) ? 5 : 0);
99
+ if (score > bestScore) {
100
+ bestScore = score;
101
+ best = c;
102
+ }
103
+ }
104
+ return best;
105
+ }
106
+ /**
107
+ * Language families that share a type system / runtime, so a same-language-only
108
+ * reference may still resolve across them (a Kotlin `Foo.BAR` can name a Java
109
+ * `Foo`). Anything not listed forms its own singleton family.
110
+ */
111
+ const LANGUAGE_FAMILY = {
112
+ java: 'jvm', kotlin: 'jvm', scala: 'jvm',
113
+ swift: 'apple', objc: 'apple',
114
+ typescript: 'web', tsx: 'web', javascript: 'web', jsx: 'web',
115
+ c: 'c', cpp: 'c',
116
+ // Razor/Blazor markup names C# types — same family so `@model Foo` /
117
+ // `<MyComponent/>` resolve to their `.cs` class through the cross-family gate.
118
+ csharp: 'dotnet', razor: 'dotnet',
119
+ };
120
+ function sameLanguageFamily(a, b) {
121
+ if (a === b)
122
+ return true;
123
+ const fa = LANGUAGE_FAMILY[a];
124
+ return fa !== undefined && fa === LANGUAGE_FAMILY[b];
125
+ }
126
+ /**
127
+ * True when `lang` belongs to a known multi-language family (jvm/apple/web/c).
128
+ * Languages not listed (php, python, go, ruby, rust, dart, …) and config
129
+ * formats (yaml/xml/blade) form their own singleton families and return
130
+ * `false` — used to leave config↔code framework bridges (whose config side is
131
+ * never a known programming-language family) out of the cross-family gate.
132
+ */
133
+ function isKnownLanguageFamily(lang) {
134
+ return LANGUAGE_FAMILY[lang] !== undefined;
135
+ }
136
+ /**
137
+ * True when `a` and `b` are two DIFFERENT *known* language families — the
138
+ * signature of a coincidental cross-language name collision (a TS `import
139
+ * React` matching a Swift `import React`, a C++ `#include "X.h"` matching a
140
+ * same-named ObjC header on another platform). The both-*known* test is
141
+ * deliberately weaker than {@link sameLanguageFamily}'s negation: a
142
+ * single-file-component language that carries its own tag (`vue`/`svelte`)
143
+ * importing a `.ts` module, or any singleton-family language (php/go/ruby/…),
144
+ * returns `false` here and is left alone.
145
+ */
146
+ function crossesKnownFamily(a, b) {
147
+ return isKnownLanguageFamily(a) && isKnownLanguageFamily(b) && !sameLanguageFamily(a, b);
148
+ }
149
+ /**
150
+ * Drop cross-language candidates from a name lookup. Two regimes:
151
+ * - `references` (type-usage): a type named in language X resolves to a
152
+ * SAME-family type, never a coincidentally same-named symbol in another
153
+ * language (the Android `BatteryManager` system class vs a JS one). Strict
154
+ * same-family filter — cross-language communication is `calls`, not refs.
155
+ * - `imports` (import binding): an `import`/`#include` never crosses two
156
+ * KNOWN families (TS `import React` ↮ Swift `import React`). Weaker
157
+ * both-known filter so `.vue`/`.svelte` (own tag) importing `.ts` survives.
158
+ */
159
+ function applyLanguageGate(candidates, ref) {
160
+ if (ref.referenceKind === 'references' || ref.referenceKind === 'function_ref') {
161
+ return candidates.filter((c) => sameLanguageFamily(c.language, ref.language));
162
+ }
163
+ if (ref.referenceKind === 'imports') {
164
+ return candidates.filter((c) => !crossesKnownFamily(c.language, ref.language));
165
+ }
166
+ return candidates;
167
+ }
168
+ /**
169
+ * Resolve a function-as-value reference (#756) — a function name used as a
170
+ * callback/function-pointer value (`register(handler)`, `o->cb = handler`,
171
+ * `{ .cb = handler }`, `signal(SIGINT, handler)`). The ONLY strategy allowed
172
+ * for `function_ref` refs: exact name, function/method targets only, same
173
+ * language family, same-file first, and cross-file only when the match is
174
+ * UNIQUE. No fuzzy fallback, no qualified-name walking — a wrong callback
175
+ * edge is worse than none.
176
+ */
177
+ function matchFunctionRef(ref, context) {
178
+ // `this.<member>` refs are resolved ONLY by the class-scoped resolver in
179
+ // resolveOne (resolveThisMemberFnRef) — never by name matching here.
180
+ if (ref.referenceName.startsWith('this.'))
181
+ return null;
182
+ // In JS/TS/Python a bare identifier can never be a method value (methods
183
+ // are only reachable through a receiver — `this.m` / `self.m` /
184
+ // `Cls.m`), so bare fn-refs match FUNCTIONS only. This also sidesteps the
185
+ // pre-existing TS quirk of class fields extracting as method-kind nodes,
186
+ // which otherwise soaked up local names passed as arguments (excalidraw
187
+ // A/B finding; same pattern in vendored docopt.py). Python's `self.m`
188
+ // form keeps method targets via its own capture shape. C++ likewise: a
189
+ // bare identifier can only be a FREE function (member values need
190
+ // `&Cls::method`). PHP string callables name global FUNCTIONS (methods
191
+ // need the `[$obj, 'm']` array form, which carries its own shape). Other
192
+ // languages keep method targets: C# method groups, Swift/Dart
193
+ // implicit-self, Java/Kotlin method references.
194
+ const bareFnOnly = ref.language === 'typescript' || ref.language === 'tsx' ||
195
+ ref.language === 'javascript' || ref.language === 'jsx' ||
196
+ ref.language === 'cpp' || ref.language === 'python' ||
197
+ ref.language === 'php';
198
+ // Qualified member-pointer (`&Widget::on_click` → "Widget::on_click"):
199
+ // resolve the member ON THAT SCOPE — exempt from bareFnOnly (the `&Cls::m`
200
+ // shape is an explicit member reference). Unique-or-drop like everything else.
201
+ if (ref.referenceName.includes('::')) {
202
+ const memberName = ref.referenceName.slice(ref.referenceName.lastIndexOf('::') + 2);
203
+ const scoped = context
204
+ .getNodesByName(memberName)
205
+ .filter((n) => (n.kind === 'function' || n.kind === 'method') &&
206
+ sameLanguageFamily(n.language, ref.language) &&
207
+ n.id !== ref.fromNodeId &&
208
+ (n.qualifiedName === ref.referenceName ||
209
+ n.qualifiedName.endsWith(`::${ref.referenceName}`)));
210
+ if (scoped.length === 0)
211
+ return null;
212
+ const sameFileScoped = scoped.filter((n) => n.filePath === ref.filePath);
213
+ const pool = sameFileScoped.length > 0 ? sameFileScoped : scoped;
214
+ if (sameFileScoped.length === 0 && scoped.length > 1)
215
+ return null;
216
+ const target = pool.reduce((a, b) => (a.startLine <= b.startLine ? a : b));
217
+ return {
218
+ original: ref,
219
+ targetNodeId: target.id,
220
+ confidence: 0.9,
221
+ resolvedBy: 'function-ref',
222
+ };
223
+ }
224
+ let candidates = context
225
+ .getNodesByName(ref.referenceName)
226
+ .filter((n) => (n.kind === 'function' || (!bareFnOnly && n.kind === 'method')) &&
227
+ sameLanguageFamily(n.language, ref.language) &&
228
+ n.id !== ref.fromNodeId // a function registering itself is not a dependency edge
229
+ );
230
+ if (candidates.length === 0)
231
+ return null;
232
+ // Swift implicit-self: a bare identifier can name a METHOD only of the
233
+ // ENCLOSING type (`Button(action: handleTap)` written inside that type) —
234
+ // a same-named method on any OTHER class is a parameter collision
235
+ // (Alamofire: a `request` parameter resolving to EventMonitor::request).
236
+ // Scope method candidates to the from-symbol's type; top-level code has no
237
+ // implicit self, so method targets are excluded there entirely. Free
238
+ // functions are unaffected.
239
+ if (ref.language === 'swift' && candidates.some((n) => n.kind === 'method')) {
240
+ const fromNode = context.getNodeById?.(ref.fromNodeId);
241
+ const sep = fromNode ? fromNode.qualifiedName.lastIndexOf('::') : -1;
242
+ const classPrefix = fromNode && sep > 0 ? fromNode.qualifiedName.slice(0, sep) : null;
243
+ candidates = candidates.filter((n) => {
244
+ if (n.kind !== 'method')
245
+ return true;
246
+ if (!classPrefix)
247
+ return false;
248
+ const mSep = n.qualifiedName.lastIndexOf('::');
249
+ if (mSep <= 0)
250
+ return false;
251
+ const methodPrefix = n.qualifiedName.slice(0, mSep);
252
+ // Accept exact-scope matches plus suffix relationships either way, so
253
+ // extension-declared members (`Holder::m`) still match a nested
254
+ // from-scope (`Module::Holder::wire`) and vice versa.
255
+ return (methodPrefix === classPrefix ||
256
+ methodPrefix.endsWith(`::${classPrefix}`) ||
257
+ classPrefix.endsWith(`::${methodPrefix}`));
258
+ });
259
+ if (candidates.length === 0)
260
+ return null;
261
+ }
262
+ // Same-file definition wins — the extraction gate guarantees most survivors
263
+ // have one, and it's the dominant C pattern (static callback registered in
264
+ // a same-file ops struct).
265
+ const sameFile = candidates.filter((n) => n.filePath === ref.filePath);
266
+ if (sameFile.length > 0) {
267
+ // Swift: several same-named METHODS in one file is an API overload family
268
+ // (`Session.request(...)` × N), and a bare identifier hitting it is almost
269
+ // always a same-named parameter, not a method value (Alamofire A/B
270
+ // finding) — refuse rather than guess. A single method (SwiftUI's
271
+ // `action: handleTap`) still resolves.
272
+ if (ref.language === 'swift' &&
273
+ sameFile.length > 1 &&
274
+ sameFile.every((n) => n.kind === 'method')) {
275
+ return null;
276
+ }
277
+ // Same-name overloads in one file are the same conceptual symbol; pick
278
+ // the first by position for determinism.
279
+ const target = sameFile.reduce((a, b) => (a.startLine <= b.startLine ? a : b));
280
+ return {
281
+ original: ref,
282
+ targetNodeId: target.id,
283
+ confidence: sameFile.length === 1 ? 0.95 : 0.9,
284
+ resolvedBy: 'function-ref',
285
+ };
286
+ }
287
+ // Cross-file (imported names the import resolver didn't already claim):
288
+ // only an unambiguous match resolves.
289
+ if (candidates.length === 1) {
290
+ return {
291
+ original: ref,
292
+ targetNodeId: candidates[0].id,
293
+ confidence: 0.8,
294
+ resolvedBy: 'function-ref',
295
+ };
296
+ }
297
+ return null;
298
+ }
61
299
  /**
62
300
  * Try to resolve a reference by exact name match
63
301
  */
64
302
  function matchByExactName(ref, context) {
65
- const candidates = context.getNodesByName(ref.referenceName);
303
+ const candidates = applyLanguageGate(context.getNodesByName(ref.referenceName), ref);
66
304
  if (candidates.length === 0) {
67
305
  return null;
68
306
  }
@@ -135,7 +373,9 @@ function resolveMethodOnType(typeName, methodName, ref, context, confidence, res
135
373
  * file-path-suffix picks the right one — the disambiguation
136
374
  * signal Java imports carry but the call site doesn't (#314).
137
375
  */
138
- preferredFqn) {
376
+ preferredFqn,
377
+ /** Recursion guard for the supertype/conformance walk. */
378
+ depth = 0) {
139
379
  // Look up methods by name and match by qualifiedName ending in
140
380
  // `<typeName>::<methodName>`. This works whether the method is defined
141
381
  // in-class (`class Foo { int bar() { ... } }`) or out-of-line in a separate
@@ -154,8 +394,23 @@ preferredFqn) {
154
394
  matches.push(m);
155
395
  }
156
396
  }
157
- if (matches.length === 0)
397
+ if (matches.length === 0) {
398
+ // Conformance fallback: the method may be defined on a supertype `typeName`
399
+ // extends, or on a protocol / trait it conforms to (e.g. a Swift protocol-
400
+ // extension method, a C# default-interface or extension method, a Kotlin
401
+ // extension on a supertype). Walk supertypes transitively (depth-capped) via
402
+ // the resolved implements/extends edges — empty in the first resolution pass,
403
+ // populated in the conformance pass. Still VALIDATED (the method must exist on
404
+ // a supertype), so a wrong inference produces no edge.
405
+ if (depth < 4 && context.getSupertypes) {
406
+ for (const supertype of context.getSupertypes(typeName, ref.language)) {
407
+ const via = resolveMethodOnType(supertype, methodName, ref, context, confidence, resolvedBy, preferredFqn, depth + 1);
408
+ if (via)
409
+ return via;
410
+ }
411
+ }
158
412
  return null;
413
+ }
159
414
  if (matches.length > 1 && preferredFqn) {
160
415
  const ext = ref.language === 'kotlin' ? '.kt' : '.java';
161
416
  const fqnPath = preferredFqn.replace(/\./g, '/') + ext;
@@ -212,7 +467,7 @@ function normalizeCppTypeName(typeName) {
212
467
  function buildDeclaratorRegex(escapedReceiver) {
213
468
  return new RegExp(`([A-Za-z_][\\w:]*(?:\\s*<[^;=(){}]+>)?(?:\\s*[*&]+)?)\\s*\\b${escapedReceiver}\\b\\s*(?=[;=,)\\[{(]|$)`);
214
469
  }
215
- function inferCppReceiverType(receiverName, ref, context) {
470
+ function inferCppReceiverType(receiverName, ref, context, depth = 0) {
216
471
  const source = context.readFile(ref.filePath);
217
472
  if (!source)
218
473
  return null;
@@ -228,8 +483,17 @@ function inferCppReceiverType(receiverName, ref, context) {
228
483
  const declaratorMatch = line.match(declaratorRegex);
229
484
  if (declaratorMatch) {
230
485
  const normalized = normalizeCppTypeName(declaratorMatch[1] ?? '');
231
- if (normalized)
486
+ if (normalized === 'auto') {
487
+ // `auto x = Foo::instance();` — the declared type is deduced; recover it
488
+ // from the initializer (call return type / construction) (#645).
489
+ const initType = inferCppAutoInitializerType(line, receiverName, ref, context, depth);
490
+ if (initType)
491
+ return initType;
492
+ // No usable initializer on this line — keep scanning earlier ones.
493
+ }
494
+ else if (normalized) {
232
495
  return normalized;
496
+ }
233
497
  }
234
498
  }
235
499
  const headerCandidates = [
@@ -250,12 +514,273 @@ function inferCppReceiverType(receiverName, ref, context) {
250
514
  if (!declaratorMatch)
251
515
  continue;
252
516
  const normalized = normalizeCppTypeName(declaratorMatch[1] ?? '');
253
- if (normalized)
517
+ if (normalized && normalized !== 'auto')
254
518
  return normalized;
255
519
  }
256
520
  }
257
521
  return null;
258
522
  }
523
+ /**
524
+ * Last `::`-separated segment of a (possibly namespace-qualified) C++ name.
525
+ */
526
+ function cppLastSegment(name) {
527
+ const parts = name.split('::').filter(Boolean);
528
+ return parts[parts.length - 1] ?? name;
529
+ }
530
+ /**
531
+ * Return type captured at extraction for `Class::method` (or a free function),
532
+ * read off the indexed node's `returnType` — used by the C++ (#645) and PHP
533
+ * (#608) chained-call resolvers. Language-filtered. Null when not indexed or no
534
+ * return type was recorded (a `void`/primitive return).
535
+ */
536
+ function lookupCalleeReturnType(callee, ref, context) {
537
+ let method = callee;
538
+ let cls = null;
539
+ if (callee.includes('::')) {
540
+ const parts = callee.split('::').filter(Boolean);
541
+ method = parts[parts.length - 1] ?? callee;
542
+ cls = parts.slice(0, -1).join('::');
543
+ }
544
+ const candidates = context.getNodesByName(method).filter((n) => (n.kind === 'method' || n.kind === 'function') &&
545
+ n.language === ref.language &&
546
+ !!n.returnType);
547
+ if (cls) {
548
+ const want = `${cls}::${method}`;
549
+ // The call site may name the class with MORE namespace qualification than
550
+ // the stored node (`details::registry::instance` at the call vs
551
+ // `registry::instance` on the node — the receiver type only carries the
552
+ // immediate class), or LESS. Accept an exact match or either being a
553
+ // namespace-suffix of the other; the shared `::<class>::<method>` tail keeps
554
+ // it specific.
555
+ const m = candidates.find((n) => n.qualifiedName === want ||
556
+ n.qualifiedName.endsWith(`::${want}`) ||
557
+ want.endsWith(`::${n.qualifiedName}`));
558
+ return m?.returnType ?? null;
559
+ }
560
+ return candidates.find((n) => n.kind === 'function')?.returnType ?? null;
561
+ }
562
+ /** Does the graph contain a class/struct named `name`'s last segment? */
563
+ function cppClassExists(name, ref, context) {
564
+ const last = cppLastSegment(name);
565
+ return context
566
+ .getNodesByName(last)
567
+ .some((n) => (n.kind === 'class' || n.kind === 'struct') && n.language === ref.language);
568
+ }
569
+ /**
570
+ * Infer the class produced by a C++ call/construction expression, using return
571
+ * types captured at extraction (#645). Handles, in order:
572
+ * - `make_unique<T>()` / `make_shared<T>()` → T
573
+ * - single-level member call `recv.method()` → recv's type, then method's return
574
+ * - `Class::method()` / free `func()` → the callee's recorded return type
575
+ * - direct construction `Type()` / `ns::Type()` → Type
576
+ * Returns null when undeterminable. Callers MUST still validate the outer method
577
+ * exists on the result before creating an edge, so a wrong guess stays silent.
578
+ */
579
+ function resolveCppCallResultType(inner, ref, context, depth = 0) {
580
+ if (depth > 3)
581
+ return null; // guard against pathological mutual recursion
582
+ const expr = inner.trim();
583
+ const make = expr.match(/(?:^|::)(?:make_unique|make_shared)\s*<\s*([A-Za-z_]\w*)/);
584
+ if (make)
585
+ return make[1] ?? null;
586
+ // Single-level member call `recv.method` (the `manager.view().render()` shape).
587
+ const dotIdx = expr.lastIndexOf('.');
588
+ if (dotIdx > 0) {
589
+ const recv = expr.slice(0, dotIdx);
590
+ const method = expr.slice(dotIdx + 1);
591
+ if (recv.includes('.') || recv.includes('(') || recv.includes('::'))
592
+ return null; // single level only
593
+ const recvType = inferCppReceiverType(recv, ref, context, depth + 1);
594
+ if (!recvType)
595
+ return null;
596
+ return lookupCalleeReturnType(`${recvType}::${method}`, ref, context);
597
+ }
598
+ const ret = lookupCalleeReturnType(expr, ref, context);
599
+ if (ret)
600
+ return ret;
601
+ // Direct construction — the callee itself names a class/struct.
602
+ if (cppClassExists(expr, ref, context))
603
+ return cppLastSegment(expr);
604
+ return null;
605
+ }
606
+ /**
607
+ * Recover the type of an `auto`-declared local from its initializer on the
608
+ * declaration line — `auto x = Foo::instance();`, `auto w = make_unique<W>();`,
609
+ * `auto p = new W();`, `auto w = Widget();` (#645).
610
+ */
611
+ function inferCppAutoInitializerType(line, receiverName, ref, context, depth) {
612
+ const escaped = receiverName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
613
+ const m = line.match(new RegExp(`\\b${escaped}\\b\\s*=\\s*([^;]+)`));
614
+ if (!m || !m[1])
615
+ return null;
616
+ const init = m[1].trim();
617
+ const neu = init.match(/^new\s+([A-Za-z_][\w:]*)/);
618
+ if (neu && neu[1])
619
+ return cppLastSegment(neu[1]);
620
+ // A call or construction: `Foo(...)`, `A::b(...)`, `make_unique<T>(...)`.
621
+ const call = init.match(/^([A-Za-z_][\w:]*(?:\s*<[^>;]*>)?)\s*\(/);
622
+ if (call && call[1])
623
+ return resolveCppCallResultType(call[1].replace(/\s+/g, ''), ref, context, depth + 1);
624
+ return null;
625
+ }
626
+ /**
627
+ * Resolve a C++ chained call whose receiver is itself a call — encoded by the
628
+ * extractor as `<innerCallee>().<method>` (#645). The receiver's type is what
629
+ * the inner call returns; the outer method is then resolved and VALIDATED on it
630
+ * (resolveMethodOnType requires `cls::method` to exist), so a wrong inference
631
+ * produces no edge rather than a wrong one.
632
+ */
633
+ function matchCppCallChain(ref, context) {
634
+ const m = ref.referenceName.match(/^(.+)\(\)\.(\w+)$/);
635
+ if (!m || !m[1] || !m[2])
636
+ return null;
637
+ const cls = resolveCppCallResultType(m[1], ref, context);
638
+ if (!cls)
639
+ return null;
640
+ return resolveMethodOnType(cls, m[2], ref, context, 0.85, 'instance-method');
641
+ }
642
+ /**
643
+ * Resolve a `::`-scoped factory chain whose receiver is a scoped/static call —
644
+ * PHP `Cls::for($x)->method()` (#608, the per-credential Laravel client idiom) or
645
+ * Rust `Foo::new().bar()` (an associated-function call) — both encoded by the
646
+ * extractor as `Cls::factory().method`. The receiver's type is what `Cls::factory`
647
+ * returns: a `self` marker (PHP `: self`/`: static`, Rust `-> Self`) resolves to
648
+ * the factory's own type, a concrete return type to that type. The outer method is
649
+ * then resolved and VALIDATED on it (resolveMethodOnType requires the method to
650
+ * exist on the type or a supertype it conforms to), so a wrong inference yields no
651
+ * edge rather than a wrong one. Shared by the `::`-receiver languages (PHP, Rust).
652
+ */
653
+ function matchScopedCallChain(ref, context) {
654
+ const m = ref.referenceName.match(/^(.+)\(\)\.(\w+)$/);
655
+ if (!m || !m[1] || !m[2])
656
+ return null;
657
+ const inner = m[1];
658
+ const method = m[2];
659
+ if (!inner.includes('::'))
660
+ return null; // only static-factory (`Cls::method`) chains
661
+ const factoryClass = inner.slice(0, inner.lastIndexOf('::'));
662
+ const ret = lookupCalleeReturnType(inner, ref, context);
663
+ if (!ret)
664
+ return null;
665
+ // `self` (the extractor's marker for self/static/$this) → the factory's class.
666
+ const resolvedClass = ret === 'self' ? factoryClass : ret;
667
+ return resolveMethodOnType(resolvedClass, method, ref, context, 0.85, 'instance-method');
668
+ }
669
+ /**
670
+ * Languages where an unprefixed capitalized call `Foo(args)` constructs the
671
+ * class (so a `Foo(args).method()` receiver's type is `Foo`). Java/C# need `new`,
672
+ * so a bare `Foo()` there is a method call, not construction — excluded. Scala's
673
+ * `Foo(args)` is a case-class / companion `apply`, which conventionally returns
674
+ * `Foo` — and resolveMethodOnType validates, so a non-conventional `apply` that
675
+ * returns another type simply yields no edge rather than a wrong one. Pascal/Delphi:
676
+ * a `TFoo(x)` is a TYPECAST whose result is a `TFoo`, so `TFoo(x).method()` resolves
677
+ * the method on `TFoo` — same shape, same validation.
678
+ */
679
+ const CONSTRUCTS_VIA_BARE_CALL = new Set(['kotlin', 'swift', 'scala', 'dart', 'pascal']);
680
+ /**
681
+ * Resolve a dotted chained call whose receiver is a static factory / fluent call —
682
+ * `Foo.getInstance().bar()`, encoded by the extractor as `Foo.getInstance().bar`
683
+ * (#645/#608 mechanism). The receiver's type is what `Foo.getInstance` returns
684
+ * (its declared return type); the outer method is then resolved and VALIDATED on
685
+ * it (resolveMethodOnType requires `Type::method` to exist), so a wrong inference
686
+ * yields no edge rather than a wrong one (e.g. a same-named `bar()` on an
687
+ * unrelated class is never matched). Shared by the dot-notation languages
688
+ * (Java, Kotlin, C#, Swift) — same receiver shape, same `Class::method` qualified names.
689
+ */
690
+ function matchDottedCallChain(ref, context) {
691
+ const m = ref.referenceName.match(/^(.+)\(\)\.(\w+)$/);
692
+ if (!m || !m[1] || !m[2])
693
+ return null;
694
+ const inner = m[1]; // `Foo.getInstance`
695
+ const method = m[2]; // `bar`
696
+ const lastDot = inner.lastIndexOf('.');
697
+ if (lastDot <= 0) {
698
+ // Go: bare package-level factory FUNCTION `New().method()` — the receiver's
699
+ // type is what `New` returns; resolve the method on that.
700
+ if (ref.language === 'go') {
701
+ const ret = lookupCalleeReturnType(inner, ref, context);
702
+ if (ret) {
703
+ return resolveMethodOnType(ret, method, ref, context, 0.85, 'instance-method', importedFqnOf(ret, ref, context));
704
+ }
705
+ // `inner` isn't a function with a captured return type — typically a
706
+ // package-level VARIABLE holding a function value (e.g. gin's `engine()`),
707
+ // whose type we can't recover. Fall back to bare-name resolution of the
708
+ // method so we don't DROP an edge the un-re-encoded bare path would have
709
+ // found. (When `inner` IS a real factory function but the method doesn't
710
+ // exist on its return type, `ret` is truthy and we returned no edge above —
711
+ // the absent-method safety guarantee is preserved.)
712
+ //
713
+ // CRITICAL: resolve the TARGET via a synthetic bare-name ref, but return the
714
+ // match tied to the ORIGINAL `ref` (referenceName `inner().method`). The
715
+ // batched resolver (resolveAndPersistBatched) reads unresolved rows from
716
+ // offset 0 every pass and relies on deleteSpecificResolvedReferences —
717
+ // keyed on referenceName — to clear each resolved row so the batch empties.
718
+ // If we propagated the synthetic ref's bare `method` as `.original`, the
719
+ // delete would never match the stored `inner().method` row, the batch would
720
+ // never drain, and the loop would re-resolve + re-insert forever (a runaway
721
+ // that grew gin's graph to 5M edges / 1.4 GB before this fix).
722
+ const bareRef = { ...ref, referenceName: method };
723
+ const bareMatch = matchByExactName(bareRef, context) ?? matchFuzzy(bareRef, context);
724
+ return bareMatch ? { ...bareMatch, original: ref } : null;
725
+ }
726
+ // Constructor receiver `Foo(args).method()` (encoded `Foo().method`): a bare,
727
+ // capitalized inner is a class construction, so the receiver's type is the
728
+ // class itself — resolve the method on it. Only in languages where an
729
+ // unprefixed capitalized call constructs the class (Kotlin, Swift); in Java/C#
730
+ // a bare `Foo()` is a method call (constructors need `new`), so we must not
731
+ // assume construction. A lowercase bare inner is a top-level `factory().method()`
732
+ // whose type we can't recover — bail.
733
+ if (!CONSTRUCTS_VIA_BARE_CALL.has(ref.language) || !/^[A-Z]/.test(inner))
734
+ return null;
735
+ return resolveMethodOnType(inner, method, ref, context, 0.85, 'instance-method', importedFqnOf(inner, ref, context));
736
+ }
737
+ // Factory/fluent receiver `Receiver.factory(args).method()`: the receiver's
738
+ // type is what `Receiver.factory` returns (its declared return type).
739
+ const factoryClass = inner.slice(0, lastDot).split('.').pop(); // simple class name
740
+ const factoryMethod = inner.slice(lastDot + 1);
741
+ if (!factoryClass || !factoryMethod)
742
+ return null;
743
+ const ret = lookupCalleeReturnType(`${factoryClass}::${factoryMethod}`, ref, context);
744
+ if (!ret) {
745
+ // Objective-C: a class-message factory — `[X alloc]`, `[X new]`,
746
+ // `[X sharedFoo]` — returns an instance of the RECEIVER class `X` by
747
+ // convention (`instancetype`). So when the factory's own return type isn't
748
+ // recoverable (its selector returns `instancetype`, or `alloc`/`new` aren't
749
+ // user-defined nodes at all), the receiver's type is the class `X` itself.
750
+ // This resolves the ubiquitous `[[X alloc] init]` and singleton chains.
751
+ // resolveMethodOnType validates against X (and its supertypes), so a class
752
+ // whose method actually lives elsewhere yields NO edge, not a wrong one — and
753
+ // crucially this does NOT fire when a concrete return type WAS captured but
754
+ // simply lacks the method (that already returned null above: absent-method
755
+ // safety, so a same-named decoy is still never matched).
756
+ if (ref.language === 'objc' && /^[A-Z]/.test(factoryClass)) {
757
+ return resolveMethodOnType(factoryClass, method, ref, context, 0.8, 'instance-method', importedFqnOf(factoryClass, ref, context));
758
+ }
759
+ // Pascal/Delphi: the extractor only re-encodes a `TFoo`/`IFoo`-prefixed chain
760
+ // (the type-naming convention), so `factoryClass` is always a real class here.
761
+ // A factory whose return type wasn't captured is a CONSTRUCTOR
762
+ // (`TFileMem.Create().SetCachePerformance` — `constructor Create` has no `:
763
+ // TBar` annotation but returns its own class) or an unannotated function. In
764
+ // both cases the receiver's type is the class itself, so resolve the method on
765
+ // `factoryClass`. resolveMethodOnType validates against it (and its
766
+ // supertypes), so a wrong inference yields no edge — and this never fires when
767
+ // a return type WAS captured but lacks the method (absent-method safety above).
768
+ if (ref.language === 'pascal' && /^[TI]/.test(factoryClass)) {
769
+ return resolveMethodOnType(factoryClass, method, ref, context, 0.8, 'instance-method', importedFqnOf(factoryClass, ref, context));
770
+ }
771
+ return null;
772
+ }
773
+ return resolveMethodOnType(ret, method, ref, context, 0.85, 'instance-method', importedFqnOf(ret, ref, context));
774
+ }
775
+ /**
776
+ * When several classes share a simple type name, the caller file's import of
777
+ * that type is the only signal that names WHICH one (#314). Returns the imported
778
+ * FQN for `typeName` in the ref's file, or undefined.
779
+ */
780
+ function importedFqnOf(typeName, ref, context) {
781
+ const imports = context.getImportMappings(ref.filePath, ref.language);
782
+ return imports.find((i) => i.localName === typeName)?.source;
783
+ }
259
784
  /**
260
785
  * Java/Kotlin: infer a receiver's declared type by walking field declarations
261
786
  * in the class enclosing the call site. The field's `signature` is already in
@@ -314,8 +839,16 @@ function inferJavaFieldReceiverType(receiverName, ref, context) {
314
839
  * Try to resolve by method name on a class/object
315
840
  */
316
841
  function matchMethodCall(ref, context) {
317
- // Parse method call patterns like "obj.method" or "Class::method"
318
- const dotMatch = ref.referenceName.match(/^(\w+)\.(\w+)$/);
842
+ // Parse method call patterns like "obj.method" or "Class::method". The method
843
+ // part allows trailing `:` keywords so Objective-C selectors resolve
844
+ // (`SDImageCache.storeImage:`, `obj.setX:y:`); colons never appear in other
845
+ // languages' method refs, so this is a no-op for them.
846
+ // The receiver allows dots (`builder.Services.AddCoreServices`) so a CHAINED
847
+ // call resolves by its last segment — Strategy 3 below name-matches the method
848
+ // (with its existing single-candidate / receiver-overlap guards). Without this
849
+ // a multi-dot extension-method call (C# DI `builder.Services.AddCoreServices()`,
850
+ // `Guard.Against.X()`) matched no pattern and never resolved.
851
+ const dotMatch = ref.referenceName.match(/^([\w.]+)\.(\w+:?(?:\w+:)*)$/);
319
852
  const colonMatch = ref.referenceName.match(/^(\w+)::(\w+)$/);
320
853
  const match = dotMatch || colonMatch;
321
854
  if (!match) {
@@ -550,7 +1083,7 @@ function matchFuzzy(ref, context) {
550
1083
  const candidates = context.getNodesByLowerName(lowerName);
551
1084
  // Filter to callable kinds only (function, method, class)
552
1085
  const callableKinds = new Set(['function', 'method', 'class']);
553
- const callableCandidates = candidates.filter((n) => callableKinds.has(n.kind));
1086
+ const callableCandidates = applyLanguageGate(candidates.filter((n) => callableKinds.has(n.kind)), ref);
554
1087
  // Prefer same-language matches
555
1088
  const sameLanguageCandidates = callableCandidates.filter(n => n.language === ref.language);
556
1089
  const finalCandidates = sameLanguageCandidates.length > 0 ? sameLanguageCandidates : callableCandidates;
@@ -569,6 +1102,12 @@ function matchFuzzy(ref, context) {
569
1102
  * Match all strategies in order of confidence
570
1103
  */
571
1104
  function matchReference(ref, context) {
1105
+ // Function-as-value refs (#756) resolve ONLY through the dedicated matcher —
1106
+ // never the fuzzy/qualified fallthrough below (a wrong callback edge is
1107
+ // worse than none).
1108
+ if (ref.referenceKind === 'function_ref') {
1109
+ return matchFunctionRef(ref, context);
1110
+ }
572
1111
  // Try strategies in order of confidence
573
1112
  let result;
574
1113
  // 0. File path match (e.g., "snippets/drawer-menu.liquid" → file node)
@@ -579,6 +1118,43 @@ function matchReference(ref, context) {
579
1118
  result = matchByQualifiedName(ref, context);
580
1119
  if (result)
581
1120
  return result;
1121
+ // 1b. C++ chained call whose receiver is another call — `Foo::instance().bar()`
1122
+ // encoded as `Foo::instance().bar` by the extractor (#645). Resolve the
1123
+ // receiver's type from what the inner call returns, then the method on it.
1124
+ if (ref.language === 'cpp' || ref.language === 'c') {
1125
+ result = matchCppCallChain(ref, context);
1126
+ if (result)
1127
+ return result;
1128
+ }
1129
+ // 1c. `::`-scoped factory chain — PHP `Cls::for($x)->method()` (#608) or Rust
1130
+ // `Foo::new().bar()`, both encoded as `Cls::factory().method`. The receiver's
1131
+ // type is the factory's `self` (PHP `: self`/`: static`, Rust `-> Self`) or
1132
+ // concrete return type.
1133
+ if (ref.language === 'php' || ref.language === 'rust') {
1134
+ result = matchScopedCallChain(ref, context);
1135
+ if (result)
1136
+ return result;
1137
+ }
1138
+ // 1d. Dotted chained static-factory / fluent call (Java / Kotlin / C# / Swift /
1139
+ // Go / Scala / Dart / Objective-C) — `Foo.getInstance().bar()` encoded as
1140
+ // `Foo.getInstance().bar`, Go's bare-factory `New().Method()` as `New().Method`,
1141
+ // Scala's companion factory, Dart's static factory / factory-constructor, or
1142
+ // ObjC's chained message send `[[Foo create] doIt]` encoded as `Foo.create().doIt`
1143
+ // (#645/#608 mechanism). Resolve the method's class from the inner call's
1144
+ // declared return type, then validate it.
1145
+ if (ref.language === 'java' ||
1146
+ ref.language === 'kotlin' ||
1147
+ ref.language === 'csharp' ||
1148
+ ref.language === 'swift' ||
1149
+ ref.language === 'go' ||
1150
+ ref.language === 'scala' ||
1151
+ ref.language === 'dart' ||
1152
+ ref.language === 'objc' ||
1153
+ ref.language === 'pascal') {
1154
+ result = matchDottedCallChain(ref, context);
1155
+ if (result)
1156
+ return result;
1157
+ }
582
1158
  // 2. Method call pattern
583
1159
  result = matchMethodCall(ref, context);
584
1160
  if (result)