@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.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.
- package/bin/codegraph.cmd +1 -1
- package/lib/dist/bin/codegraph.js +206 -44
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/context/formatter.d.ts +7 -1
- package/lib/dist/context/formatter.d.ts.map +1 -1
- package/lib/dist/context/formatter.js +12 -6
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +12 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +101 -25
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +179 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +368 -7
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +25 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +234 -5
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +687 -53
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +16 -3
- package/lib/dist/db/sqlite-adapter.d.ts +3 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +22 -4
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +15 -2
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +88 -6
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/directory.d.ts +29 -0
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +52 -0
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/extraction/extraction-version.d.ts +1 -1
- package/lib/dist/extraction/extraction-version.js +1 -1
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +6 -0
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.d.ts +48 -12
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +176 -11
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +101 -2
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +138 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +518 -94
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.d.ts +9 -0
- package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/decode.js +162 -0
- package/lib/dist/extraction/kernel/decode.js.map +1 -0
- package/lib/dist/extraction/kernel/index.d.ts +64 -0
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/index.js +279 -0
- package/lib/dist/extraction/kernel/index.js.map +1 -0
- package/lib/dist/extraction/kernel/layout.d.ts +101 -0
- package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/layout.js +104 -0
- package/lib/dist/extraction/kernel/layout.js.map +1 -0
- package/lib/dist/extraction/kernel/loader.d.ts +103 -0
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/loader.js +146 -0
- package/lib/dist/extraction/kernel/loader.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +868 -16
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
- package/lib/dist/extraction/languages/erlang.js +58 -22
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +4 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +47 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +15 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +35 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +35 -1
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +24 -0
- package/lib/dist/extraction/store-worker.d.ts.map +1 -0
- package/lib/dist/extraction/store-worker.js +139 -0
- package/lib/dist/extraction/store-worker.js.map +1 -0
- package/lib/dist/extraction/store-writer.d.ts +63 -0
- package/lib/dist/extraction/store-writer.d.ts.map +1 -0
- package/lib/dist/extraction/store-writer.js +174 -0
- package/lib/dist/extraction/store-writer.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +27 -5
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +257 -56
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -0
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/traversal.js +1 -1
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +36 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +305 -11
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.d.ts +54 -0
- package/lib/dist/installer/beta-signup.d.ts.map +1 -0
- package/lib/dist/installer/beta-signup.js +178 -0
- package/lib/dist/installer/beta-signup.js.map +1 -0
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +19 -6
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +37 -5
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +22 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +65 -48
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-cli.js +209 -0
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.js +219 -0
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +6 -0
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +6 -5
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +99 -20
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +5 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +1 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +6 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +54 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +10 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +51 -3
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +9 -6
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +10 -8
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +3 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +45 -3
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +137 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +236 -0
- package/lib/dist/mcp/explore-dedup.js.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.js +558 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.d.ts +217 -0
- package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +322 -0
- package/lib/dist/mcp/explore-session-state.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +24 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +67 -6
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +3 -1
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +6 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +2 -2
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +8 -3
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +16 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +36 -13
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +276 -10
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +2425 -237
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/project-config.d.ts +23 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +39 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +287 -167
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
- package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/lib/dist/resolution/cooperative-yield.js +6 -4
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +29 -6
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +11 -1
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +184 -9
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +87 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +731 -134
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/memory-budget.d.ts +48 -0
- package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
- package/lib/dist/resolution/memory-budget.js +162 -0
- package/lib/dist/resolution/memory-budget.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +42 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +681 -99
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/path-aliases.d.ts +6 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +125 -17
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/resolver-pool.d.ts +106 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-pool.js +344 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -0
- package/lib/dist/resolution/resolver-worker.d.ts +17 -0
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-worker.js +141 -0
- package/lib/dist/resolution/resolver-worker.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +3 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.d.ts +10 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.js +29 -0
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-paths.d.ts +57 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +298 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +1 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +13 -3
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +47 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +127 -8
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +61 -3
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +27 -1
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.d.ts +21 -0
- package/lib/dist/ui/color.d.ts.map +1 -0
- package/lib/dist/ui/color.js +42 -0
- package/lib/dist/ui/color.js.map +1 -0
- package/lib/dist/ui/glyphs.d.ts +35 -10
- package/lib/dist/ui/glyphs.d.ts.map +1 -1
- package/lib/dist/ui/glyphs.js +59 -12
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +78 -4
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +25 -17
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui/types.d.ts +0 -2
- package/lib/dist/ui/types.d.ts.map +1 -1
- package/lib/dist/upgrade/index.d.ts +7 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +18 -5
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +0 -0
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +6 -1
- package/package.json +6 -2
|
@@ -13,12 +13,18 @@ exports.matchFunctionRef = matchFunctionRef;
|
|
|
13
13
|
exports.matchByExactName = matchByExactName;
|
|
14
14
|
exports.matchByQualifiedName = matchByQualifiedName;
|
|
15
15
|
exports.preferCallSiteFile = preferCallSiteFile;
|
|
16
|
+
exports.resolveObjectLiteralMember = resolveObjectLiteralMember;
|
|
16
17
|
exports.resolveMethodOnType = resolveMethodOnType;
|
|
17
18
|
exports.matchCppCallChain = matchCppCallChain;
|
|
18
19
|
exports.matchScopedCallChain = matchScopedCallChain;
|
|
19
20
|
exports.matchDottedCallChain = matchDottedCallChain;
|
|
21
|
+
exports.normalizeInferredTypeName = normalizeInferredTypeName;
|
|
22
|
+
exports.clearNameMatcherMemos = clearNameMatcherMemos;
|
|
23
|
+
exports.localReceiverTypePatterns = localReceiverTypePatterns;
|
|
20
24
|
exports.matchMethodCall = matchMethodCall;
|
|
25
|
+
exports.rustFieldTypeName = rustFieldTypeName;
|
|
21
26
|
exports.matchFuzzy = matchFuzzy;
|
|
27
|
+
exports.dumpNameMatcherProfile = dumpNameMatcherProfile;
|
|
22
28
|
exports.matchReference = matchReference;
|
|
23
29
|
/**
|
|
24
30
|
* Ceiling on how many same-named definitions a FUZZY name-match strategy will
|
|
@@ -227,6 +233,15 @@ function matchFunctionRef(ref, context) {
|
|
|
227
233
|
ref.language === 'arkts' ||
|
|
228
234
|
ref.language === 'cpp' || ref.language === 'python' ||
|
|
229
235
|
ref.language === 'php';
|
|
236
|
+
// Python additionally accepts CLASS targets for bare identifiers (#1478):
|
|
237
|
+
// class-as-value is a core Python idiom (`return SomeSerializer`,
|
|
238
|
+
// `Meta.model = Org`, registry dicts, `admin.site.register(Model, Admin)`)
|
|
239
|
+
// and, unlike TS, Python has no type-annotation recovery path. The
|
|
240
|
+
// false-positive mechanism behind the function-only rule was lowercase
|
|
241
|
+
// locals colliding with same-named METHODS (docopt.py) — a candidate must
|
|
242
|
+
// be an exact-name CLASS node here, and the extraction gate (same-file
|
|
243
|
+
// class ∪ imports) plus unique-or-drop still apply. Methods stay excluded.
|
|
244
|
+
const bareClassOk = ref.language === 'python';
|
|
230
245
|
// Qualified member-pointer (`&Widget::on_click` → "Widget::on_click"):
|
|
231
246
|
// resolve the member ON THAT SCOPE — exempt from bareFnOnly (the `&Cls::m`
|
|
232
247
|
// shape is an explicit member reference). Unique-or-drop like everything else.
|
|
@@ -255,7 +270,9 @@ function matchFunctionRef(ref, context) {
|
|
|
255
270
|
}
|
|
256
271
|
let candidates = context
|
|
257
272
|
.getNodesByName(ref.referenceName)
|
|
258
|
-
.filter((n) => (n.kind === 'function' ||
|
|
273
|
+
.filter((n) => (n.kind === 'function' ||
|
|
274
|
+
(!bareFnOnly && n.kind === 'method') ||
|
|
275
|
+
(bareClassOk && n.kind === 'class')) &&
|
|
259
276
|
sameLanguageFamily(n.language, ref.language) &&
|
|
260
277
|
n.id !== ref.fromNodeId // a function registering itself is not a dependency edge
|
|
261
278
|
);
|
|
@@ -328,6 +345,35 @@ function matchFunctionRef(ref, context) {
|
|
|
328
345
|
}
|
|
329
346
|
return null;
|
|
330
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* A function nested inside another FUNCTION is only callable from within its
|
|
350
|
+
* container — Python, JS/TS, and every closure language scope it lexically.
|
|
351
|
+
* Resolving a bare name from elsewhere to a nested local fabricates an edge
|
|
352
|
+
* scope already rules out: `join(...)` in one function must never bind to a
|
|
353
|
+
* `join` defined inside a DIFFERENT function (#1230). A candidate whose
|
|
354
|
+
* qualifiedName parent is a same-file function/method is kept only when the
|
|
355
|
+
* ref originates inside that parent's line range. Class members are
|
|
356
|
+
* unaffected (their parent resolves to a class-like node), as are top-level
|
|
357
|
+
* symbols and C++ namespace-prefixed names (the prefix has no node).
|
|
358
|
+
*/
|
|
359
|
+
function isLexicallyReachable(candidate, ref, context) {
|
|
360
|
+
if (candidate.kind !== 'function')
|
|
361
|
+
return true;
|
|
362
|
+
const qn = candidate.qualifiedName;
|
|
363
|
+
if (!qn || !qn.includes('::'))
|
|
364
|
+
return true;
|
|
365
|
+
const parentQn = qn.slice(0, qn.lastIndexOf('::'));
|
|
366
|
+
const containers = context
|
|
367
|
+
.getNodesByQualifiedName(parentQn)
|
|
368
|
+
.filter((p) => p.filePath === candidate.filePath &&
|
|
369
|
+
(p.kind === 'function' || p.kind === 'method') &&
|
|
370
|
+
p.startLine <= candidate.startLine &&
|
|
371
|
+
p.endLine >= candidate.endLine);
|
|
372
|
+
if (containers.length === 0)
|
|
373
|
+
return true;
|
|
374
|
+
return (ref.filePath === candidate.filePath &&
|
|
375
|
+
containers.some((p) => ref.line >= p.startLine && ref.line <= p.endLine));
|
|
376
|
+
}
|
|
331
377
|
/**
|
|
332
378
|
* Try to resolve a reference by exact name match
|
|
333
379
|
*/
|
|
@@ -342,7 +388,9 @@ function matchByExactName(ref, context) {
|
|
|
342
388
|
// findBestMatch — O(K²) per package, the dominant cost of "Resolving refs" on
|
|
343
389
|
// large import-heavy (front-end + back-end) repos (#915).
|
|
344
390
|
const candidates = applyLanguageGate(context.getNodesByName(ref.referenceName), ref)
|
|
345
|
-
.filter((n) => n.kind !== 'import')
|
|
391
|
+
.filter((n) => n.kind !== 'import')
|
|
392
|
+
// Nested locals are only reachable from inside their container (#1230).
|
|
393
|
+
.filter((n) => isLexicallyReachable(n, ref, context));
|
|
346
394
|
if (candidates.length === 0) {
|
|
347
395
|
return null;
|
|
348
396
|
}
|
|
@@ -421,6 +469,32 @@ function matchByQualifiedName(ref, context) {
|
|
|
421
469
|
};
|
|
422
470
|
}
|
|
423
471
|
}
|
|
472
|
+
// Erlang qualified refs (#1610): every erlang function's qualifiedName
|
|
473
|
+
// carries its arity (`mod::f/2`), and refs carry the call-site arity when it
|
|
474
|
+
// is statically known.
|
|
475
|
+
if (ref.language === 'erlang' && ref.referenceName.includes('::')) {
|
|
476
|
+
// A ref WITH arity that missed the exact lookup names an arity that isn't
|
|
477
|
+
// defined (or a module out of repo). Never fall through to the partial
|
|
478
|
+
// match — its "last segment" would be the arity digits — and never settle
|
|
479
|
+
// for a sibling arity: silent beats wrong.
|
|
480
|
+
if (/\/\d{1,3}$/.test(ref.referenceName))
|
|
481
|
+
return null;
|
|
482
|
+
// An arity-LESS qualified ref (dynamic MFA whose args list wasn't a
|
|
483
|
+
// static literal): resolve only when the module defines exactly ONE arity
|
|
484
|
+
// of that function; several arities with no signal is a guess.
|
|
485
|
+
const base = ref.referenceName.slice(ref.referenceName.lastIndexOf('::') + 2);
|
|
486
|
+
const prefix = `${ref.referenceName}/`;
|
|
487
|
+
const arityCands = keepForRef(context.getNodesByName(base)).filter((n) => n.qualifiedName.startsWith(prefix) && /^\d{1,3}$/.test(n.qualifiedName.slice(prefix.length)));
|
|
488
|
+
if (arityCands.length === 1) {
|
|
489
|
+
return {
|
|
490
|
+
original: ref,
|
|
491
|
+
targetNodeId: arityCands[0].id,
|
|
492
|
+
confidence: 0.85,
|
|
493
|
+
resolvedBy: 'qualified-name',
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
424
498
|
// Try partial qualified name match — again preferring the call site's own
|
|
425
499
|
// file when more than one symbol's qualifiedName ends with the reference.
|
|
426
500
|
const parts = ref.referenceName.split(/[:.]/);
|
|
@@ -461,6 +535,82 @@ function preferCallSiteFile(nodes, callSiteFile) {
|
|
|
461
535
|
}
|
|
462
536
|
return same.length ? [...same, ...other] : nodes;
|
|
463
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Languages whose object literals declare callable members — `export const
|
|
540
|
+
* api = { call() {…}, get: () => {…} }` used as a namespace (#1573).
|
|
541
|
+
*/
|
|
542
|
+
const OBJECT_LITERAL_LANGUAGES = new Set(['typescript', 'tsx', 'javascript', 'jsx', 'arkts']);
|
|
543
|
+
/** True when `inner`'s source range lies within `outer`'s (lines, then columns on a shared line). */
|
|
544
|
+
function rangeWithin(inner, outer) {
|
|
545
|
+
const innerEnd = inner.endLine ?? inner.startLine;
|
|
546
|
+
const outerEnd = outer.endLine ?? outer.startLine;
|
|
547
|
+
if (inner.startLine < outer.startLine || innerEnd > outerEnd)
|
|
548
|
+
return false;
|
|
549
|
+
if (inner.startLine === outer.startLine && inner.startColumn < outer.startColumn)
|
|
550
|
+
return false;
|
|
551
|
+
if (innerEnd === outerEnd && inner.endColumn > outer.endColumn)
|
|
552
|
+
return false;
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
function sameRange(a, b) {
|
|
556
|
+
return (a.startLine === b.startLine &&
|
|
557
|
+
a.startColumn === b.startColumn &&
|
|
558
|
+
(a.endLine ?? a.startLine) === (b.endLine ?? b.startLine) &&
|
|
559
|
+
a.endColumn === b.endColumn);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Resolve `container.member` where `container` is a VALUE holding an object
|
|
563
|
+
* literal — `export const api = { call() {…}, get: () => {…} }` used as the
|
|
564
|
+
* module's namespace (#1573). The members are extracted as plain functions
|
|
565
|
+
* with BARE qualified names inside the constant's source extent (there is no
|
|
566
|
+
* `api::call`), so neither the `Container::member` lookup the class-shaped
|
|
567
|
+
* kinds use (#825) nor the declared-type inference for singleton instances
|
|
568
|
+
* (#1292) can reach them, and every such call resolved to nothing — or, via
|
|
569
|
+
* an import, to the constant itself. This looks the member up by CONTAINMENT:
|
|
570
|
+
* a node named `member` whose range lies inside the container's, in the
|
|
571
|
+
* container's own file. A helper declared inside a member's body is not a
|
|
572
|
+
* member and is skipped; nothing else in the file can donate a match. Calls
|
|
573
|
+
* take callable kinds only; other references accept value members too.
|
|
574
|
+
*/
|
|
575
|
+
function resolveObjectLiteralMember(container, member, ref, context, confidence, resolvedBy) {
|
|
576
|
+
if (container.kind !== 'constant' && container.kind !== 'variable')
|
|
577
|
+
return null;
|
|
578
|
+
if (!OBJECT_LITERAL_LANGUAGES.has(container.language))
|
|
579
|
+
return null;
|
|
580
|
+
if (!sameLanguageFamily(container.language, ref.language))
|
|
581
|
+
return null;
|
|
582
|
+
const inFile = context.getNodesInFile(container.filePath);
|
|
583
|
+
const callable = (n) => n.kind === 'function' || n.kind === 'method';
|
|
584
|
+
const valueMember = (n) => callable(n) || n.kind === 'property' || n.kind === 'variable' || n.kind === 'constant';
|
|
585
|
+
const accepts = ref.referenceKind === 'calls' ? callable : valueMember;
|
|
586
|
+
const inside = inFile.filter((n) => n.id !== container.id && rangeWithin(n, container));
|
|
587
|
+
let candidates = inside.filter((n) => n.name === member && accepts(n));
|
|
588
|
+
if (candidates.length === 0)
|
|
589
|
+
return null;
|
|
590
|
+
// Drop a candidate nested inside ANOTHER callable's body within the literal
|
|
591
|
+
// (`{ run() { const call = () => {}; } }` — `call` is `run`'s local, not a
|
|
592
|
+
// member). Strict containment: an identically-ranged sibling node for the
|
|
593
|
+
// same member (a property node over an arrow function) is not a body.
|
|
594
|
+
const bodies = inside.filter(callable);
|
|
595
|
+
candidates = candidates.filter((c) => !bodies.some((b) => b.id !== c.id && !sameRange(b, c) && rangeWithin(c, b)));
|
|
596
|
+
if (candidates.length === 0)
|
|
597
|
+
return null;
|
|
598
|
+
// Several survivors (a property AND a function for one arrow member, say):
|
|
599
|
+
// a callable first, then the earliest in source order.
|
|
600
|
+
candidates.sort((a, b) => {
|
|
601
|
+
const ca = callable(a) ? 0 : 1;
|
|
602
|
+
const cb = callable(b) ? 0 : 1;
|
|
603
|
+
if (ca !== cb)
|
|
604
|
+
return ca - cb;
|
|
605
|
+
return a.startLine - b.startLine || a.startColumn - b.startColumn;
|
|
606
|
+
});
|
|
607
|
+
return {
|
|
608
|
+
original: ref,
|
|
609
|
+
targetNodeId: candidates[0].id,
|
|
610
|
+
confidence,
|
|
611
|
+
resolvedBy,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
464
614
|
// Exported for the precedence unit tests (#1079): they assert the
|
|
465
615
|
// preferredFqn → same-file → matches[0] ordering directly.
|
|
466
616
|
function resolveMethodOnType(typeName, methodName, ref, context, confidence, resolvedBy,
|
|
@@ -513,11 +663,16 @@ depth = 0) {
|
|
|
513
663
|
// populated in the conformance pass. Still VALIDATED (the method must exist on
|
|
514
664
|
// a supertype), so a wrong inference produces no edge.
|
|
515
665
|
if (depth < 4 && context.getSupertypes) {
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
666
|
+
const viaSupers = nmTimedT('rmot-supers', ref, () => {
|
|
667
|
+
for (const supertype of context.getSupertypes(typeName, ref.language)) {
|
|
668
|
+
const via = resolveMethodOnType(supertype, methodName, ref, context, confidence, resolvedBy, preferredFqn, depth + 1);
|
|
669
|
+
if (via)
|
|
670
|
+
return via;
|
|
671
|
+
}
|
|
672
|
+
return null;
|
|
673
|
+
});
|
|
674
|
+
if (viaSupers)
|
|
675
|
+
return viaSupers;
|
|
521
676
|
}
|
|
522
677
|
return null;
|
|
523
678
|
}
|
|
@@ -685,12 +840,12 @@ function lookupCalleeReturnType(callee, ref, context) {
|
|
|
685
840
|
}
|
|
686
841
|
return candidates.find((n) => n.kind === 'function')?.returnType ?? null;
|
|
687
842
|
}
|
|
688
|
-
/** Does the graph contain
|
|
843
|
+
/** Does the graph contain an aggregate type named `name`'s last segment? */
|
|
689
844
|
function cppClassExists(name, ref, context) {
|
|
690
845
|
const last = cppLastSegment(name);
|
|
691
846
|
return context
|
|
692
847
|
.getNodesByName(last)
|
|
693
|
-
.some((n) => (n.kind === 'class' || n.kind === 'struct') && n.language === ref.language);
|
|
848
|
+
.some((n) => (n.kind === 'class' || n.kind === 'struct' || n.kind === 'union') && n.language === ref.language);
|
|
694
849
|
}
|
|
695
850
|
/**
|
|
696
851
|
* Infer the class produced by a C++ call/construction expression, using return
|
|
@@ -839,10 +994,11 @@ function matchDottedCallChain(ref, context) {
|
|
|
839
994
|
// CRITICAL: resolve the TARGET via a synthetic bare-name ref, but return the
|
|
840
995
|
// match tied to the ORIGINAL `ref` (referenceName `inner().method`). The
|
|
841
996
|
// batched resolver (resolveAndPersistBatched) reads unresolved rows from
|
|
842
|
-
// offset 0 every pass and relies on
|
|
843
|
-
//
|
|
844
|
-
//
|
|
845
|
-
//
|
|
997
|
+
// offset 0 every pass and relies on the post-batch cleanup (row-id delete
|
|
998
|
+
// for DB-loaded refs, referenceName-keyed delete otherwise, #1269) to
|
|
999
|
+
// clear each resolved row so the batch empties. If we propagated the
|
|
1000
|
+
// synthetic ref's bare `method` as `.original`, a key-based delete
|
|
1001
|
+
// would never match the stored `inner().method` row, the batch would
|
|
846
1002
|
// never drain, and the loop would re-resolve + re-insert forever (a runaway
|
|
847
1003
|
// that grew gin's graph to 5M edges / 1.4 GB before this fix).
|
|
848
1004
|
const bareRef = { ...ref, referenceName: method };
|
|
@@ -998,7 +1154,50 @@ function normalizeInferredTypeName(raw) {
|
|
|
998
1154
|
* PascalCase is required in the capture where the language convention allows,
|
|
999
1155
|
* as a cheap false-positive guard on top of resolveMethodOnType's validation.
|
|
1000
1156
|
*/
|
|
1157
|
+
/**
|
|
1158
|
+
* Compiled-pattern memo for the receiver-type pattern builders below. They
|
|
1159
|
+
* run for EVERY `receiver.method()` ref the matcher attempts, compiling 2–4
|
|
1160
|
+
* fresh RegExp objects per call — and receivers repeat massively (`self`
|
|
1161
|
+
* alone accounts for tens of thousands of refs on a Lua repo, measured 41µs
|
|
1162
|
+
* per methodCall miss on kong with compilation a large slice). The patterns
|
|
1163
|
+
* are a pure function of (language, receiver) and non-global (`.match()`
|
|
1164
|
+
* never touches lastIndex), so shared instances are behavior-identical.
|
|
1165
|
+
* FIFO-capped with no per-get mutation (the §7a.6 LRU-churn lesson): a hit
|
|
1166
|
+
* costs one Map lookup, overflow evicts oldest, and an evicted entry simply
|
|
1167
|
+
* recompiles exactly as every call did before this memo.
|
|
1168
|
+
*/
|
|
1169
|
+
const PATTERN_MEMO = new Map();
|
|
1170
|
+
const PATTERN_MEMO_CAP = 8192;
|
|
1171
|
+
const INFER_SCAN_STATES = new WeakMap();
|
|
1172
|
+
function getInferScanStates(context) {
|
|
1173
|
+
let m = INFER_SCAN_STATES.get(context);
|
|
1174
|
+
if (!m) {
|
|
1175
|
+
m = new Map();
|
|
1176
|
+
INFER_SCAN_STATES.set(context, m);
|
|
1177
|
+
}
|
|
1178
|
+
return m;
|
|
1179
|
+
}
|
|
1180
|
+
/** Drop the per-context scan states (see ReferenceResolver.clearCaches). */
|
|
1181
|
+
function clearNameMatcherMemos(context) {
|
|
1182
|
+
INFER_SCAN_STATES.delete(context);
|
|
1183
|
+
}
|
|
1184
|
+
function memoPatterns(key, build) {
|
|
1185
|
+
const hit = PATTERN_MEMO.get(key);
|
|
1186
|
+
if (hit)
|
|
1187
|
+
return hit;
|
|
1188
|
+
const patterns = build();
|
|
1189
|
+
if (PATTERN_MEMO.size >= PATTERN_MEMO_CAP) {
|
|
1190
|
+
const oldest = PATTERN_MEMO.keys().next().value;
|
|
1191
|
+
if (oldest !== undefined)
|
|
1192
|
+
PATTERN_MEMO.delete(oldest);
|
|
1193
|
+
}
|
|
1194
|
+
PATTERN_MEMO.set(key, patterns);
|
|
1195
|
+
return patterns;
|
|
1196
|
+
}
|
|
1001
1197
|
function localReceiverTypePatterns(language, r) {
|
|
1198
|
+
return memoPatterns(`${language}|${r}`, () => buildLocalReceiverTypePatterns(language, r));
|
|
1199
|
+
}
|
|
1200
|
+
function buildLocalReceiverTypePatterns(language, r) {
|
|
1002
1201
|
switch (language) {
|
|
1003
1202
|
case 'typescript':
|
|
1004
1203
|
case 'javascript':
|
|
@@ -1241,6 +1440,53 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1241
1440
|
}
|
|
1242
1441
|
return null;
|
|
1243
1442
|
};
|
|
1443
|
+
// Incremental-scan memo (INFER_SCAN_STATES): this scan runs for EVERY
|
|
1444
|
+
// `receiver.method()` ref and was measured at 61µs/ref on kong (2.4s of
|
|
1445
|
+
// worker time, 99% misses — `self:` calls hunting a declaration Lua never
|
|
1446
|
+
// writes). Refs for the same (file, scope, receiver) arrive in ~ascending
|
|
1447
|
+
// line order, and the scan is a pure function of the file's immutable
|
|
1448
|
+
// lines, so each line pays its regex matches ONCE per key instead of once
|
|
1449
|
+
// per ref: query(c) = highest matching line in [startIdx..c]; a monotonic
|
|
1450
|
+
// call extends the stored watermark by scanning only (hi..c] (the region
|
|
1451
|
+
// at-or-below the previous answer is already proven empty above it); a
|
|
1452
|
+
// non-monotonic call (rare — refs are rowid-ordered) falls back to the
|
|
1453
|
+
// plain bounded scan and leaves the state alone. componentScoped is keyed
|
|
1454
|
+
// out — its position-independent whole-file sweep below has different
|
|
1455
|
+
// semantics.
|
|
1456
|
+
if (!componentScoped) {
|
|
1457
|
+
const states = getInferScanStates(context);
|
|
1458
|
+
const key = `${ref.filePath}|${startIdx}|${ref.language}|${scanReceiver}`;
|
|
1459
|
+
const state = states.get(key);
|
|
1460
|
+
if (!state) {
|
|
1461
|
+
for (let i = callIdx; i >= startIdx; i--) {
|
|
1462
|
+
const type = matchLine(i);
|
|
1463
|
+
if (type) {
|
|
1464
|
+
states.set(key, { hi: callIdx, ansIdx: i, ansType: type });
|
|
1465
|
+
return type;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
states.set(key, { hi: callIdx, ansIdx: -1, ansType: null });
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
if (callIdx >= state.hi) {
|
|
1472
|
+
for (let i = callIdx; i > state.hi; i--) {
|
|
1473
|
+
const type = matchLine(i);
|
|
1474
|
+
if (type) {
|
|
1475
|
+
state.ansIdx = i;
|
|
1476
|
+
state.ansType = type;
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
state.hi = callIdx;
|
|
1481
|
+
return state.ansIdx >= startIdx ? state.ansType : null;
|
|
1482
|
+
}
|
|
1483
|
+
for (let i = callIdx; i >= startIdx; i--) {
|
|
1484
|
+
const type = matchLine(i);
|
|
1485
|
+
if (type)
|
|
1486
|
+
return type;
|
|
1487
|
+
}
|
|
1488
|
+
return null;
|
|
1489
|
+
}
|
|
1244
1490
|
// Nearest declaration wins: scan backward from the call to the scope start.
|
|
1245
1491
|
for (let i = callIdx; i >= startIdx; i--) {
|
|
1246
1492
|
const type = matchLine(i);
|
|
@@ -1283,6 +1529,9 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1283
1529
|
* shape is handled by inferPhpAssignedPropertyType instead.
|
|
1284
1530
|
*/
|
|
1285
1531
|
function phpPropertyTypePatterns(r) {
|
|
1532
|
+
return memoPatterns(`php-prop|${r}`, () => buildPhpPropertyTypePatterns(r));
|
|
1533
|
+
}
|
|
1534
|
+
function buildPhpPropertyTypePatterns(r) {
|
|
1286
1535
|
return [
|
|
1287
1536
|
new RegExp(`\\b(?:(?:private|protected|public|readonly|static|final)(?:\\(set\\))?\\s+)+\\??([A-Za-z_\\\\][\\w\\\\]*)\\s+&?\\$${r}\\b`), // private readonly ?Foo $prop (typed property / promoted param)
|
|
1288
1537
|
new RegExp(`\\$this->${r}\\b\\s*=\\s*new\\s+([A-Za-z_\\\\][\\w\\\\]*)`), // $this->prop = new Foo()
|
|
@@ -1362,7 +1611,17 @@ function matchMethodCall(ref, context) {
|
|
|
1362
1611
|
// (with its existing single-candidate / receiver-overlap guards). Without this
|
|
1363
1612
|
// a multi-dot extension-method call (C# DI `builder.Services.AddCoreServices()`,
|
|
1364
1613
|
// `Guard.Against.X()`) matched no pattern and never resolved.
|
|
1365
|
-
|
|
1614
|
+
// C++ explicit operator call `a.operator+(b)` reaches the resolver as
|
|
1615
|
+
// `a.operator+` (#1247) — the operator's symbol chars (`+`, `==`, `[]`, `()`)
|
|
1616
|
+
// fail the \w method part of the plain pattern, so admit them explicitly.
|
|
1617
|
+
// Names like `operatorTable` stay on the plain pattern (tried first); the
|
|
1618
|
+
// operator form requires at least one non-word char after `operator`, and
|
|
1619
|
+
// every downstream strategy compares the method part by exact string
|
|
1620
|
+
// equality, so a stray match can't invent an edge.
|
|
1621
|
+
const dotMatch = ref.referenceName.match(/^([\w.]+)\.(\w+:?(?:\w+:)*)$/) ??
|
|
1622
|
+
(ref.language === 'cpp'
|
|
1623
|
+
? ref.referenceName.match(/^([\w.]+)\.(operator[^\w\s.]+)$/)
|
|
1624
|
+
: null);
|
|
1366
1625
|
const colonMatch = ref.referenceName.match(/^(\w+)::(\w+)$/);
|
|
1367
1626
|
// Lua/Luau method calls use a single colon (`lg:log`); R uses `$` (`lg$log`).
|
|
1368
1627
|
// Recognize these receiver/method separators so local-variable receiver-type
|
|
@@ -1406,9 +1665,9 @@ function matchMethodCall(ref, context) {
|
|
|
1406
1665
|
// shared source-based inferrer. resolveMethodOnType validates the method
|
|
1407
1666
|
// exists on the inferred type, so a mis-inference produces no edge.
|
|
1408
1667
|
if (inferableReceiver) {
|
|
1409
|
-
const inferredType = ref.language === 'cpp'
|
|
1668
|
+
const inferredType = nmTimedT('mc-infer', ref, () => ref.language === 'cpp'
|
|
1410
1669
|
? inferCppReceiverType(objectOrClass, ref, context)
|
|
1411
|
-
: inferLocalReceiverType(objectOrClass, ref, context);
|
|
1670
|
+
: inferLocalReceiverType(objectOrClass, ref, context));
|
|
1412
1671
|
if (inferredType) {
|
|
1413
1672
|
// Java/Kotlin: when two classes share the simple name, the file's import
|
|
1414
1673
|
// pins WHICH one (#314). Other languages disambiguate by call-site file.
|
|
@@ -1417,12 +1676,37 @@ function matchMethodCall(ref, context) {
|
|
|
1417
1676
|
.getImportMappings(ref.filePath, ref.language)
|
|
1418
1677
|
.find((i) => i.localName === inferredType)?.source
|
|
1419
1678
|
: undefined;
|
|
1420
|
-
const typedMatch = resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn);
|
|
1679
|
+
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn));
|
|
1421
1680
|
if (typedMatch) {
|
|
1422
1681
|
return typedMatch;
|
|
1423
1682
|
}
|
|
1424
1683
|
}
|
|
1425
1684
|
}
|
|
1685
|
+
// Go 2-hop field chain `base.field.Method` (#1276): the base's type comes
|
|
1686
|
+
// from the enclosing scope (typed parameter / method receiver / local var),
|
|
1687
|
+
// the field's declared type from that struct's own declaration lines, and
|
|
1688
|
+
// the method is VALIDATED on the field's type by resolveMethodOnType. This
|
|
1689
|
+
// branch is EXCLUSIVE for chained Go receivers: when the hop can't be
|
|
1690
|
+
// inferred or the field's type is external (`conn *sql.DB` — no project
|
|
1691
|
+
// node), the ref stays unresolved rather than falling through to the
|
|
1692
|
+
// bare-name strategies below, which is exactly how `target.conn.Exec(...)`
|
|
1693
|
+
// fabricated a dependency on an unrelated local interface's same-named
|
|
1694
|
+
// method. Chained Go receivers were never emitted before #1276, so there
|
|
1695
|
+
// is no prior recall to preserve on the fallback path.
|
|
1696
|
+
if (ref.language === 'go' && dotMatch && objectOrClass.includes('.')) {
|
|
1697
|
+
return matchGoFieldChainCall(objectOrClass, methodName, ref, context);
|
|
1698
|
+
}
|
|
1699
|
+
// Rust call through a field of the enclosing type — `self.inner.run()`,
|
|
1700
|
+
// emitted as `self.inner.run` (#1585). Same discipline as the Go branch
|
|
1701
|
+
// above, and EXCLUSIVE for the same reason: validated field-type inference
|
|
1702
|
+
// or nothing. Letting this shape reach the bare-name strategies below is
|
|
1703
|
+
// how `self.inner.run()` resolved to a same-named method on an unrelated
|
|
1704
|
+
// type — or to the calling method itself, a self-edge the source doesn't
|
|
1705
|
+
// contain — whenever the field's type was external or merely shared a
|
|
1706
|
+
// method name with something nearby.
|
|
1707
|
+
if (ref.language === 'rust' && dotMatch && objectOrClass.startsWith('self.')) {
|
|
1708
|
+
return matchRustSelfFieldCall(objectOrClass.slice('self.'.length), methodName, ref, context);
|
|
1709
|
+
}
|
|
1426
1710
|
// Java/Kotlin: receiver may be a field whose name doesn't match the type by
|
|
1427
1711
|
// Java naming convention (`userbo` → class `UserBO`, abbreviated). Look up
|
|
1428
1712
|
// the field in the enclosing class to get its declared type, then resolve
|
|
@@ -1436,44 +1720,41 @@ function matchMethodCall(ref, context) {
|
|
|
1436
1720
|
// imported FQN so resolveMethodOnType can disambiguate (#314).
|
|
1437
1721
|
const imports = context.getImportMappings(ref.filePath, ref.language);
|
|
1438
1722
|
const importedFqn = imports.find((i) => i.localName === inferredType)?.source;
|
|
1439
|
-
const typedMatch = resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn);
|
|
1723
|
+
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn));
|
|
1440
1724
|
if (typedMatch) {
|
|
1441
1725
|
return typedMatch;
|
|
1442
1726
|
}
|
|
1443
1727
|
}
|
|
1444
1728
|
}
|
|
1729
|
+
// Object-literal namespace receiver (#1573): `api.call()` where `api` is a
|
|
1730
|
+
// same-file `const api = { call() {…}, get: () => {…} }`. Its members are
|
|
1731
|
+
// plain functions with bare names inside the constant's extent — no
|
|
1732
|
+
// `Container::member` qualified name — so none of the class-shaped
|
|
1733
|
+
// strategies below can see them (Strategy 3 only considers `method`
|
|
1734
|
+
// kinds) and the call resolved to nothing at all. Same file only: a
|
|
1735
|
+
// cross-file use reaches the same helper through the import path.
|
|
1736
|
+
if (dotMatch && !objectOrClass.includes('.') && OBJECT_LITERAL_LANGUAGES.has(ref.language)) {
|
|
1737
|
+
const literalMatch = nmTimedT('mc-literal', ref, () => {
|
|
1738
|
+
const holders = preferCallSiteFile(context.getNodesByName(objectOrClass), ref.filePath).filter((n) => (n.kind === 'constant' || n.kind === 'variable') && n.filePath === ref.filePath);
|
|
1739
|
+
for (const holder of holders) {
|
|
1740
|
+
const hit = resolveObjectLiteralMember(holder, methodName, ref, context, 0.85, 'instance-method');
|
|
1741
|
+
if (hit)
|
|
1742
|
+
return hit;
|
|
1743
|
+
}
|
|
1744
|
+
return null;
|
|
1745
|
+
});
|
|
1746
|
+
if (literalMatch)
|
|
1747
|
+
return literalMatch;
|
|
1748
|
+
}
|
|
1445
1749
|
// Strategy 1: Direct class name match (existing logic). When the receiver
|
|
1446
1750
|
// names a class that exists in several files (`Logger.log()` / `Logger::log()`
|
|
1447
1751
|
// with a `Logger` in both `a/` and `b/`), try the class in the call site's
|
|
1448
1752
|
// own file first — otherwise the first-indexed class wins and a call in `b/`
|
|
1449
1753
|
// resolves to `a/`'s method (#1079).
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
if (classNode.language !== ref.language)
|
|
1455
|
-
continue;
|
|
1456
|
-
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
1457
|
-
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
1458
|
-
n.name === methodName &&
|
|
1459
|
-
n.qualifiedName.includes(classNode.name));
|
|
1460
|
-
if (methodNode) {
|
|
1461
|
-
return {
|
|
1462
|
-
original: ref,
|
|
1463
|
-
targetNodeId: methodNode.id,
|
|
1464
|
-
confidence: 0.85,
|
|
1465
|
-
resolvedBy: 'qualified-name',
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
// Strategy 2: Instance variable receiver - try capitalized form to find class
|
|
1471
|
-
// e.g., "permissionEngine" → look for classes containing "PermissionEngine"
|
|
1472
|
-
const capitalizedReceiver = objectOrClass.charAt(0).toUpperCase() + objectOrClass.slice(1);
|
|
1473
|
-
if (capitalizedReceiver !== objectOrClass) {
|
|
1474
|
-
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver), ref.filePath);
|
|
1475
|
-
for (const classNode of fuzzyClassCandidates) {
|
|
1476
|
-
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'interface') {
|
|
1754
|
+
const strat1 = nmTimedT('mc-class', ref, () => {
|
|
1755
|
+
const classCandidates = preferCallSiteFile(context.getNodesByName(objectOrClass), ref.filePath);
|
|
1756
|
+
for (const classNode of classCandidates) {
|
|
1757
|
+
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'union' || classNode.kind === 'interface') {
|
|
1477
1758
|
// Skip cross-language class matches
|
|
1478
1759
|
if (classNode.language !== ref.language)
|
|
1479
1760
|
continue;
|
|
@@ -1485,67 +1766,288 @@ function matchMethodCall(ref, context) {
|
|
|
1485
1766
|
return {
|
|
1486
1767
|
original: ref,
|
|
1487
1768
|
targetNodeId: methodNode.id,
|
|
1488
|
-
confidence: 0.
|
|
1489
|
-
resolvedBy: '
|
|
1769
|
+
confidence: 0.85,
|
|
1770
|
+
resolvedBy: 'qualified-name',
|
|
1490
1771
|
};
|
|
1491
1772
|
}
|
|
1492
1773
|
}
|
|
1493
1774
|
}
|
|
1775
|
+
return null;
|
|
1776
|
+
});
|
|
1777
|
+
if (strat1)
|
|
1778
|
+
return strat1;
|
|
1779
|
+
// Strategy 2: Instance variable receiver - try capitalized form to find class
|
|
1780
|
+
// e.g., "permissionEngine" → look for classes containing "PermissionEngine"
|
|
1781
|
+
const capitalizedReceiver = objectOrClass.charAt(0).toUpperCase() + objectOrClass.slice(1);
|
|
1782
|
+
if (capitalizedReceiver !== objectOrClass) {
|
|
1783
|
+
const strat2 = nmTimedT('mc-capital', ref, () => {
|
|
1784
|
+
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver), ref.filePath);
|
|
1785
|
+
for (const classNode of fuzzyClassCandidates) {
|
|
1786
|
+
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'union' || classNode.kind === 'interface') {
|
|
1787
|
+
// Skip cross-language class matches
|
|
1788
|
+
if (classNode.language !== ref.language)
|
|
1789
|
+
continue;
|
|
1790
|
+
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
1791
|
+
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
1792
|
+
n.name === methodName &&
|
|
1793
|
+
n.qualifiedName.includes(classNode.name));
|
|
1794
|
+
if (methodNode) {
|
|
1795
|
+
return {
|
|
1796
|
+
original: ref,
|
|
1797
|
+
targetNodeId: methodNode.id,
|
|
1798
|
+
confidence: 0.8,
|
|
1799
|
+
resolvedBy: 'instance-method',
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
return null;
|
|
1805
|
+
});
|
|
1806
|
+
if (strat2)
|
|
1807
|
+
return strat2;
|
|
1494
1808
|
}
|
|
1495
1809
|
// Strategy 3: Find methods by name across the codebase, match by receiver
|
|
1496
1810
|
// name similarity with the containing class. Handles abbreviated variable
|
|
1497
1811
|
// names like permissionEngine → PermissionRuleEngine.
|
|
1498
1812
|
if (methodName) {
|
|
1499
|
-
const
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
const methods = methodCandidates.filter((n) => n.kind === 'method' && n.name === methodName);
|
|
1510
|
-
// Filter to same-language candidates first
|
|
1511
|
-
const sameLanguageMethods = methods.filter(m => m.language === ref.language);
|
|
1512
|
-
const targetMethods = sameLanguageMethods.length > 0 ? sameLanguageMethods : methods;
|
|
1513
|
-
// If only one same-language method with this name exists, use it
|
|
1514
|
-
if (targetMethods.length === 1 && targetMethods[0].language === ref.language) {
|
|
1515
|
-
return {
|
|
1516
|
-
original: ref,
|
|
1517
|
-
targetNodeId: targetMethods[0].id,
|
|
1518
|
-
confidence: 0.7,
|
|
1519
|
-
resolvedBy: 'instance-method',
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
|
-
// Multiple methods: score by receiver name word overlap with class name
|
|
1523
|
-
if (targetMethods.length > 1) {
|
|
1524
|
-
const receiverWords = splitCamelCase(objectOrClass);
|
|
1525
|
-
let bestMatch;
|
|
1526
|
-
let bestScore = 0;
|
|
1527
|
-
// Same-file candidates first, so a score tie (`score > bestScore` keeps
|
|
1528
|
-
// the first seen) resolves to the call site's own file rather than the
|
|
1529
|
-
// first-indexed duplicate (#1079).
|
|
1530
|
-
for (const method of preferCallSiteFile(targetMethods, ref.filePath)) {
|
|
1531
|
-
const classWords = splitCamelCase(method.qualifiedName);
|
|
1532
|
-
let score = receiverWords.filter(w => classWords.some(cw => cw.toLowerCase() === w.toLowerCase())).length;
|
|
1533
|
-
// Bonus for same language
|
|
1534
|
-
if (method.language === ref.language)
|
|
1535
|
-
score += 1;
|
|
1536
|
-
if (score > bestScore) {
|
|
1537
|
-
bestScore = score;
|
|
1538
|
-
bestMatch = method;
|
|
1539
|
-
}
|
|
1813
|
+
const strat3 = nmTimedT('mc-byname', ref, () => {
|
|
1814
|
+
const methodCandidates = context.getNodesByName(methodName);
|
|
1815
|
+
// Ubiquitous-method ceiling (#999): a method name re-declared across a
|
|
1816
|
+
// vendored theme/SDK (Metronic's `init`/`update`/… on every widget) yields
|
|
1817
|
+
// K candidates that receiver-word overlap can't reliably disambiguate —
|
|
1818
|
+
// and filtering + scoring all K per call is the O(K²) cost that wedged
|
|
1819
|
+
// "Resolving refs" for 15-28 min. Bail before the O(K) work; Strategy 1/2
|
|
1820
|
+
// (class-name match) already had their precise shot above.
|
|
1821
|
+
if (methodCandidates.length > AMBIGUOUS_NAME_CEILING) {
|
|
1822
|
+
return null;
|
|
1540
1823
|
}
|
|
1541
|
-
|
|
1824
|
+
const methods = methodCandidates.filter((n) => n.kind === 'method' && n.name === methodName);
|
|
1825
|
+
// Filter to same-language candidates first
|
|
1826
|
+
const sameLanguageMethods = methods.filter(m => m.language === ref.language);
|
|
1827
|
+
const targetMethods = sameLanguageMethods.length > 0 ? sameLanguageMethods : methods;
|
|
1828
|
+
// If only one same-language method with this name exists, use it
|
|
1829
|
+
if (targetMethods.length === 1 && targetMethods[0].language === ref.language) {
|
|
1542
1830
|
return {
|
|
1543
1831
|
original: ref,
|
|
1544
|
-
targetNodeId:
|
|
1545
|
-
confidence: 0.
|
|
1832
|
+
targetNodeId: targetMethods[0].id,
|
|
1833
|
+
confidence: 0.7,
|
|
1546
1834
|
resolvedBy: 'instance-method',
|
|
1547
1835
|
};
|
|
1548
1836
|
}
|
|
1837
|
+
// Multiple methods: score by receiver name word overlap with class name
|
|
1838
|
+
if (targetMethods.length > 1) {
|
|
1839
|
+
const receiverWords = splitCamelCase(objectOrClass);
|
|
1840
|
+
let bestMatch;
|
|
1841
|
+
let bestScore = 0;
|
|
1842
|
+
// Same-file candidates first, so a score tie (`score > bestScore` keeps
|
|
1843
|
+
// the first seen) resolves to the call site's own file rather than the
|
|
1844
|
+
// first-indexed duplicate (#1079).
|
|
1845
|
+
for (const method of preferCallSiteFile(targetMethods, ref.filePath)) {
|
|
1846
|
+
const classWords = splitCamelCase(method.qualifiedName);
|
|
1847
|
+
let score = receiverWords.filter(w => classWords.some(cw => cw.toLowerCase() === w.toLowerCase())).length;
|
|
1848
|
+
// Bonus for same language
|
|
1849
|
+
if (method.language === ref.language)
|
|
1850
|
+
score += 1;
|
|
1851
|
+
if (score > bestScore) {
|
|
1852
|
+
bestScore = score;
|
|
1853
|
+
bestMatch = method;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
if (bestMatch && bestScore >= 2) {
|
|
1857
|
+
return {
|
|
1858
|
+
original: ref,
|
|
1859
|
+
targetNodeId: bestMatch.id,
|
|
1860
|
+
confidence: 0.65,
|
|
1861
|
+
resolvedBy: 'instance-method',
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return null;
|
|
1866
|
+
});
|
|
1867
|
+
if (strat3)
|
|
1868
|
+
return strat3;
|
|
1869
|
+
}
|
|
1870
|
+
return null;
|
|
1871
|
+
}
|
|
1872
|
+
/** Go builtin/primitive field types that can never carry a project method. */
|
|
1873
|
+
const GO_BUILTIN_FIELD_TYPES = new Set([
|
|
1874
|
+
'string', 'bool', 'byte', 'rune', 'error', 'any',
|
|
1875
|
+
'int', 'int8', 'int16', 'int32', 'int64',
|
|
1876
|
+
'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uintptr',
|
|
1877
|
+
'float32', 'float64', 'complex64', 'complex128',
|
|
1878
|
+
'chan', 'map', 'func', 'struct', 'interface',
|
|
1879
|
+
]);
|
|
1880
|
+
/**
|
|
1881
|
+
* Resolve a Go 2-hop field-chain call `base.field.Method(...)` (#1276):
|
|
1882
|
+
* `target.conn.Exec("insert")` where `func (target *Target) Write()` and
|
|
1883
|
+
* `type Target struct { conn *sql.DB }`. Two inference hops, both read from
|
|
1884
|
+
* source the same way #1108 does:
|
|
1885
|
+
* 1. `base`'s type from the enclosing scope (method receiver, typed
|
|
1886
|
+
* parameter, or local declaration) via inferLocalReceiverType;
|
|
1887
|
+
* 2. `field`'s declared type from the struct's own declaration lines.
|
|
1888
|
+
* The method is then resolved AND VALIDATED on the field's type. A field
|
|
1889
|
+
* whose type has no project node (`sql.DB`, any external dependency) yields
|
|
1890
|
+
* null — the caller treats this branch as exclusive for chained Go
|
|
1891
|
+
* receivers, so the ref stays unresolved instead of name-guessing.
|
|
1892
|
+
*/
|
|
1893
|
+
function matchGoFieldChainCall(receiverChain, methodName, ref, context) {
|
|
1894
|
+
const segs = receiverChain.split('.');
|
|
1895
|
+
if (segs.length !== 2 || !segs[0] || !segs[1])
|
|
1896
|
+
return null;
|
|
1897
|
+
const [base, field] = segs;
|
|
1898
|
+
const baseType = inferLocalReceiverType(base, ref, context);
|
|
1899
|
+
if (!baseType)
|
|
1900
|
+
return null;
|
|
1901
|
+
const fieldEsc = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1902
|
+
const fieldTypeRe = new RegExp(`\\b${fieldEsc}\\s+\\*?\\[?\\]?([A-Za-z_][\\w.]*)`);
|
|
1903
|
+
const structs = preferCallSiteFile(context.getNodesByName(baseType), ref.filePath).filter((n) => (n.kind === 'struct' || n.kind === 'class') && n.language === 'go');
|
|
1904
|
+
for (const s of structs) {
|
|
1905
|
+
const source = context.readFile(s.filePath);
|
|
1906
|
+
if (!source)
|
|
1907
|
+
continue;
|
|
1908
|
+
// Only the struct's own declaration lines — a same-named identifier
|
|
1909
|
+
// elsewhere in the file can't donate a type. Matched LINE BY LINE with
|
|
1910
|
+
// comments stripped: chi's `Mux` has a doc comment reading "the tree
|
|
1911
|
+
// router" right above `tree *node`, and a whole-block match captured
|
|
1912
|
+
// `router` from the prose instead of `node` from the field.
|
|
1913
|
+
const declLines = source.split('\n').slice(Math.max(0, s.startLine - 1), s.endLine);
|
|
1914
|
+
for (const rawLine of declLines) {
|
|
1915
|
+
const line = rawLine.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '');
|
|
1916
|
+
const m = line.match(fieldTypeRe);
|
|
1917
|
+
if (!m || !m[1])
|
|
1918
|
+
continue;
|
|
1919
|
+
const rawType = m[1];
|
|
1920
|
+
// A package-qualified field type (`http.Handler`, `sql.DB`) is only
|
|
1921
|
+
// followed when the package is IN-MODULE: stripping the qualifier and
|
|
1922
|
+
// matching the bare name would conflate a stdlib/third-party type with
|
|
1923
|
+
// any same-named project type — on chi, `handler http.Handler` bound
|
|
1924
|
+
// to an example app's unrelated local `Handler`. That is the exact
|
|
1925
|
+
// fabrication this matcher exists to prevent (#1276).
|
|
1926
|
+
if (rawType.includes('.')) {
|
|
1927
|
+
const pkg = rawType.split('.')[0];
|
|
1928
|
+
const mod = context.getGoModule?.();
|
|
1929
|
+
const imp = context
|
|
1930
|
+
.getImportMappings(s.filePath, 'go')
|
|
1931
|
+
.find((i) => i.localName === pkg);
|
|
1932
|
+
const inModule = !!mod &&
|
|
1933
|
+
!!imp &&
|
|
1934
|
+
(imp.source === mod.modulePath || imp.source.startsWith(mod.modulePath + '/'));
|
|
1935
|
+
if (!inModule)
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
// Unexported (lowercase) types are idiomatic Go and stay eligible —
|
|
1939
|
+
// chi's `mx.tree.FindRoute()` chains through `tree *node`. A
|
|
1940
|
+
// mis-capture is harmless: resolveMethodOnType only returns a
|
|
1941
|
+
// validated `<type>::<method>` match.
|
|
1942
|
+
const fieldType = rawType.split('.').pop();
|
|
1943
|
+
if (!fieldType || !/^[A-Za-z_]/.test(fieldType) || GO_BUILTIN_FIELD_TYPES.has(fieldType))
|
|
1944
|
+
continue;
|
|
1945
|
+
const resolved = resolveMethodOnType(fieldType, methodName, ref, context, 0.85, 'instance-method');
|
|
1946
|
+
if (resolved)
|
|
1947
|
+
return resolved;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
return null;
|
|
1951
|
+
}
|
|
1952
|
+
// Rust primitives and the prelude's own types: a field of one of these never
|
|
1953
|
+
// names a project type, so a `self.<field>.<method>()` on it stays unresolved.
|
|
1954
|
+
const RUST_NON_PROJECT_FIELD_TYPES = new Set([
|
|
1955
|
+
'bool', 'char', 'str', 'String',
|
|
1956
|
+
'i8', 'i16', 'i32', 'i64', 'i128', 'isize',
|
|
1957
|
+
'u8', 'u16', 'u32', 'u64', 'u128', 'usize',
|
|
1958
|
+
'f32', 'f64',
|
|
1959
|
+
'Self', 'self',
|
|
1960
|
+
]);
|
|
1961
|
+
/**
|
|
1962
|
+
* Reduce a Rust field's declared type text to the simple name of the type a
|
|
1963
|
+
* method call on that field auto-derefs to, or null when there is none we can
|
|
1964
|
+
* name. Only the layers Rust's method-call auto-deref looks through are
|
|
1965
|
+
* unwrapped: references (`&`, `&'a mut`) and the owning smart pointers
|
|
1966
|
+
* (`Box`, `Rc`, `Arc`) — `self.inner.run()` with `inner: Box<Inner>` calls
|
|
1967
|
+
* `Inner::run`. Containers that do NOT auto-deref to their parameter
|
|
1968
|
+
* (`Option<Inner>`, `Vec<Inner>`, `Mutex<Inner>`, `RefCell<Inner>`) keep their
|
|
1969
|
+
* own name and, having no project node, resolve to nothing — `self.items.push()`
|
|
1970
|
+
* must never become `Inner::push`. A trait object (`Box<dyn Source>`) yields
|
|
1971
|
+
* the trait, whose method node the interface-impl synthesizer fans out. A
|
|
1972
|
+
* generic parameter (`T`), a primitive, a tuple / array / raw pointer / fn
|
|
1973
|
+
* type, or a non-identifier yields null.
|
|
1974
|
+
*/
|
|
1975
|
+
function rustFieldTypeName(raw) {
|
|
1976
|
+
let t = raw.trim();
|
|
1977
|
+
for (;;) {
|
|
1978
|
+
const before = t;
|
|
1979
|
+
t = t.replace(/^&\s*(?:'\w+\s+)?(?:mut\s+)?/, '');
|
|
1980
|
+
t = t.replace(/^(?:Box|Rc|Arc)\s*<\s*/, '');
|
|
1981
|
+
t = t.replace(/^(?:dyn|impl)\s+/, '');
|
|
1982
|
+
if (t === before)
|
|
1983
|
+
break;
|
|
1984
|
+
}
|
|
1985
|
+
// Drop generic args, the closing `>`s of unwrapped pointers, and trait-object
|
|
1986
|
+
// bounds (`dyn Source + Send`); keep the last path segment.
|
|
1987
|
+
t = t.replace(/[<>+].*$/, '').trim();
|
|
1988
|
+
const seg = t.split('::').filter(Boolean).pop();
|
|
1989
|
+
if (!seg || !/^[A-Za-z_]\w*$/.test(seg))
|
|
1990
|
+
return null;
|
|
1991
|
+
if (RUST_NON_PROJECT_FIELD_TYPES.has(seg))
|
|
1992
|
+
return null;
|
|
1993
|
+
if (/^[A-Z]$/.test(seg))
|
|
1994
|
+
return null; // bare single-letter generic parameter
|
|
1995
|
+
return seg;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Resolve a Rust call through a field of the enclosing type —
|
|
1999
|
+
* `self.inner.run()`, emitted by the extractor as `self.inner.run` (#1585).
|
|
2000
|
+
* Mirrors the Go 2-hop precedent above (#1276): the owner type is the calling
|
|
2001
|
+
* method's qualified-name prefix (`Outer::run` → `Outer`), the field's declared
|
|
2002
|
+
* type comes from the owner struct's OWN declaration lines, and the method is
|
|
2003
|
+
* resolved AND VALIDATED on that type by resolveMethodOnType. The caller
|
|
2004
|
+
* treats this branch as exclusive for `self.<field>` receivers: a field whose
|
|
2005
|
+
* type is external (`std::vec::IntoIter`, `regex::Regex`), a generic
|
|
2006
|
+
* parameter, or not declared where we can see it yields null and the ref stays
|
|
2007
|
+
* unresolved. Rust struct fields are not graph nodes, so the declaration text
|
|
2008
|
+
* is the only place the type lives.
|
|
2009
|
+
*/
|
|
2010
|
+
function matchRustSelfFieldCall(field, methodName, ref, context) {
|
|
2011
|
+
// The extractor only ever emits a single field hop; anything else is not ours.
|
|
2012
|
+
if (!field || field.includes('.'))
|
|
2013
|
+
return null;
|
|
2014
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
2015
|
+
if (!caller)
|
|
2016
|
+
return null;
|
|
2017
|
+
const sep = caller.qualifiedName.lastIndexOf('::');
|
|
2018
|
+
if (sep <= 0)
|
|
2019
|
+
return null; // a free fn has no `self`
|
|
2020
|
+
const owner = caller.qualifiedName.slice(0, sep).split('::').pop();
|
|
2021
|
+
if (!owner)
|
|
2022
|
+
return null;
|
|
2023
|
+
const owners = preferCallSiteFile(context.getNodesByName(owner), ref.filePath).filter((n) => (n.kind === 'struct' || n.kind === 'union' || n.kind === 'class') &&
|
|
2024
|
+
n.language === 'rust');
|
|
2025
|
+
const fieldEsc = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2026
|
+
// `pub inner: Inner,` / `inner: Box<dyn Source>,` / `pub(crate) inner: T }` —
|
|
2027
|
+
// the type text runs to the field separator. A comma inside generic args
|
|
2028
|
+
// (`HashMap<K, V>`) truncates the capture, which rustFieldTypeName then
|
|
2029
|
+
// reduces to the container's own name — exactly the non-deref case it
|
|
2030
|
+
// refuses anyway.
|
|
2031
|
+
const fieldRe = new RegExp(`\\b${fieldEsc}\\s*:\\s*([^,{}]+)`);
|
|
2032
|
+
for (const s of owners) {
|
|
2033
|
+
const source = context.readFile(s.filePath);
|
|
2034
|
+
if (!source)
|
|
2035
|
+
continue;
|
|
2036
|
+
// Only the struct's own declaration lines, comment-stripped line by line —
|
|
2037
|
+
// same discipline as the Go helper: prose or a same-named identifier
|
|
2038
|
+
// elsewhere in the file can never donate a type.
|
|
2039
|
+
const declLines = source.split('\n').slice(Math.max(0, s.startLine - 1), s.endLine);
|
|
2040
|
+
for (const rawLine of declLines) {
|
|
2041
|
+
const line = rawLine.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '');
|
|
2042
|
+
const m = line.match(fieldRe);
|
|
2043
|
+
if (!m || !m[1])
|
|
2044
|
+
continue;
|
|
2045
|
+
const fieldType = rustFieldTypeName(m[1]);
|
|
2046
|
+
// The field is declared here; whether or not its type names a project
|
|
2047
|
+
// symbol, this owner is the answer — no other same-named struct applies.
|
|
2048
|
+
if (!fieldType)
|
|
2049
|
+
return null;
|
|
2050
|
+
return resolveMethodOnType(fieldType, methodName, ref, context, 0.85, 'instance-method');
|
|
1549
2051
|
}
|
|
1550
2052
|
}
|
|
1551
2053
|
return null;
|
|
@@ -1648,6 +2150,7 @@ function findBestMatch(ref, candidates, _context) {
|
|
|
1648
2150
|
if (ref.referenceKind === 'instantiates') {
|
|
1649
2151
|
if (candidate.kind === 'class' ||
|
|
1650
2152
|
candidate.kind === 'struct' ||
|
|
2153
|
+
candidate.kind === 'union' ||
|
|
1651
2154
|
candidate.kind === 'interface') {
|
|
1652
2155
|
score += 25;
|
|
1653
2156
|
}
|
|
@@ -1708,6 +2211,45 @@ function matchFuzzy(ref, context) {
|
|
|
1708
2211
|
*/
|
|
1709
2212
|
/** ArkUI attribute-helper decorators a `.attr(...)` chain may resolve to. */
|
|
1710
2213
|
const ARKUI_ATTRIBUTE_DECORATORS = new Set(['Extend', 'Styles', 'AnimatableExtend', 'Builder']);
|
|
2214
|
+
/**
|
|
2215
|
+
* CODEGRAPH_RESOLVE_PROFILE=2 sub-stage attribution for matchReference's
|
|
2216
|
+
* strategy pipeline (`nm:<stage>|<refKind>|hit/miss`). Module-global because
|
|
2217
|
+
* the matcher is a free function; each thread (main + every pool worker) has
|
|
2218
|
+
* its own module instance, and dumpNameMatcherProfile is invoked from
|
|
2219
|
+
* ReferenceResolver.dumpResolveProfile so worker tables surface too.
|
|
2220
|
+
*/
|
|
2221
|
+
const NM_PROFILE = process.env.CODEGRAPH_RESOLVE_PROFILE === '2' ? new Map() : null;
|
|
2222
|
+
function nmTimedT(stage, ref, fn) {
|
|
2223
|
+
if (!NM_PROFILE)
|
|
2224
|
+
return fn();
|
|
2225
|
+
const t0 = process.hrtime.bigint();
|
|
2226
|
+
const r = fn();
|
|
2227
|
+
const dt = process.hrtime.bigint() - t0;
|
|
2228
|
+
const key = `nm:${stage}|${ref.referenceKind}|${r ? 'hit' : 'miss'}`;
|
|
2229
|
+
const slot = NM_PROFILE.get(key);
|
|
2230
|
+
if (slot) {
|
|
2231
|
+
slot.n++;
|
|
2232
|
+
slot.ns += dt;
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
NM_PROFILE.set(key, { n: 1, ns: dt });
|
|
2236
|
+
}
|
|
2237
|
+
return r;
|
|
2238
|
+
}
|
|
2239
|
+
function nmTimed(stage, ref, fn) {
|
|
2240
|
+
return nmTimedT(stage, ref, fn);
|
|
2241
|
+
}
|
|
2242
|
+
/** Dump this thread's matchReference sub-stage table to stderr (no-op unless =2). */
|
|
2243
|
+
function dumpNameMatcherProfile(label) {
|
|
2244
|
+
if (!NM_PROFILE || NM_PROFILE.size === 0)
|
|
2245
|
+
return;
|
|
2246
|
+
const rows = [...NM_PROFILE.entries()]
|
|
2247
|
+
.map(([k, v]) => ({ k, n: v.n, ms: Number(v.ns / 1000000n) }))
|
|
2248
|
+
.sort((a, b) => b.ms - a.ms);
|
|
2249
|
+
for (const r of rows) {
|
|
2250
|
+
console.error(`[resolve-profile] ${label} ${r.k}: n=${r.n} total=${(r.ms / 1000).toFixed(1)}s avg=${((r.ms * 1000) / Math.max(1, r.n)).toFixed(0)}µs`);
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
1711
2253
|
function matchReference(ref, context) {
|
|
1712
2254
|
// Function-as-value refs (#756) resolve ONLY through the dedicated matcher —
|
|
1713
2255
|
// never the fuzzy/qualified fallthrough below (a wrong callback edge is
|
|
@@ -1766,21 +2308,61 @@ function matchReference(ref, context) {
|
|
|
1766
2308
|
resolvedBy: 'exact-match',
|
|
1767
2309
|
};
|
|
1768
2310
|
}
|
|
2311
|
+
// Erlang call/fun refs carry the call-site arity (`f/1` — #1610) because
|
|
2312
|
+
// arity is part of the function's identity and every erlang function's
|
|
2313
|
+
// qualifiedName carries it (`mod::f/1`). Resolve ONLY to a definition of
|
|
2314
|
+
// that exact arity: the call site's own file first (a local call targets its
|
|
2315
|
+
// own module by language semantics; `-import`ed functions ride the
|
|
2316
|
+
// cross-file branch), and when no definition of that arity exists anywhere,
|
|
2317
|
+
// resolve to NOTHING rather than a sibling arity — the real target may be
|
|
2318
|
+
// macro-generated or out of repo, and a wrong-arity edge is worse than none.
|
|
2319
|
+
if (ref.language === 'erlang' &&
|
|
2320
|
+
!ref.referenceName.includes('::') &&
|
|
2321
|
+
(ref.referenceKind === 'calls' || ref.referenceKind === 'references')) {
|
|
2322
|
+
const am = /^(.+)\/(\d{1,3})$/.exec(ref.referenceName);
|
|
2323
|
+
if (am) {
|
|
2324
|
+
// endsWith is length-anchored, so `/1` cannot match `…/11`.
|
|
2325
|
+
const arityTail = `/${am[2]}`;
|
|
2326
|
+
const candidates = context
|
|
2327
|
+
.getNodesByName(am[1])
|
|
2328
|
+
.filter((n) => n.language === 'erlang' && n.kind === 'function' && n.qualifiedName.endsWith(arityTail));
|
|
2329
|
+
if (candidates.length > 0) {
|
|
2330
|
+
const sameFile = candidates.find((n) => n.filePath === ref.filePath);
|
|
2331
|
+
if (sameFile) {
|
|
2332
|
+
return { original: ref, targetNodeId: sameFile.id, confidence: 0.95, resolvedBy: 'exact-match' };
|
|
2333
|
+
}
|
|
2334
|
+
if (candidates.length === 1) {
|
|
2335
|
+
return { original: ref, targetNodeId: candidates[0].id, confidence: 0.8, resolvedBy: 'exact-match' };
|
|
2336
|
+
}
|
|
2337
|
+
const best = findBestMatch(ref, candidates, context);
|
|
2338
|
+
if (best) {
|
|
2339
|
+
const proximity = computePathProximity(ref.filePath, best.filePath);
|
|
2340
|
+
return {
|
|
2341
|
+
original: ref,
|
|
2342
|
+
targetNodeId: best.id,
|
|
2343
|
+
confidence: proximity >= 30 ? 0.7 : 0.4,
|
|
2344
|
+
resolvedBy: 'exact-match',
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return null;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
1769
2351
|
// Try strategies in order of confidence
|
|
1770
2352
|
let result;
|
|
1771
2353
|
// 0. File path match (e.g., "snippets/drawer-menu.liquid" → file node)
|
|
1772
|
-
result = matchByFilePath(ref, context);
|
|
2354
|
+
result = nmTimed('filePath', ref, () => matchByFilePath(ref, context));
|
|
1773
2355
|
if (result)
|
|
1774
2356
|
return result;
|
|
1775
2357
|
// 1. Qualified name match (highest confidence)
|
|
1776
|
-
result = matchByQualifiedName(ref, context);
|
|
2358
|
+
result = nmTimed('qualifiedName', ref, () => matchByQualifiedName(ref, context));
|
|
1777
2359
|
if (result)
|
|
1778
2360
|
return result;
|
|
1779
2361
|
// 1b. C++ chained call whose receiver is another call — `Foo::instance().bar()`
|
|
1780
2362
|
// encoded as `Foo::instance().bar` by the extractor (#645). Resolve the
|
|
1781
2363
|
// receiver's type from what the inner call returns, then the method on it.
|
|
1782
2364
|
if (ref.language === 'cpp' || ref.language === 'c') {
|
|
1783
|
-
result = matchCppCallChain(ref, context);
|
|
2365
|
+
result = nmTimed('cppChain', ref, () => matchCppCallChain(ref, context));
|
|
1784
2366
|
if (result)
|
|
1785
2367
|
return result;
|
|
1786
2368
|
}
|
|
@@ -1789,7 +2371,7 @@ function matchReference(ref, context) {
|
|
|
1789
2371
|
// type is the factory's `self` (PHP `: self`/`: static`, Rust `-> Self`) or
|
|
1790
2372
|
// concrete return type.
|
|
1791
2373
|
if (ref.language === 'php' || ref.language === 'rust') {
|
|
1792
|
-
result = matchScopedCallChain(ref, context);
|
|
2374
|
+
result = nmTimed('scopedChain', ref, () => matchScopedCallChain(ref, context));
|
|
1793
2375
|
if (result)
|
|
1794
2376
|
return result;
|
|
1795
2377
|
}
|
|
@@ -1809,20 +2391,20 @@ function matchReference(ref, context) {
|
|
|
1809
2391
|
ref.language === 'dart' ||
|
|
1810
2392
|
ref.language === 'objc' ||
|
|
1811
2393
|
ref.language === 'pascal') {
|
|
1812
|
-
result = matchDottedCallChain(ref, context);
|
|
2394
|
+
result = nmTimed('dottedChain', ref, () => matchDottedCallChain(ref, context));
|
|
1813
2395
|
if (result)
|
|
1814
2396
|
return result;
|
|
1815
2397
|
}
|
|
1816
2398
|
// 2. Method call pattern
|
|
1817
|
-
result = matchMethodCall(ref, context);
|
|
2399
|
+
result = nmTimed('methodCall', ref, () => matchMethodCall(ref, context));
|
|
1818
2400
|
if (result)
|
|
1819
2401
|
return result;
|
|
1820
2402
|
// 3. Exact name match
|
|
1821
|
-
result = matchByExactName(ref, context);
|
|
2403
|
+
result = nmTimed('exactName', ref, () => matchByExactName(ref, context));
|
|
1822
2404
|
if (result)
|
|
1823
2405
|
return result;
|
|
1824
2406
|
// 4. Fuzzy match (lowest confidence)
|
|
1825
|
-
result = matchFuzzy(ref, context);
|
|
2407
|
+
result = nmTimed('fuzzy', ref, () => matchFuzzy(ref, context));
|
|
1826
2408
|
if (result)
|
|
1827
2409
|
return result;
|
|
1828
2410
|
return null;
|