@colbymchenry/codegraph-win32-arm64 1.4.1 → 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 +61 -15
- package/lib/dist/bin/codegraph.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/queries.d.ts +74 -2
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +287 -20
- package/lib/dist/db/queries.js.map +1 -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 +254 -61
- 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 +14 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +188 -10
- 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.map +1 -1
- package/lib/dist/installer/index.js +11 -0
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +27 -0
- 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 +87 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +716 -130
- 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 +387 -95
- 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 +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
|
@@ -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':
|
|
@@ -1241,6 +1325,53 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1241
1325
|
}
|
|
1242
1326
|
return null;
|
|
1243
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
|
+
}
|
|
1244
1375
|
// Nearest declaration wins: scan backward from the call to the scope start.
|
|
1245
1376
|
for (let i = callIdx; i >= startIdx; i--) {
|
|
1246
1377
|
const type = matchLine(i);
|
|
@@ -1283,6 +1414,9 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1283
1414
|
* shape is handled by inferPhpAssignedPropertyType instead.
|
|
1284
1415
|
*/
|
|
1285
1416
|
function phpPropertyTypePatterns(r) {
|
|
1417
|
+
return memoPatterns(`php-prop|${r}`, () => buildPhpPropertyTypePatterns(r));
|
|
1418
|
+
}
|
|
1419
|
+
function buildPhpPropertyTypePatterns(r) {
|
|
1286
1420
|
return [
|
|
1287
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)
|
|
1288
1422
|
new RegExp(`\\$this->${r}\\b\\s*=\\s*new\\s+([A-Za-z_\\\\][\\w\\\\]*)`), // $this->prop = new Foo()
|
|
@@ -1362,7 +1496,17 @@ function matchMethodCall(ref, context) {
|
|
|
1362
1496
|
// (with its existing single-candidate / receiver-overlap guards). Without this
|
|
1363
1497
|
// a multi-dot extension-method call (C# DI `builder.Services.AddCoreServices()`,
|
|
1364
1498
|
// `Guard.Against.X()`) matched no pattern and never resolved.
|
|
1365
|
-
|
|
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);
|
|
1366
1510
|
const colonMatch = ref.referenceName.match(/^(\w+)::(\w+)$/);
|
|
1367
1511
|
// Lua/Luau method calls use a single colon (`lg:log`); R uses `$` (`lg$log`).
|
|
1368
1512
|
// Recognize these receiver/method separators so local-variable receiver-type
|
|
@@ -1406,9 +1550,9 @@ function matchMethodCall(ref, context) {
|
|
|
1406
1550
|
// shared source-based inferrer. resolveMethodOnType validates the method
|
|
1407
1551
|
// exists on the inferred type, so a mis-inference produces no edge.
|
|
1408
1552
|
if (inferableReceiver) {
|
|
1409
|
-
const inferredType = ref.language === 'cpp'
|
|
1553
|
+
const inferredType = nmTimedT('mc-infer', ref, () => ref.language === 'cpp'
|
|
1410
1554
|
? inferCppReceiverType(objectOrClass, ref, context)
|
|
1411
|
-
: inferLocalReceiverType(objectOrClass, ref, context);
|
|
1555
|
+
: inferLocalReceiverType(objectOrClass, ref, context));
|
|
1412
1556
|
if (inferredType) {
|
|
1413
1557
|
// Java/Kotlin: when two classes share the simple name, the file's import
|
|
1414
1558
|
// pins WHICH one (#314). Other languages disambiguate by call-site file.
|
|
@@ -1417,12 +1561,26 @@ function matchMethodCall(ref, context) {
|
|
|
1417
1561
|
.getImportMappings(ref.filePath, ref.language)
|
|
1418
1562
|
.find((i) => i.localName === inferredType)?.source
|
|
1419
1563
|
: undefined;
|
|
1420
|
-
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));
|
|
1421
1565
|
if (typedMatch) {
|
|
1422
1566
|
return typedMatch;
|
|
1423
1567
|
}
|
|
1424
1568
|
}
|
|
1425
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
|
+
}
|
|
1426
1584
|
// Java/Kotlin: receiver may be a field whose name doesn't match the type by
|
|
1427
1585
|
// Java naming convention (`userbo` → class `UserBO`, abbreviated). Look up
|
|
1428
1586
|
// the field in the enclosing class to get its declared type, then resolve
|
|
@@ -1436,7 +1594,7 @@ function matchMethodCall(ref, context) {
|
|
|
1436
1594
|
// imported FQN so resolveMethodOnType can disambiguate (#314).
|
|
1437
1595
|
const imports = context.getImportMappings(ref.filePath, ref.language);
|
|
1438
1596
|
const importedFqn = imports.find((i) => i.localName === inferredType)?.source;
|
|
1439
|
-
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));
|
|
1440
1598
|
if (typedMatch) {
|
|
1441
1599
|
return typedMatch;
|
|
1442
1600
|
}
|
|
@@ -1447,32 +1605,9 @@ function matchMethodCall(ref, context) {
|
|
|
1447
1605
|
// with a `Logger` in both `a/` and `b/`), try the class in the call site's
|
|
1448
1606
|
// own file first — otherwise the first-indexed class wins and a call in `b/`
|
|
1449
1607
|
// resolves to `a/`'s method (#1079).
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
// Skip cross-language class matches
|
|
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) {
|
|
1608
|
+
const strat1 = nmTimedT('mc-class', ref, () => {
|
|
1609
|
+
const classCandidates = preferCallSiteFile(context.getNodesByName(objectOrClass), ref.filePath);
|
|
1610
|
+
for (const classNode of classCandidates) {
|
|
1476
1611
|
if (classNode.kind === 'class' || classNode.kind === 'struct' || classNode.kind === 'interface') {
|
|
1477
1612
|
// Skip cross-language class matches
|
|
1478
1613
|
if (classNode.language !== ref.language)
|
|
@@ -1485,67 +1620,185 @@ function matchMethodCall(ref, context) {
|
|
|
1485
1620
|
return {
|
|
1486
1621
|
original: ref,
|
|
1487
1622
|
targetNodeId: methodNode.id,
|
|
1488
|
-
confidence: 0.
|
|
1489
|
-
resolvedBy: '
|
|
1623
|
+
confidence: 0.85,
|
|
1624
|
+
resolvedBy: 'qualified-name',
|
|
1490
1625
|
};
|
|
1491
1626
|
}
|
|
1492
1627
|
}
|
|
1493
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;
|
|
1494
1662
|
}
|
|
1495
1663
|
// Strategy 3: Find methods by name across the codebase, match by receiver
|
|
1496
1664
|
// name similarity with the containing class. Handles abbreviated variable
|
|
1497
1665
|
// names like permissionEngine → PermissionRuleEngine.
|
|
1498
1666
|
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
|
-
}
|
|
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;
|
|
1540
1677
|
}
|
|
1541
|
-
|
|
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) {
|
|
1542
1684
|
return {
|
|
1543
1685
|
original: ref,
|
|
1544
|
-
targetNodeId:
|
|
1545
|
-
confidence: 0.
|
|
1686
|
+
targetNodeId: targetMethods[0].id,
|
|
1687
|
+
confidence: 0.7,
|
|
1546
1688
|
resolvedBy: 'instance-method',
|
|
1547
1689
|
};
|
|
1548
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;
|
|
1549
1802
|
}
|
|
1550
1803
|
}
|
|
1551
1804
|
return null;
|
|
@@ -1708,6 +1961,45 @@ function matchFuzzy(ref, context) {
|
|
|
1708
1961
|
*/
|
|
1709
1962
|
/** ArkUI attribute-helper decorators a `.attr(...)` chain may resolve to. */
|
|
1710
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
|
+
}
|
|
1711
2003
|
function matchReference(ref, context) {
|
|
1712
2004
|
// Function-as-value refs (#756) resolve ONLY through the dedicated matcher —
|
|
1713
2005
|
// never the fuzzy/qualified fallthrough below (a wrong callback edge is
|
|
@@ -1769,18 +2061,18 @@ function matchReference(ref, context) {
|
|
|
1769
2061
|
// Try strategies in order of confidence
|
|
1770
2062
|
let result;
|
|
1771
2063
|
// 0. File path match (e.g., "snippets/drawer-menu.liquid" → file node)
|
|
1772
|
-
result = matchByFilePath(ref, context);
|
|
2064
|
+
result = nmTimed('filePath', ref, () => matchByFilePath(ref, context));
|
|
1773
2065
|
if (result)
|
|
1774
2066
|
return result;
|
|
1775
2067
|
// 1. Qualified name match (highest confidence)
|
|
1776
|
-
result = matchByQualifiedName(ref, context);
|
|
2068
|
+
result = nmTimed('qualifiedName', ref, () => matchByQualifiedName(ref, context));
|
|
1777
2069
|
if (result)
|
|
1778
2070
|
return result;
|
|
1779
2071
|
// 1b. C++ chained call whose receiver is another call — `Foo::instance().bar()`
|
|
1780
2072
|
// encoded as `Foo::instance().bar` by the extractor (#645). Resolve the
|
|
1781
2073
|
// receiver's type from what the inner call returns, then the method on it.
|
|
1782
2074
|
if (ref.language === 'cpp' || ref.language === 'c') {
|
|
1783
|
-
result = matchCppCallChain(ref, context);
|
|
2075
|
+
result = nmTimed('cppChain', ref, () => matchCppCallChain(ref, context));
|
|
1784
2076
|
if (result)
|
|
1785
2077
|
return result;
|
|
1786
2078
|
}
|
|
@@ -1789,7 +2081,7 @@ function matchReference(ref, context) {
|
|
|
1789
2081
|
// type is the factory's `self` (PHP `: self`/`: static`, Rust `-> Self`) or
|
|
1790
2082
|
// concrete return type.
|
|
1791
2083
|
if (ref.language === 'php' || ref.language === 'rust') {
|
|
1792
|
-
result = matchScopedCallChain(ref, context);
|
|
2084
|
+
result = nmTimed('scopedChain', ref, () => matchScopedCallChain(ref, context));
|
|
1793
2085
|
if (result)
|
|
1794
2086
|
return result;
|
|
1795
2087
|
}
|
|
@@ -1809,20 +2101,20 @@ function matchReference(ref, context) {
|
|
|
1809
2101
|
ref.language === 'dart' ||
|
|
1810
2102
|
ref.language === 'objc' ||
|
|
1811
2103
|
ref.language === 'pascal') {
|
|
1812
|
-
result = matchDottedCallChain(ref, context);
|
|
2104
|
+
result = nmTimed('dottedChain', ref, () => matchDottedCallChain(ref, context));
|
|
1813
2105
|
if (result)
|
|
1814
2106
|
return result;
|
|
1815
2107
|
}
|
|
1816
2108
|
// 2. Method call pattern
|
|
1817
|
-
result = matchMethodCall(ref, context);
|
|
2109
|
+
result = nmTimed('methodCall', ref, () => matchMethodCall(ref, context));
|
|
1818
2110
|
if (result)
|
|
1819
2111
|
return result;
|
|
1820
2112
|
// 3. Exact name match
|
|
1821
|
-
result = matchByExactName(ref, context);
|
|
2113
|
+
result = nmTimed('exactName', ref, () => matchByExactName(ref, context));
|
|
1822
2114
|
if (result)
|
|
1823
2115
|
return result;
|
|
1824
2116
|
// 4. Fuzzy match (lowest confidence)
|
|
1825
|
-
result = matchFuzzy(ref, context);
|
|
2117
|
+
result = nmTimed('fuzzy', ref, () => matchFuzzy(ref, context));
|
|
1826
2118
|
if (result)
|
|
1827
2119
|
return result;
|
|
1828
2120
|
return null;
|