@colbymchenry/codegraph-win32-arm64 1.4.0 → 1.5.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 +106 -19
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/command-supervision.d.ts +38 -1
- package/lib/dist/bin/command-supervision.d.ts.map +1 -1
- package/lib/dist/bin/command-supervision.js +8 -2
- package/lib/dist/bin/command-supervision.js.map +1 -1
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +41 -11
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +142 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +267 -6
- 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 +31 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +113 -4
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +398 -24
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +13 -1
- 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/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +63 -0
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +32 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +313 -56
- 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 +849 -12
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +8 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +15 -0
- 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.d.ts +22 -4
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +151 -6
- 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/index.d.ts +19 -6
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +233 -17
- 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 +42 -0
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +105 -1
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +8 -0
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +18 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +73 -13
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.js +1 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +14 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +22 -1
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +76 -1
- package/lib/dist/mcp/tools.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 +574 -132
- 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 +249 -157
- 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/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +166 -7
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +97 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +783 -124
- 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 +12 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +517 -96
- package/lib/dist/resolution/name-matcher.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/sync/watcher.d.ts +25 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +76 -3
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +41 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +26 -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 +39 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +180 -19
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/dist/upgrade/remove-binary.d.ts +87 -0
- package/lib/dist/upgrade/remove-binary.d.ts.map +1 -0
- package/lib/dist/upgrade/remove-binary.js +289 -0
- package/lib/dist/upgrade/remove-binary.js.map +1 -0
- package/lib/dist/upgrade/update-check.d.ts +92 -0
- package/lib/dist/upgrade/update-check.d.ts.map +1 -0
- package/lib/dist/upgrade/update-check.js +258 -0
- package/lib/dist/upgrade/update-check.js.map +1 -0
- 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
|
@@ -17,8 +17,12 @@ exports.resolveMethodOnType = resolveMethodOnType;
|
|
|
17
17
|
exports.matchCppCallChain = matchCppCallChain;
|
|
18
18
|
exports.matchScopedCallChain = matchScopedCallChain;
|
|
19
19
|
exports.matchDottedCallChain = matchDottedCallChain;
|
|
20
|
+
exports.normalizeInferredTypeName = normalizeInferredTypeName;
|
|
21
|
+
exports.clearNameMatcherMemos = clearNameMatcherMemos;
|
|
22
|
+
exports.localReceiverTypePatterns = localReceiverTypePatterns;
|
|
20
23
|
exports.matchMethodCall = matchMethodCall;
|
|
21
24
|
exports.matchFuzzy = matchFuzzy;
|
|
25
|
+
exports.dumpNameMatcherProfile = dumpNameMatcherProfile;
|
|
22
26
|
exports.matchReference = matchReference;
|
|
23
27
|
/**
|
|
24
28
|
* Ceiling on how many same-named definitions a FUZZY name-match strategy will
|
|
@@ -328,6 +332,35 @@ function matchFunctionRef(ref, context) {
|
|
|
328
332
|
}
|
|
329
333
|
return null;
|
|
330
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* A function nested inside another FUNCTION is only callable from within its
|
|
337
|
+
* container — Python, JS/TS, and every closure language scope it lexically.
|
|
338
|
+
* Resolving a bare name from elsewhere to a nested local fabricates an edge
|
|
339
|
+
* scope already rules out: `join(...)` in one function must never bind to a
|
|
340
|
+
* `join` defined inside a DIFFERENT function (#1230). A candidate whose
|
|
341
|
+
* qualifiedName parent is a same-file function/method is kept only when the
|
|
342
|
+
* ref originates inside that parent's line range. Class members are
|
|
343
|
+
* unaffected (their parent resolves to a class-like node), as are top-level
|
|
344
|
+
* symbols and C++ namespace-prefixed names (the prefix has no node).
|
|
345
|
+
*/
|
|
346
|
+
function isLexicallyReachable(candidate, ref, context) {
|
|
347
|
+
if (candidate.kind !== 'function')
|
|
348
|
+
return true;
|
|
349
|
+
const qn = candidate.qualifiedName;
|
|
350
|
+
if (!qn || !qn.includes('::'))
|
|
351
|
+
return true;
|
|
352
|
+
const parentQn = qn.slice(0, qn.lastIndexOf('::'));
|
|
353
|
+
const containers = context
|
|
354
|
+
.getNodesByQualifiedName(parentQn)
|
|
355
|
+
.filter((p) => p.filePath === candidate.filePath &&
|
|
356
|
+
(p.kind === 'function' || p.kind === 'method') &&
|
|
357
|
+
p.startLine <= candidate.startLine &&
|
|
358
|
+
p.endLine >= candidate.endLine);
|
|
359
|
+
if (containers.length === 0)
|
|
360
|
+
return true;
|
|
361
|
+
return (ref.filePath === candidate.filePath &&
|
|
362
|
+
containers.some((p) => ref.line >= p.startLine && ref.line <= p.endLine));
|
|
363
|
+
}
|
|
331
364
|
/**
|
|
332
365
|
* Try to resolve a reference by exact name match
|
|
333
366
|
*/
|
|
@@ -342,7 +375,9 @@ function matchByExactName(ref, context) {
|
|
|
342
375
|
// findBestMatch — O(K²) per package, the dominant cost of "Resolving refs" on
|
|
343
376
|
// large import-heavy (front-end + back-end) repos (#915).
|
|
344
377
|
const candidates = applyLanguageGate(context.getNodesByName(ref.referenceName), ref)
|
|
345
|
-
.filter((n) => n.kind !== 'import')
|
|
378
|
+
.filter((n) => n.kind !== 'import')
|
|
379
|
+
// Nested locals are only reachable from inside their container (#1230).
|
|
380
|
+
.filter((n) => isLexicallyReachable(n, ref, context));
|
|
346
381
|
if (candidates.length === 0) {
|
|
347
382
|
return null;
|
|
348
383
|
}
|
|
@@ -513,11 +548,16 @@ depth = 0) {
|
|
|
513
548
|
// populated in the conformance pass. Still VALIDATED (the method must exist on
|
|
514
549
|
// a supertype), so a wrong inference produces no edge.
|
|
515
550
|
if (depth < 4 && context.getSupertypes) {
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
551
|
+
const viaSupers = nmTimedT('rmot-supers', ref, () => {
|
|
552
|
+
for (const supertype of context.getSupertypes(typeName, ref.language)) {
|
|
553
|
+
const via = resolveMethodOnType(supertype, methodName, ref, context, confidence, resolvedBy, preferredFqn, depth + 1);
|
|
554
|
+
if (via)
|
|
555
|
+
return via;
|
|
556
|
+
}
|
|
557
|
+
return null;
|
|
558
|
+
});
|
|
559
|
+
if (viaSupers)
|
|
560
|
+
return viaSupers;
|
|
521
561
|
}
|
|
522
562
|
return null;
|
|
523
563
|
}
|
|
@@ -839,10 +879,11 @@ function matchDottedCallChain(ref, context) {
|
|
|
839
879
|
// CRITICAL: resolve the TARGET via a synthetic bare-name ref, but return the
|
|
840
880
|
// match tied to the ORIGINAL `ref` (referenceName `inner().method`). The
|
|
841
881
|
// batched resolver (resolveAndPersistBatched) reads unresolved rows from
|
|
842
|
-
// offset 0 every pass and relies on
|
|
843
|
-
//
|
|
844
|
-
//
|
|
845
|
-
//
|
|
882
|
+
// offset 0 every pass and relies on the post-batch cleanup (row-id delete
|
|
883
|
+
// for DB-loaded refs, referenceName-keyed delete otherwise, #1269) to
|
|
884
|
+
// clear each resolved row so the batch empties. If we propagated the
|
|
885
|
+
// synthetic ref's bare `method` as `.original`, a key-based delete
|
|
886
|
+
// would never match the stored `inner().method` row, the batch would
|
|
846
887
|
// never drain, and the loop would re-resolve + re-insert forever (a runaway
|
|
847
888
|
// that grew gin's graph to 5M edges / 1.4 GB before this fix).
|
|
848
889
|
const bareRef = { ...ref, referenceName: method };
|
|
@@ -998,7 +1039,50 @@ function normalizeInferredTypeName(raw) {
|
|
|
998
1039
|
* PascalCase is required in the capture where the language convention allows,
|
|
999
1040
|
* as a cheap false-positive guard on top of resolveMethodOnType's validation.
|
|
1000
1041
|
*/
|
|
1042
|
+
/**
|
|
1043
|
+
* Compiled-pattern memo for the receiver-type pattern builders below. They
|
|
1044
|
+
* run for EVERY `receiver.method()` ref the matcher attempts, compiling 2–4
|
|
1045
|
+
* fresh RegExp objects per call — and receivers repeat massively (`self`
|
|
1046
|
+
* alone accounts for tens of thousands of refs on a Lua repo, measured 41µs
|
|
1047
|
+
* per methodCall miss on kong with compilation a large slice). The patterns
|
|
1048
|
+
* are a pure function of (language, receiver) and non-global (`.match()`
|
|
1049
|
+
* never touches lastIndex), so shared instances are behavior-identical.
|
|
1050
|
+
* FIFO-capped with no per-get mutation (the §7a.6 LRU-churn lesson): a hit
|
|
1051
|
+
* costs one Map lookup, overflow evicts oldest, and an evicted entry simply
|
|
1052
|
+
* recompiles exactly as every call did before this memo.
|
|
1053
|
+
*/
|
|
1054
|
+
const PATTERN_MEMO = new Map();
|
|
1055
|
+
const PATTERN_MEMO_CAP = 8192;
|
|
1056
|
+
const INFER_SCAN_STATES = new WeakMap();
|
|
1057
|
+
function getInferScanStates(context) {
|
|
1058
|
+
let m = INFER_SCAN_STATES.get(context);
|
|
1059
|
+
if (!m) {
|
|
1060
|
+
m = new Map();
|
|
1061
|
+
INFER_SCAN_STATES.set(context, m);
|
|
1062
|
+
}
|
|
1063
|
+
return m;
|
|
1064
|
+
}
|
|
1065
|
+
/** Drop the per-context scan states (see ReferenceResolver.clearCaches). */
|
|
1066
|
+
function clearNameMatcherMemos(context) {
|
|
1067
|
+
INFER_SCAN_STATES.delete(context);
|
|
1068
|
+
}
|
|
1069
|
+
function memoPatterns(key, build) {
|
|
1070
|
+
const hit = PATTERN_MEMO.get(key);
|
|
1071
|
+
if (hit)
|
|
1072
|
+
return hit;
|
|
1073
|
+
const patterns = build();
|
|
1074
|
+
if (PATTERN_MEMO.size >= PATTERN_MEMO_CAP) {
|
|
1075
|
+
const oldest = PATTERN_MEMO.keys().next().value;
|
|
1076
|
+
if (oldest !== undefined)
|
|
1077
|
+
PATTERN_MEMO.delete(oldest);
|
|
1078
|
+
}
|
|
1079
|
+
PATTERN_MEMO.set(key, patterns);
|
|
1080
|
+
return patterns;
|
|
1081
|
+
}
|
|
1001
1082
|
function localReceiverTypePatterns(language, r) {
|
|
1083
|
+
return memoPatterns(`${language}|${r}`, () => buildLocalReceiverTypePatterns(language, r));
|
|
1084
|
+
}
|
|
1085
|
+
function buildLocalReceiverTypePatterns(language, r) {
|
|
1002
1086
|
switch (language) {
|
|
1003
1087
|
case 'typescript':
|
|
1004
1088
|
case 'javascript':
|
|
@@ -1185,7 +1269,29 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1185
1269
|
componentScoped = scope === 'variables' || scope === 'this';
|
|
1186
1270
|
}
|
|
1187
1271
|
}
|
|
1188
|
-
|
|
1272
|
+
// PHP `$this->prop` receiver — the property's declaration lives outside the
|
|
1273
|
+
// calling method (a promoted constructor parameter `private readonly Foo $prop`,
|
|
1274
|
+
// a typed property `private Foo $prop;`, or a classic constructor parameter
|
|
1275
|
+
// `Foo $prop` assigned in __construct). Strip the prefix and widen the scan to
|
|
1276
|
+
// the whole file (the constructor may sit below the calling method), but —
|
|
1277
|
+
// unlike CFML's scopes above — switch to PROPERTY-shaped patterns: a plain
|
|
1278
|
+
// `$prop` local or parameter lives in a different namespace than `$this->prop`
|
|
1279
|
+
// and can never shadow it, so the generic local patterns would type the
|
|
1280
|
+
// property from unrelated same-named variables in other methods (a wrong
|
|
1281
|
+
// 0.9-confidence edge, not a missing one).
|
|
1282
|
+
let phpProperty = false;
|
|
1283
|
+
if (ref.language === 'php') {
|
|
1284
|
+
const scoped = receiverName.match(/^this->(.+)$/);
|
|
1285
|
+
if (scoped) {
|
|
1286
|
+
scanReceiver = scoped[1];
|
|
1287
|
+
componentScoped = true;
|
|
1288
|
+
phpProperty = true;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
const escapedReceiver = scanReceiver.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1292
|
+
const patterns = phpProperty
|
|
1293
|
+
? phpPropertyTypePatterns(escapedReceiver)
|
|
1294
|
+
: localReceiverTypePatterns(ref.language, escapedReceiver);
|
|
1189
1295
|
if (patterns.length === 0)
|
|
1190
1296
|
return null;
|
|
1191
1297
|
// Split through the context's per-file lines cache when available: this runs
|
|
@@ -1219,6 +1325,53 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1219
1325
|
}
|
|
1220
1326
|
return null;
|
|
1221
1327
|
};
|
|
1328
|
+
// Incremental-scan memo (INFER_SCAN_STATES): this scan runs for EVERY
|
|
1329
|
+
// `receiver.method()` ref and was measured at 61µs/ref on kong (2.4s of
|
|
1330
|
+
// worker time, 99% misses — `self:` calls hunting a declaration Lua never
|
|
1331
|
+
// writes). Refs for the same (file, scope, receiver) arrive in ~ascending
|
|
1332
|
+
// line order, and the scan is a pure function of the file's immutable
|
|
1333
|
+
// lines, so each line pays its regex matches ONCE per key instead of once
|
|
1334
|
+
// per ref: query(c) = highest matching line in [startIdx..c]; a monotonic
|
|
1335
|
+
// call extends the stored watermark by scanning only (hi..c] (the region
|
|
1336
|
+
// at-or-below the previous answer is already proven empty above it); a
|
|
1337
|
+
// non-monotonic call (rare — refs are rowid-ordered) falls back to the
|
|
1338
|
+
// plain bounded scan and leaves the state alone. componentScoped is keyed
|
|
1339
|
+
// out — its position-independent whole-file sweep below has different
|
|
1340
|
+
// semantics.
|
|
1341
|
+
if (!componentScoped) {
|
|
1342
|
+
const states = getInferScanStates(context);
|
|
1343
|
+
const key = `${ref.filePath}|${startIdx}|${ref.language}|${scanReceiver}`;
|
|
1344
|
+
const state = states.get(key);
|
|
1345
|
+
if (!state) {
|
|
1346
|
+
for (let i = callIdx; i >= startIdx; i--) {
|
|
1347
|
+
const type = matchLine(i);
|
|
1348
|
+
if (type) {
|
|
1349
|
+
states.set(key, { hi: callIdx, ansIdx: i, ansType: type });
|
|
1350
|
+
return type;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
states.set(key, { hi: callIdx, ansIdx: -1, ansType: null });
|
|
1354
|
+
return null;
|
|
1355
|
+
}
|
|
1356
|
+
if (callIdx >= state.hi) {
|
|
1357
|
+
for (let i = callIdx; i > state.hi; i--) {
|
|
1358
|
+
const type = matchLine(i);
|
|
1359
|
+
if (type) {
|
|
1360
|
+
state.ansIdx = i;
|
|
1361
|
+
state.ansType = type;
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
state.hi = callIdx;
|
|
1366
|
+
return state.ansIdx >= startIdx ? state.ansType : null;
|
|
1367
|
+
}
|
|
1368
|
+
for (let i = callIdx; i >= startIdx; i--) {
|
|
1369
|
+
const type = matchLine(i);
|
|
1370
|
+
if (type)
|
|
1371
|
+
return type;
|
|
1372
|
+
}
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1222
1375
|
// Nearest declaration wins: scan backward from the call to the scope start.
|
|
1223
1376
|
for (let i = callIdx; i >= startIdx; i--) {
|
|
1224
1377
|
const type = matchLine(i);
|
|
@@ -1236,6 +1389,98 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1236
1389
|
return type;
|
|
1237
1390
|
}
|
|
1238
1391
|
}
|
|
1392
|
+
// A PHP property with no statically-typed declaration (classic pre-7.4
|
|
1393
|
+
// style) may still be typed by what gets ASSIGNED to it — follow the
|
|
1394
|
+
// `$this->prop = $var` assignment to the assigned variable's own typed
|
|
1395
|
+
// declaration (a classic or multi-line constructor parameter, or a typed
|
|
1396
|
+
// setter's parameter).
|
|
1397
|
+
if (phpProperty) {
|
|
1398
|
+
return inferPhpAssignedPropertyType(escapedReceiver, lines, callIdx);
|
|
1399
|
+
}
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Patterns that recover a PHP class property's declared type for a
|
|
1404
|
+
* `$this->prop` receiver. Deliberately NOT localReceiverTypePatterns: only
|
|
1405
|
+
* property-shaped declarations qualify —
|
|
1406
|
+
* 1. a modifier-prefixed typed declaration, which covers both a typed
|
|
1407
|
+
* property (`private ?Foo $prop;`) and a promoted constructor parameter
|
|
1408
|
+
* (`private readonly Foo $prop`), and
|
|
1409
|
+
* 2. the pseudoconstructor assignment (`$this->prop = new Foo(...)`).
|
|
1410
|
+
* A bare `X $prop` parameter or `$prop = new X()` local elsewhere in the
|
|
1411
|
+
* file must NOT match: those variables can never alias `$this->prop`.
|
|
1412
|
+
* Union-typed properties (`Foo|Bar $prop`) yield no match and thus no edge —
|
|
1413
|
+
* silent beats wrong. The classic untyped-property-assigned-in-constructor
|
|
1414
|
+
* shape is handled by inferPhpAssignedPropertyType instead.
|
|
1415
|
+
*/
|
|
1416
|
+
function phpPropertyTypePatterns(r) {
|
|
1417
|
+
return memoPatterns(`php-prop|${r}`, () => buildPhpPropertyTypePatterns(r));
|
|
1418
|
+
}
|
|
1419
|
+
function buildPhpPropertyTypePatterns(r) {
|
|
1420
|
+
return [
|
|
1421
|
+
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)
|
|
1422
|
+
new RegExp(`\\$this->${r}\\b\\s*=\\s*new\\s+([A-Za-z_\\\\][\\w\\\\]*)`), // $this->prop = new Foo()
|
|
1423
|
+
];
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Second-chance typing for a PHP `$this->prop` receiver whose property
|
|
1427
|
+
* declaration carries no static type (classic pre-7.4 style): find the
|
|
1428
|
+
* `$this->prop = $var` assignment, then recover `$var`'s type from its own
|
|
1429
|
+
* declaration WITHIN the assignment's function — the constructor's (possibly
|
|
1430
|
+
* multi-line) parameter list, a typed setter's parameter, or a `= new X()`
|
|
1431
|
+
* local. The backward scan stops at the enclosing `function` line (checked
|
|
1432
|
+
* for a match first — a single-line `__construct(Foo $var) { ... }` carries
|
|
1433
|
+
* the typed parameter itself), so a same-named variable in another method
|
|
1434
|
+
* can never type the property.
|
|
1435
|
+
*/
|
|
1436
|
+
function inferPhpAssignedPropertyType(escapedProp, lines, callIdx) {
|
|
1437
|
+
const assignRe = new RegExp(`\\$this->${escapedProp}\\b\\s*=\\s*\\$(\\w+)\\b`);
|
|
1438
|
+
const assignAt = (i) => {
|
|
1439
|
+
const line = lines[i];
|
|
1440
|
+
if (!line || line.length > 10_000)
|
|
1441
|
+
return null;
|
|
1442
|
+
return line.match(assignRe);
|
|
1443
|
+
};
|
|
1444
|
+
// The assignment is position-independent relative to the call — nearest-
|
|
1445
|
+
// backward first, then sweep forward, same order as the componentScoped scan.
|
|
1446
|
+
let assignIdx = -1;
|
|
1447
|
+
let varName = null;
|
|
1448
|
+
for (let i = callIdx; i >= 0; i--) {
|
|
1449
|
+
const m = assignAt(i);
|
|
1450
|
+
if (m) {
|
|
1451
|
+
assignIdx = i;
|
|
1452
|
+
varName = m[1];
|
|
1453
|
+
break;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (varName === null) {
|
|
1457
|
+
for (let i = callIdx + 1; i < lines.length; i++) {
|
|
1458
|
+
const m = assignAt(i);
|
|
1459
|
+
if (m) {
|
|
1460
|
+
assignIdx = i;
|
|
1461
|
+
varName = m[1];
|
|
1462
|
+
break;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (varName === null)
|
|
1467
|
+
return null;
|
|
1468
|
+
const varPatterns = localReceiverTypePatterns('php', varName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
1469
|
+
for (let i = assignIdx; i >= 0; i--) {
|
|
1470
|
+
const line = lines[i];
|
|
1471
|
+
if (line && line.length <= 10_000) {
|
|
1472
|
+
for (const re of varPatterns) {
|
|
1473
|
+
const m = line.match(re);
|
|
1474
|
+
if (m && m[1]) {
|
|
1475
|
+
const type = normalizeInferredTypeName(m[1]);
|
|
1476
|
+
if (type)
|
|
1477
|
+
return type;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (line && /\bfunction\b/.test(line))
|
|
1482
|
+
break;
|
|
1483
|
+
}
|
|
1239
1484
|
return null;
|
|
1240
1485
|
}
|
|
1241
1486
|
/**
|
|
@@ -1251,7 +1496,17 @@ function matchMethodCall(ref, context) {
|
|
|
1251
1496
|
// (with its existing single-candidate / receiver-overlap guards). Without this
|
|
1252
1497
|
// a multi-dot extension-method call (C# DI `builder.Services.AddCoreServices()`,
|
|
1253
1498
|
// `Guard.Against.X()`) matched no pattern and never resolved.
|
|
1254
|
-
|
|
1499
|
+
// C++ explicit operator call `a.operator+(b)` reaches the resolver as
|
|
1500
|
+
// `a.operator+` (#1247) — the operator's symbol chars (`+`, `==`, `[]`, `()`)
|
|
1501
|
+
// fail the \w method part of the plain pattern, so admit them explicitly.
|
|
1502
|
+
// Names like `operatorTable` stay on the plain pattern (tried first); the
|
|
1503
|
+
// operator form requires at least one non-word char after `operator`, and
|
|
1504
|
+
// every downstream strategy compares the method part by exact string
|
|
1505
|
+
// equality, so a stray match can't invent an edge.
|
|
1506
|
+
const dotMatch = ref.referenceName.match(/^([\w.]+)\.(\w+:?(?:\w+:)*)$/) ??
|
|
1507
|
+
(ref.language === 'cpp'
|
|
1508
|
+
? ref.referenceName.match(/^([\w.]+)\.(operator[^\w\s.]+)$/)
|
|
1509
|
+
: null);
|
|
1255
1510
|
const colonMatch = ref.referenceName.match(/^(\w+)::(\w+)$/);
|
|
1256
1511
|
// Lua/Luau method calls use a single colon (`lg:log`); R uses `$` (`lg$log`).
|
|
1257
1512
|
// Recognize these receiver/method separators so local-variable receiver-type
|
|
@@ -1263,6 +1518,24 @@ function matchMethodCall(ref, context) {
|
|
|
1263
1518
|
const rDollarMatch = ref.language === 'r'
|
|
1264
1519
|
? ref.referenceName.match(/^([\w.]+)\$(\w+)$/)
|
|
1265
1520
|
: null;
|
|
1521
|
+
// PHP property receiver: `$this->prop->method()` reaches the resolver as
|
|
1522
|
+
// `this->prop.method` (the extractor records the receiver's raw text with the
|
|
1523
|
+
// leading `$` stripped). Resolve it EXCLUSIVELY through declared-type
|
|
1524
|
+
// inference + resolveMethodOnType validation — the name-similarity strategies
|
|
1525
|
+
// below must never see this shape, so a property whose type can't be
|
|
1526
|
+
// recovered stays unlinked rather than guessed (a wrong inference produces no
|
|
1527
|
+
// edge rather than a wrong one). Deeper chains (`this->a->b.method`) don't
|
|
1528
|
+
// match the single-property pattern and stay unlinked, same as before.
|
|
1529
|
+
const phpThisPropMatch = ref.language === 'php'
|
|
1530
|
+
? ref.referenceName.match(/^(this->\w+)\.(\w+)$/)
|
|
1531
|
+
: null;
|
|
1532
|
+
if (phpThisPropMatch) {
|
|
1533
|
+
const [, receiver, phpMethodName] = phpThisPropMatch;
|
|
1534
|
+
const inferredType = inferLocalReceiverType(receiver, ref, context);
|
|
1535
|
+
if (!inferredType)
|
|
1536
|
+
return null;
|
|
1537
|
+
return resolveMethodOnType(inferredType, phpMethodName, ref, context, 0.9, 'instance-method', importedFqnOf(inferredType, ref, context));
|
|
1538
|
+
}
|
|
1266
1539
|
const match = dotMatch || colonMatch || luaColonMatch || rDollarMatch;
|
|
1267
1540
|
if (!match) {
|
|
1268
1541
|
return null;
|
|
@@ -1277,9 +1550,9 @@ function matchMethodCall(ref, context) {
|
|
|
1277
1550
|
// shared source-based inferrer. resolveMethodOnType validates the method
|
|
1278
1551
|
// exists on the inferred type, so a mis-inference produces no edge.
|
|
1279
1552
|
if (inferableReceiver) {
|
|
1280
|
-
const inferredType = ref.language === 'cpp'
|
|
1553
|
+
const inferredType = nmTimedT('mc-infer', ref, () => ref.language === 'cpp'
|
|
1281
1554
|
? inferCppReceiverType(objectOrClass, ref, context)
|
|
1282
|
-
: inferLocalReceiverType(objectOrClass, ref, context);
|
|
1555
|
+
: inferLocalReceiverType(objectOrClass, ref, context));
|
|
1283
1556
|
if (inferredType) {
|
|
1284
1557
|
// Java/Kotlin: when two classes share the simple name, the file's import
|
|
1285
1558
|
// pins WHICH one (#314). Other languages disambiguate by call-site file.
|
|
@@ -1288,12 +1561,26 @@ function matchMethodCall(ref, context) {
|
|
|
1288
1561
|
.getImportMappings(ref.filePath, ref.language)
|
|
1289
1562
|
.find((i) => i.localName === inferredType)?.source
|
|
1290
1563
|
: undefined;
|
|
1291
|
-
const typedMatch = resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn);
|
|
1564
|
+
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn));
|
|
1292
1565
|
if (typedMatch) {
|
|
1293
1566
|
return typedMatch;
|
|
1294
1567
|
}
|
|
1295
1568
|
}
|
|
1296
1569
|
}
|
|
1570
|
+
// Go 2-hop field chain `base.field.Method` (#1276): the base's type comes
|
|
1571
|
+
// from the enclosing scope (typed parameter / method receiver / local var),
|
|
1572
|
+
// the field's declared type from that struct's own declaration lines, and
|
|
1573
|
+
// the method is VALIDATED on the field's type by resolveMethodOnType. This
|
|
1574
|
+
// branch is EXCLUSIVE for chained Go receivers: when the hop can't be
|
|
1575
|
+
// inferred or the field's type is external (`conn *sql.DB` — no project
|
|
1576
|
+
// node), the ref stays unresolved rather than falling through to the
|
|
1577
|
+
// bare-name strategies below, which is exactly how `target.conn.Exec(...)`
|
|
1578
|
+
// fabricated a dependency on an unrelated local interface's same-named
|
|
1579
|
+
// method. Chained Go receivers were never emitted before #1276, so there
|
|
1580
|
+
// is no prior recall to preserve on the fallback path.
|
|
1581
|
+
if (ref.language === 'go' && dotMatch && objectOrClass.includes('.')) {
|
|
1582
|
+
return matchGoFieldChainCall(objectOrClass, methodName, ref, context);
|
|
1583
|
+
}
|
|
1297
1584
|
// Java/Kotlin: receiver may be a field whose name doesn't match the type by
|
|
1298
1585
|
// Java naming convention (`userbo` → class `UserBO`, abbreviated). Look up
|
|
1299
1586
|
// the field in the enclosing class to get its declared type, then resolve
|
|
@@ -1307,7 +1594,7 @@ function matchMethodCall(ref, context) {
|
|
|
1307
1594
|
// imported FQN so resolveMethodOnType can disambiguate (#314).
|
|
1308
1595
|
const imports = context.getImportMappings(ref.filePath, ref.language);
|
|
1309
1596
|
const importedFqn = imports.find((i) => i.localName === inferredType)?.source;
|
|
1310
|
-
const typedMatch = resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn);
|
|
1597
|
+
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn));
|
|
1311
1598
|
if (typedMatch) {
|
|
1312
1599
|
return typedMatch;
|
|
1313
1600
|
}
|
|
@@ -1318,32 +1605,9 @@ function matchMethodCall(ref, context) {
|
|
|
1318
1605
|
// with a `Logger` in both `a/` and `b/`), try the class in the call site's
|
|
1319
1606
|
// own file first — otherwise the first-indexed class wins and a call in `b/`
|
|
1320
1607
|
// resolves to `a/`'s method (#1079).
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
// Skip cross-language class matches
|
|
1325
|
-
if (classNode.language !== ref.language)
|
|
1326
|
-
continue;
|
|
1327
|
-
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
1328
|
-
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
1329
|
-
n.name === methodName &&
|
|
1330
|
-
n.qualifiedName.includes(classNode.name));
|
|
1331
|
-
if (methodNode) {
|
|
1332
|
-
return {
|
|
1333
|
-
original: ref,
|
|
1334
|
-
targetNodeId: methodNode.id,
|
|
1335
|
-
confidence: 0.85,
|
|
1336
|
-
resolvedBy: 'qualified-name',
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
// Strategy 2: Instance variable receiver - try capitalized form to find class
|
|
1342
|
-
// e.g., "permissionEngine" → look for classes containing "PermissionEngine"
|
|
1343
|
-
const capitalizedReceiver = objectOrClass.charAt(0).toUpperCase() + objectOrClass.slice(1);
|
|
1344
|
-
if (capitalizedReceiver !== objectOrClass) {
|
|
1345
|
-
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver), ref.filePath);
|
|
1346
|
-
for (const classNode of fuzzyClassCandidates) {
|
|
1608
|
+
const strat1 = nmTimedT('mc-class', ref, () => {
|
|
1609
|
+
const classCandidates = preferCallSiteFile(context.getNodesByName(objectOrClass), ref.filePath);
|
|
1610
|
+
for (const classNode of classCandidates) {
|
|
1347
1611
|
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'interface') {
|
|
1348
1612
|
// Skip cross-language class matches
|
|
1349
1613
|
if (classNode.language !== ref.language)
|
|
@@ -1356,67 +1620,185 @@ function matchMethodCall(ref, context) {
|
|
|
1356
1620
|
return {
|
|
1357
1621
|
original: ref,
|
|
1358
1622
|
targetNodeId: methodNode.id,
|
|
1359
|
-
confidence: 0.
|
|
1360
|
-
resolvedBy: '
|
|
1623
|
+
confidence: 0.85,
|
|
1624
|
+
resolvedBy: 'qualified-name',
|
|
1361
1625
|
};
|
|
1362
1626
|
}
|
|
1363
1627
|
}
|
|
1364
1628
|
}
|
|
1629
|
+
return null;
|
|
1630
|
+
});
|
|
1631
|
+
if (strat1)
|
|
1632
|
+
return strat1;
|
|
1633
|
+
// Strategy 2: Instance variable receiver - try capitalized form to find class
|
|
1634
|
+
// e.g., "permissionEngine" → look for classes containing "PermissionEngine"
|
|
1635
|
+
const capitalizedReceiver = objectOrClass.charAt(0).toUpperCase() + objectOrClass.slice(1);
|
|
1636
|
+
if (capitalizedReceiver !== objectOrClass) {
|
|
1637
|
+
const strat2 = nmTimedT('mc-capital', ref, () => {
|
|
1638
|
+
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver), ref.filePath);
|
|
1639
|
+
for (const classNode of fuzzyClassCandidates) {
|
|
1640
|
+
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'interface') {
|
|
1641
|
+
// Skip cross-language class matches
|
|
1642
|
+
if (classNode.language !== ref.language)
|
|
1643
|
+
continue;
|
|
1644
|
+
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
1645
|
+
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
1646
|
+
n.name === methodName &&
|
|
1647
|
+
n.qualifiedName.includes(classNode.name));
|
|
1648
|
+
if (methodNode) {
|
|
1649
|
+
return {
|
|
1650
|
+
original: ref,
|
|
1651
|
+
targetNodeId: methodNode.id,
|
|
1652
|
+
confidence: 0.8,
|
|
1653
|
+
resolvedBy: 'instance-method',
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
return null;
|
|
1659
|
+
});
|
|
1660
|
+
if (strat2)
|
|
1661
|
+
return strat2;
|
|
1365
1662
|
}
|
|
1366
1663
|
// Strategy 3: Find methods by name across the codebase, match by receiver
|
|
1367
1664
|
// name similarity with the containing class. Handles abbreviated variable
|
|
1368
1665
|
// names like permissionEngine → PermissionRuleEngine.
|
|
1369
1666
|
if (methodName) {
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
const methods = methodCandidates.filter((n) => n.kind === 'method' && n.name === methodName);
|
|
1381
|
-
// Filter to same-language candidates first
|
|
1382
|
-
const sameLanguageMethods = methods.filter(m => m.language === ref.language);
|
|
1383
|
-
const targetMethods = sameLanguageMethods.length > 0 ? sameLanguageMethods : methods;
|
|
1384
|
-
// If only one same-language method with this name exists, use it
|
|
1385
|
-
if (targetMethods.length === 1 && targetMethods[0].language === ref.language) {
|
|
1386
|
-
return {
|
|
1387
|
-
original: ref,
|
|
1388
|
-
targetNodeId: targetMethods[0].id,
|
|
1389
|
-
confidence: 0.7,
|
|
1390
|
-
resolvedBy: 'instance-method',
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
// Multiple methods: score by receiver name word overlap with class name
|
|
1394
|
-
if (targetMethods.length > 1) {
|
|
1395
|
-
const receiverWords = splitCamelCase(objectOrClass);
|
|
1396
|
-
let bestMatch;
|
|
1397
|
-
let bestScore = 0;
|
|
1398
|
-
// Same-file candidates first, so a score tie (`score > bestScore` keeps
|
|
1399
|
-
// the first seen) resolves to the call site's own file rather than the
|
|
1400
|
-
// first-indexed duplicate (#1079).
|
|
1401
|
-
for (const method of preferCallSiteFile(targetMethods, ref.filePath)) {
|
|
1402
|
-
const classWords = splitCamelCase(method.qualifiedName);
|
|
1403
|
-
let score = receiverWords.filter(w => classWords.some(cw => cw.toLowerCase() === w.toLowerCase())).length;
|
|
1404
|
-
// Bonus for same language
|
|
1405
|
-
if (method.language === ref.language)
|
|
1406
|
-
score += 1;
|
|
1407
|
-
if (score > bestScore) {
|
|
1408
|
-
bestScore = score;
|
|
1409
|
-
bestMatch = method;
|
|
1410
|
-
}
|
|
1667
|
+
const strat3 = nmTimedT('mc-byname', ref, () => {
|
|
1668
|
+
const methodCandidates = context.getNodesByName(methodName);
|
|
1669
|
+
// Ubiquitous-method ceiling (#999): a method name re-declared across a
|
|
1670
|
+
// vendored theme/SDK (Metronic's `init`/`update`/… on every widget) yields
|
|
1671
|
+
// K candidates that receiver-word overlap can't reliably disambiguate —
|
|
1672
|
+
// and filtering + scoring all K per call is the O(K²) cost that wedged
|
|
1673
|
+
// "Resolving refs" for 15-28 min. Bail before the O(K) work; Strategy 1/2
|
|
1674
|
+
// (class-name match) already had their precise shot above.
|
|
1675
|
+
if (methodCandidates.length > AMBIGUOUS_NAME_CEILING) {
|
|
1676
|
+
return null;
|
|
1411
1677
|
}
|
|
1412
|
-
|
|
1678
|
+
const methods = methodCandidates.filter((n) => n.kind === 'method' && n.name === methodName);
|
|
1679
|
+
// Filter to same-language candidates first
|
|
1680
|
+
const sameLanguageMethods = methods.filter(m => m.language === ref.language);
|
|
1681
|
+
const targetMethods = sameLanguageMethods.length > 0 ? sameLanguageMethods : methods;
|
|
1682
|
+
// If only one same-language method with this name exists, use it
|
|
1683
|
+
if (targetMethods.length === 1 && targetMethods[0].language === ref.language) {
|
|
1413
1684
|
return {
|
|
1414
1685
|
original: ref,
|
|
1415
|
-
targetNodeId:
|
|
1416
|
-
confidence: 0.
|
|
1686
|
+
targetNodeId: targetMethods[0].id,
|
|
1687
|
+
confidence: 0.7,
|
|
1417
1688
|
resolvedBy: 'instance-method',
|
|
1418
1689
|
};
|
|
1419
1690
|
}
|
|
1691
|
+
// Multiple methods: score by receiver name word overlap with class name
|
|
1692
|
+
if (targetMethods.length > 1) {
|
|
1693
|
+
const receiverWords = splitCamelCase(objectOrClass);
|
|
1694
|
+
let bestMatch;
|
|
1695
|
+
let bestScore = 0;
|
|
1696
|
+
// Same-file candidates first, so a score tie (`score > bestScore` keeps
|
|
1697
|
+
// the first seen) resolves to the call site's own file rather than the
|
|
1698
|
+
// first-indexed duplicate (#1079).
|
|
1699
|
+
for (const method of preferCallSiteFile(targetMethods, ref.filePath)) {
|
|
1700
|
+
const classWords = splitCamelCase(method.qualifiedName);
|
|
1701
|
+
let score = receiverWords.filter(w => classWords.some(cw => cw.toLowerCase() === w.toLowerCase())).length;
|
|
1702
|
+
// Bonus for same language
|
|
1703
|
+
if (method.language === ref.language)
|
|
1704
|
+
score += 1;
|
|
1705
|
+
if (score > bestScore) {
|
|
1706
|
+
bestScore = score;
|
|
1707
|
+
bestMatch = method;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (bestMatch && bestScore >= 2) {
|
|
1711
|
+
return {
|
|
1712
|
+
original: ref,
|
|
1713
|
+
targetNodeId: bestMatch.id,
|
|
1714
|
+
confidence: 0.65,
|
|
1715
|
+
resolvedBy: 'instance-method',
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
return null;
|
|
1720
|
+
});
|
|
1721
|
+
if (strat3)
|
|
1722
|
+
return strat3;
|
|
1723
|
+
}
|
|
1724
|
+
return null;
|
|
1725
|
+
}
|
|
1726
|
+
/** Go builtin/primitive field types that can never carry a project method. */
|
|
1727
|
+
const GO_BUILTIN_FIELD_TYPES = new Set([
|
|
1728
|
+
'string', 'bool', 'byte', 'rune', 'error', 'any',
|
|
1729
|
+
'int', 'int8', 'int16', 'int32', 'int64',
|
|
1730
|
+
'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uintptr',
|
|
1731
|
+
'float32', 'float64', 'complex64', 'complex128',
|
|
1732
|
+
'chan', 'map', 'func', 'struct', 'interface',
|
|
1733
|
+
]);
|
|
1734
|
+
/**
|
|
1735
|
+
* Resolve a Go 2-hop field-chain call `base.field.Method(...)` (#1276):
|
|
1736
|
+
* `target.conn.Exec("insert")` where `func (target *Target) Write()` and
|
|
1737
|
+
* `type Target struct { conn *sql.DB }`. Two inference hops, both read from
|
|
1738
|
+
* source the same way #1108 does:
|
|
1739
|
+
* 1. `base`'s type from the enclosing scope (method receiver, typed
|
|
1740
|
+
* parameter, or local declaration) via inferLocalReceiverType;
|
|
1741
|
+
* 2. `field`'s declared type from the struct's own declaration lines.
|
|
1742
|
+
* The method is then resolved AND VALIDATED on the field's type. A field
|
|
1743
|
+
* whose type has no project node (`sql.DB`, any external dependency) yields
|
|
1744
|
+
* null — the caller treats this branch as exclusive for chained Go
|
|
1745
|
+
* receivers, so the ref stays unresolved instead of name-guessing.
|
|
1746
|
+
*/
|
|
1747
|
+
function matchGoFieldChainCall(receiverChain, methodName, ref, context) {
|
|
1748
|
+
const segs = receiverChain.split('.');
|
|
1749
|
+
if (segs.length !== 2 || !segs[0] || !segs[1])
|
|
1750
|
+
return null;
|
|
1751
|
+
const [base, field] = segs;
|
|
1752
|
+
const baseType = inferLocalReceiverType(base, ref, context);
|
|
1753
|
+
if (!baseType)
|
|
1754
|
+
return null;
|
|
1755
|
+
const fieldEsc = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1756
|
+
const fieldTypeRe = new RegExp(`\\b${fieldEsc}\\s+\\*?\\[?\\]?([A-Za-z_][\\w.]*)`);
|
|
1757
|
+
const structs = preferCallSiteFile(context.getNodesByName(baseType), ref.filePath).filter((n) => (n.kind === 'struct' || n.kind === 'class') && n.language === 'go');
|
|
1758
|
+
for (const s of structs) {
|
|
1759
|
+
const source = context.readFile(s.filePath);
|
|
1760
|
+
if (!source)
|
|
1761
|
+
continue;
|
|
1762
|
+
// Only the struct's own declaration lines — a same-named identifier
|
|
1763
|
+
// elsewhere in the file can't donate a type. Matched LINE BY LINE with
|
|
1764
|
+
// comments stripped: chi's `Mux` has a doc comment reading "the tree
|
|
1765
|
+
// router" right above `tree *node`, and a whole-block match captured
|
|
1766
|
+
// `router` from the prose instead of `node` from the field.
|
|
1767
|
+
const declLines = source.split('\n').slice(Math.max(0, s.startLine - 1), s.endLine);
|
|
1768
|
+
for (const rawLine of declLines) {
|
|
1769
|
+
const line = rawLine.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '');
|
|
1770
|
+
const m = line.match(fieldTypeRe);
|
|
1771
|
+
if (!m || !m[1])
|
|
1772
|
+
continue;
|
|
1773
|
+
const rawType = m[1];
|
|
1774
|
+
// A package-qualified field type (`http.Handler`, `sql.DB`) is only
|
|
1775
|
+
// followed when the package is IN-MODULE: stripping the qualifier and
|
|
1776
|
+
// matching the bare name would conflate a stdlib/third-party type with
|
|
1777
|
+
// any same-named project type — on chi, `handler http.Handler` bound
|
|
1778
|
+
// to an example app's unrelated local `Handler`. That is the exact
|
|
1779
|
+
// fabrication this matcher exists to prevent (#1276).
|
|
1780
|
+
if (rawType.includes('.')) {
|
|
1781
|
+
const pkg = rawType.split('.')[0];
|
|
1782
|
+
const mod = context.getGoModule?.();
|
|
1783
|
+
const imp = context
|
|
1784
|
+
.getImportMappings(s.filePath, 'go')
|
|
1785
|
+
.find((i) => i.localName === pkg);
|
|
1786
|
+
const inModule = !!mod &&
|
|
1787
|
+
!!imp &&
|
|
1788
|
+
(imp.source === mod.modulePath || imp.source.startsWith(mod.modulePath + '/'));
|
|
1789
|
+
if (!inModule)
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
// Unexported (lowercase) types are idiomatic Go and stay eligible —
|
|
1793
|
+
// chi's `mx.tree.FindRoute()` chains through `tree *node`. A
|
|
1794
|
+
// mis-capture is harmless: resolveMethodOnType only returns a
|
|
1795
|
+
// validated `<type>::<method>` match.
|
|
1796
|
+
const fieldType = rawType.split('.').pop();
|
|
1797
|
+
if (!fieldType || !/^[A-Za-z_]/.test(fieldType) || GO_BUILTIN_FIELD_TYPES.has(fieldType))
|
|
1798
|
+
continue;
|
|
1799
|
+
const resolved = resolveMethodOnType(fieldType, methodName, ref, context, 0.85, 'instance-method');
|
|
1800
|
+
if (resolved)
|
|
1801
|
+
return resolved;
|
|
1420
1802
|
}
|
|
1421
1803
|
}
|
|
1422
1804
|
return null;
|
|
@@ -1579,6 +1961,45 @@ function matchFuzzy(ref, context) {
|
|
|
1579
1961
|
*/
|
|
1580
1962
|
/** ArkUI attribute-helper decorators a `.attr(...)` chain may resolve to. */
|
|
1581
1963
|
const ARKUI_ATTRIBUTE_DECORATORS = new Set(['Extend', 'Styles', 'AnimatableExtend', 'Builder']);
|
|
1964
|
+
/**
|
|
1965
|
+
* CODEGRAPH_RESOLVE_PROFILE=2 sub-stage attribution for matchReference's
|
|
1966
|
+
* strategy pipeline (`nm:<stage>|<refKind>|hit/miss`). Module-global because
|
|
1967
|
+
* the matcher is a free function; each thread (main + every pool worker) has
|
|
1968
|
+
* its own module instance, and dumpNameMatcherProfile is invoked from
|
|
1969
|
+
* ReferenceResolver.dumpResolveProfile so worker tables surface too.
|
|
1970
|
+
*/
|
|
1971
|
+
const NM_PROFILE = process.env.CODEGRAPH_RESOLVE_PROFILE === '2' ? new Map() : null;
|
|
1972
|
+
function nmTimedT(stage, ref, fn) {
|
|
1973
|
+
if (!NM_PROFILE)
|
|
1974
|
+
return fn();
|
|
1975
|
+
const t0 = process.hrtime.bigint();
|
|
1976
|
+
const r = fn();
|
|
1977
|
+
const dt = process.hrtime.bigint() - t0;
|
|
1978
|
+
const key = `nm:${stage}|${ref.referenceKind}|${r ? 'hit' : 'miss'}`;
|
|
1979
|
+
const slot = NM_PROFILE.get(key);
|
|
1980
|
+
if (slot) {
|
|
1981
|
+
slot.n++;
|
|
1982
|
+
slot.ns += dt;
|
|
1983
|
+
}
|
|
1984
|
+
else {
|
|
1985
|
+
NM_PROFILE.set(key, { n: 1, ns: dt });
|
|
1986
|
+
}
|
|
1987
|
+
return r;
|
|
1988
|
+
}
|
|
1989
|
+
function nmTimed(stage, ref, fn) {
|
|
1990
|
+
return nmTimedT(stage, ref, fn);
|
|
1991
|
+
}
|
|
1992
|
+
/** Dump this thread's matchReference sub-stage table to stderr (no-op unless =2). */
|
|
1993
|
+
function dumpNameMatcherProfile(label) {
|
|
1994
|
+
if (!NM_PROFILE || NM_PROFILE.size === 0)
|
|
1995
|
+
return;
|
|
1996
|
+
const rows = [...NM_PROFILE.entries()]
|
|
1997
|
+
.map(([k, v]) => ({ k, n: v.n, ms: Number(v.ns / 1000000n) }))
|
|
1998
|
+
.sort((a, b) => b.ms - a.ms);
|
|
1999
|
+
for (const r of rows) {
|
|
2000
|
+
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`);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
1582
2003
|
function matchReference(ref, context) {
|
|
1583
2004
|
// Function-as-value refs (#756) resolve ONLY through the dedicated matcher —
|
|
1584
2005
|
// never the fuzzy/qualified fallthrough below (a wrong callback edge is
|
|
@@ -1640,18 +2061,18 @@ function matchReference(ref, context) {
|
|
|
1640
2061
|
// Try strategies in order of confidence
|
|
1641
2062
|
let result;
|
|
1642
2063
|
// 0. File path match (e.g., "snippets/drawer-menu.liquid" → file node)
|
|
1643
|
-
result = matchByFilePath(ref, context);
|
|
2064
|
+
result = nmTimed('filePath', ref, () => matchByFilePath(ref, context));
|
|
1644
2065
|
if (result)
|
|
1645
2066
|
return result;
|
|
1646
2067
|
// 1. Qualified name match (highest confidence)
|
|
1647
|
-
result = matchByQualifiedName(ref, context);
|
|
2068
|
+
result = nmTimed('qualifiedName', ref, () => matchByQualifiedName(ref, context));
|
|
1648
2069
|
if (result)
|
|
1649
2070
|
return result;
|
|
1650
2071
|
// 1b. C++ chained call whose receiver is another call — `Foo::instance().bar()`
|
|
1651
2072
|
// encoded as `Foo::instance().bar` by the extractor (#645). Resolve the
|
|
1652
2073
|
// receiver's type from what the inner call returns, then the method on it.
|
|
1653
2074
|
if (ref.language === 'cpp' || ref.language === 'c') {
|
|
1654
|
-
result = matchCppCallChain(ref, context);
|
|
2075
|
+
result = nmTimed('cppChain', ref, () => matchCppCallChain(ref, context));
|
|
1655
2076
|
if (result)
|
|
1656
2077
|
return result;
|
|
1657
2078
|
}
|
|
@@ -1660,7 +2081,7 @@ function matchReference(ref, context) {
|
|
|
1660
2081
|
// type is the factory's `self` (PHP `: self`/`: static`, Rust `-> Self`) or
|
|
1661
2082
|
// concrete return type.
|
|
1662
2083
|
if (ref.language === 'php' || ref.language === 'rust') {
|
|
1663
|
-
result = matchScopedCallChain(ref, context);
|
|
2084
|
+
result = nmTimed('scopedChain', ref, () => matchScopedCallChain(ref, context));
|
|
1664
2085
|
if (result)
|
|
1665
2086
|
return result;
|
|
1666
2087
|
}
|
|
@@ -1680,20 +2101,20 @@ function matchReference(ref, context) {
|
|
|
1680
2101
|
ref.language === 'dart' ||
|
|
1681
2102
|
ref.language === 'objc' ||
|
|
1682
2103
|
ref.language === 'pascal') {
|
|
1683
|
-
result = matchDottedCallChain(ref, context);
|
|
2104
|
+
result = nmTimed('dottedChain', ref, () => matchDottedCallChain(ref, context));
|
|
1684
2105
|
if (result)
|
|
1685
2106
|
return result;
|
|
1686
2107
|
}
|
|
1687
2108
|
// 2. Method call pattern
|
|
1688
|
-
result = matchMethodCall(ref, context);
|
|
2109
|
+
result = nmTimed('methodCall', ref, () => matchMethodCall(ref, context));
|
|
1689
2110
|
if (result)
|
|
1690
2111
|
return result;
|
|
1691
2112
|
// 3. Exact name match
|
|
1692
|
-
result = matchByExactName(ref, context);
|
|
2113
|
+
result = nmTimed('exactName', ref, () => matchByExactName(ref, context));
|
|
1693
2114
|
if (result)
|
|
1694
2115
|
return result;
|
|
1695
2116
|
// 4. Fuzzy match (lowest confidence)
|
|
1696
|
-
result = matchFuzzy(ref, context);
|
|
2117
|
+
result = nmTimed('fuzzy', ref, () => matchFuzzy(ref, context));
|
|
1697
2118
|
if (result)
|
|
1698
2119
|
return result;
|
|
1699
2120
|
return null;
|