@colbymchenry/codegraph-win32-arm64 1.6.3 → 1.6.4
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/lib/dist/.test-build-engine.json +1 -1
- package/lib/dist/.test-build-viewer.json +1 -1
- package/lib/dist/bin/codegraph.js +85 -17
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/db/queries.d.ts +44 -1
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +75 -5
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/engine.d.ts +1 -1
- package/lib/dist/engine.d.ts.map +1 -1
- package/lib/dist/engine.js +2 -1
- package/lib/dist/engine.js.map +1 -1
- package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/cfml-extractor.js +4 -2
- package/lib/dist/extraction/cfml-extractor.js.map +1 -1
- package/lib/dist/extraction/extraction-version.d.ts +1 -1
- package/lib/dist/extraction/extraction-version.js +1 -1
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +12 -1
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +28 -0
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +106 -0
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +11 -0
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +42 -3
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -1
- package/lib/dist/extraction/kernel/index.js +23 -2
- package/lib/dist/extraction/kernel/index.js.map +1 -1
- package/lib/dist/extraction/kernel/loader.d.ts +5 -1
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -1
- package/lib/dist/extraction/kernel/loader.js.map +1 -1
- package/lib/dist/extraction/languages/dart.d.ts +47 -2
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +193 -6
- package/lib/dist/extraction/languages/dart.js.map +1 -1
- package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/lib/dist/extraction/languages/kotlin.js +8 -13
- package/lib/dist/extraction/languages/kotlin.js.map +1 -1
- package/lib/dist/extraction/languages/php.d.ts +9 -0
- package/lib/dist/extraction/languages/php.d.ts.map +1 -1
- package/lib/dist/extraction/languages/php.js +202 -2
- package/lib/dist/extraction/languages/php.js.map +1 -1
- package/lib/dist/extraction/languages/rust-macro-calls.d.ts +32 -0
- package/lib/dist/extraction/languages/rust-macro-calls.d.ts.map +1 -0
- package/lib/dist/extraction/languages/rust-macro-calls.js +306 -0
- package/lib/dist/extraction/languages/rust-macro-calls.js.map +1 -0
- package/lib/dist/extraction/parse-budget.d.ts +42 -7
- package/lib/dist/extraction/parse-budget.d.ts.map +1 -1
- package/lib/dist/extraction/parse-budget.js +39 -2
- package/lib/dist/extraction/parse-budget.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +1 -13
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +7 -19
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +77 -7
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +218 -18
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +9 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +17 -1
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/graph/file-drift.d.ts +35 -0
- package/lib/dist/graph/file-drift.d.ts.map +1 -0
- package/lib/dist/graph/file-drift.js +46 -0
- package/lib/dist/graph/file-drift.js.map +1 -0
- package/lib/dist/graph/queries.d.ts +4 -1
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -2
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/symbol-references.d.ts +86 -0
- package/lib/dist/graph/symbol-references.d.ts.map +1 -0
- package/lib/dist/graph/symbol-references.js +304 -0
- package/lib/dist/graph/symbol-references.js.map +1 -0
- package/lib/dist/graph/test-code.d.ts +15 -3
- package/lib/dist/graph/test-code.d.ts.map +1 -1
- package/lib/dist/graph/test-code.js +56 -2
- package/lib/dist/graph/test-code.js.map +1 -1
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +2 -4
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +24 -1
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +42 -3
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts +4 -1
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +2 -1
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/instructions-template.d.ts +15 -0
- package/lib/dist/installer/instructions-template.d.ts.map +1 -1
- package/lib/dist/installer/instructions-template.js +10 -1
- package/lib/dist/installer/instructions-template.js.map +1 -1
- package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
- package/lib/dist/installer/targets/opencode.js +1 -1
- package/lib/dist/installer/targets/opencode.js.map +1 -1
- package/lib/dist/installer/targets/shared.d.ts +2 -2
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +18 -2
- package/lib/dist/installer/targets/shared.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +2 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +7 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-proof.d.ts +19 -0
- package/lib/dist/mcp/daemon-proof.d.ts.map +1 -0
- package/lib/dist/mcp/daemon-proof.js +126 -0
- package/lib/dist/mcp/daemon-proof.js.map +1 -0
- package/lib/dist/mcp/daemon-registry.d.ts +7 -2
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +14 -2
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +46 -0
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +97 -3
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +16 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +14 -0
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-diagnostics.d.ts +6 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -1
- package/lib/dist/mcp/explore-diagnostics.js +8 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -1
- package/lib/dist/mcp/explore-one-symbol.d.ts +77 -0
- package/lib/dist/mcp/explore-one-symbol.d.ts.map +1 -0
- package/lib/dist/mcp/explore-one-symbol.js +431 -0
- package/lib/dist/mcp/explore-one-symbol.js.map +1 -0
- package/lib/dist/mcp/hook-client.d.ts +44 -0
- package/lib/dist/mcp/hook-client.d.ts.map +1 -0
- package/lib/dist/mcp/hook-client.js +202 -0
- package/lib/dist/mcp/hook-client.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +13 -3
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +15 -9
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/opencode-tool-names.d.ts +32 -0
- package/lib/dist/mcp/opencode-tool-names.d.ts.map +1 -0
- package/lib/dist/mcp/opencode-tool-names.js +24 -0
- package/lib/dist/mcp/opencode-tool-names.js.map +1 -0
- package/lib/dist/mcp/project-lifecycle.d.ts +6 -0
- package/lib/dist/mcp/project-lifecycle.d.ts.map +1 -1
- package/lib/dist/mcp/project-lifecycle.js +21 -3
- package/lib/dist/mcp/project-lifecycle.js.map +1 -1
- package/lib/dist/mcp/prompt-explore.d.ts +19 -0
- package/lib/dist/mcp/prompt-explore.d.ts.map +1 -0
- package/lib/dist/mcp/prompt-explore.js +6 -0
- package/lib/dist/mcp/prompt-explore.js.map +1 -0
- package/lib/dist/mcp/proxy.d.ts +14 -7
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +71 -26
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +9 -0
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +5 -0
- package/lib/dist/mcp/query-pool.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +18 -0
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +12 -1
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +19 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +42 -3
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +31 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +137 -32
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/project-config.d.ts +20 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +30 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +4 -4
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +44 -77
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/event-emitter-synthesizer.d.ts +39 -0
- package/lib/dist/resolution/event-emitter-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/event-emitter-synthesizer.js +656 -0
- package/lib/dist/resolution/event-emitter-synthesizer.js.map +1 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.d.ts +62 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.js +382 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.js.map +1 -0
- package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/csharp.js +80 -34
- package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
- package/lib/dist/resolution/frameworks/elysia.d.ts +38 -0
- package/lib/dist/resolution/frameworks/elysia.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/elysia.js +683 -0
- package/lib/dist/resolution/frameworks/elysia.js.map +1 -0
- package/lib/dist/resolution/frameworks/express.d.ts +48 -1
- package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +13 -2
- package/lib/dist/resolution/frameworks/express.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +1 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +5 -1
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.js +69 -11
- package/lib/dist/resolution/frameworks/laravel.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +2 -0
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +164 -25
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +102 -0
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +289 -13
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/js-builtins.d.ts +9 -0
- package/lib/dist/resolution/js-builtins.d.ts.map +1 -1
- package/lib/dist/resolution/js-builtins.js +21 -1
- package/lib/dist/resolution/js-builtins.js.map +1 -1
- package/lib/dist/resolution/module-importers.d.ts +25 -0
- package/lib/dist/resolution/module-importers.d.ts.map +1 -1
- package/lib/dist/resolution/module-importers.js +85 -0
- package/lib/dist/resolution/module-importers.js.map +1 -1
- package/lib/dist/resolution/name-matcher.d.ts +129 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +1603 -92
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/php-web-root.d.ts +39 -0
- package/lib/dist/resolution/php-web-root.d.ts.map +1 -0
- package/lib/dist/resolution/php-web-root.js +141 -0
- package/lib/dist/resolution/php-web-root.js.map +1 -0
- package/lib/dist/resolution/python-overloads.d.ts +10 -0
- package/lib/dist/resolution/python-overloads.d.ts.map +1 -0
- package/lib/dist/resolution/python-overloads.js +75 -0
- package/lib/dist/resolution/python-overloads.js.map +1 -0
- package/lib/dist/resolution/swift-type-visibility.d.ts.map +1 -1
- package/lib/dist/resolution/swift-type-visibility.js +60 -3
- package/lib/dist/resolution/swift-type-visibility.js.map +1 -1
- package/lib/dist/resolution/tier-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/tier-synthesizer.js +31 -7
- package/lib/dist/resolution/tier-synthesizer.js.map +1 -1
- package/lib/dist/resolution/types.d.ts +9 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/types.js.map +1 -1
- package/lib/dist/resolution/workspace-packages.d.ts.map +1 -1
- package/lib/dist/resolution/workspace-packages.js +3 -0
- package/lib/dist/resolution/workspace-packages.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +2 -2
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
|
@@ -42,6 +42,7 @@ exports.isPythonNameFromOutside = isPythonNameFromOutside;
|
|
|
42
42
|
exports.pythonFunctionModuleAlias = pythonFunctionModuleAlias;
|
|
43
43
|
exports.pythonReceiverBinding = pythonReceiverBinding;
|
|
44
44
|
exports.pythonModuleImportKeys = pythonModuleImportKeys;
|
|
45
|
+
exports.pythonFunctionImportKeys = pythonFunctionImportKeys;
|
|
45
46
|
exports.matchFunctionRef = matchFunctionRef;
|
|
46
47
|
exports.isLexicallyReachable = isLexicallyReachable;
|
|
47
48
|
exports.tsGlobalScope = tsGlobalScope;
|
|
@@ -61,6 +62,10 @@ exports.isGoLocallyBound = isGoLocallyBound;
|
|
|
61
62
|
exports.blankGoCode = blankGoCode;
|
|
62
63
|
exports.isVisibleAcrossFiles = isVisibleAcrossFiles;
|
|
63
64
|
exports.isPythonSelfCall = isPythonSelfCall;
|
|
65
|
+
exports.isJsThisCall = isJsThisCall;
|
|
66
|
+
exports.pythonSelfCallReaches = pythonSelfCallReaches;
|
|
67
|
+
exports.isLexicalBindingOfJsThisCall = isLexicalBindingOfJsThisCall;
|
|
68
|
+
exports.isRefusedDeepThisTarget = isRefusedDeepThisTarget;
|
|
64
69
|
exports.isGoBareName = isGoBareName;
|
|
65
70
|
exports.isPythonOutsideModuleReceiver = isPythonOutsideModuleReceiver;
|
|
66
71
|
exports.isDartChainLink = isDartChainLink;
|
|
@@ -85,6 +90,9 @@ exports.matchRustUseBoundName = matchRustUseBoundName;
|
|
|
85
90
|
exports.rustPathTarget = rustPathTarget;
|
|
86
91
|
exports.isRustNameFromStd = isRustNameFromStd;
|
|
87
92
|
exports.isRustForeignImplCallable = isRustForeignImplCallable;
|
|
93
|
+
exports.isRustOtherTypesMethod = isRustOtherTypesMethod;
|
|
94
|
+
exports.isRustTraitImplMember = isRustTraitImplMember;
|
|
95
|
+
exports.isRustCallUnreachable = isRustCallUnreachable;
|
|
88
96
|
exports.isRustPathCallReachable = isRustPathCallReachable;
|
|
89
97
|
exports.jsCodeBindsName = jsCodeBindsName;
|
|
90
98
|
exports.isImportShadowedByJsBinding = isImportShadowedByJsBinding;
|
|
@@ -93,6 +101,7 @@ exports.matchByQualifiedName = matchByQualifiedName;
|
|
|
93
101
|
exports.preferCallSiteFile = preferCallSiteFile;
|
|
94
102
|
exports.resolveObjectLiteralMember = resolveObjectLiteralMember;
|
|
95
103
|
exports.objectLiteralMemberBinding = objectLiteralMemberBinding;
|
|
104
|
+
exports.objectLiteralMembers = objectLiteralMembers;
|
|
96
105
|
exports.resolveObjectLiteralBinding = resolveObjectLiteralBinding;
|
|
97
106
|
exports.thisScopeCaller = thisScopeCaller;
|
|
98
107
|
exports.matchObjectPathCall = matchObjectPathCall;
|
|
@@ -118,7 +127,9 @@ exports.inferLocalReceiverType = inferLocalReceiverType;
|
|
|
118
127
|
exports.jsReceiverTypeFile = jsReceiverTypeFile;
|
|
119
128
|
exports.matchMethodCall = matchMethodCall;
|
|
120
129
|
exports.reExportSource = reExportSource;
|
|
130
|
+
exports.matchCsharpLiteralCall = matchCsharpLiteralCall;
|
|
121
131
|
exports.isPythonFromImportModule = isPythonFromImportModule;
|
|
132
|
+
exports.isPythonImportStatementModule = isPythonImportStatementModule;
|
|
122
133
|
exports.matchGoAssertedCall = matchGoAssertedCall;
|
|
123
134
|
exports.isGoAssertedLocal = isGoAssertedLocal;
|
|
124
135
|
exports.isGoProjectLocalCall = isGoProjectLocalCall;
|
|
@@ -126,6 +137,7 @@ exports.preferGoBuildTwin = preferGoBuildTwin;
|
|
|
126
137
|
exports.goDotImportedSupertype = goDotImportedSupertype;
|
|
127
138
|
exports.matchGoIndexedCall = matchGoIndexedCall;
|
|
128
139
|
exports.matchGoChainedCall = matchGoChainedCall;
|
|
140
|
+
exports.matchGoBuiltinReceiverCall = matchGoBuiltinReceiverCall;
|
|
129
141
|
exports.matchPythonTypedLocalCall = matchPythonTypedLocalCall;
|
|
130
142
|
exports.pythonAttrRefResolves = pythonAttrRefResolves;
|
|
131
143
|
exports.rustFieldTypeName = rustFieldTypeName;
|
|
@@ -338,6 +350,21 @@ function gateLanguageMatch(result, ref, context) {
|
|
|
338
350
|
return null;
|
|
339
351
|
return result;
|
|
340
352
|
}
|
|
353
|
+
function matchCsharpMethodGroup(receiver, member, ref, context) {
|
|
354
|
+
if (!context.getNodesByName(member).some((n) => n.kind === 'method' && n.language === 'csharp'))
|
|
355
|
+
return null;
|
|
356
|
+
let type = /^[A-Za-z_]\w*$/.test(receiver)
|
|
357
|
+
? inferLocalReceiverType(receiver, ref, context) ?? inferMemberReceiverType(receiver, ref, context)
|
|
358
|
+
: null;
|
|
359
|
+
if (!type && /^[A-Z]\w*$/.test(receiver) &&
|
|
360
|
+
context.getNodesByName(receiver).some((n) => n.language === 'csharp' && CSHARP_TYPE_KINDS.has(n.kind)))
|
|
361
|
+
type = receiver;
|
|
362
|
+
if (!type || /^[a-z]/.test(type))
|
|
363
|
+
return null;
|
|
364
|
+
const found = resolveMethodOnType(type, member, ref, context, 0.9, 'function-ref');
|
|
365
|
+
const target = found ? context.getNodeById?.(found.targetNodeId) : undefined;
|
|
366
|
+
return found && target?.kind === 'method' && target.id !== ref.fromNodeId ? found : null;
|
|
367
|
+
}
|
|
341
368
|
function matchMemberFunctionRef(ref, context) {
|
|
342
369
|
const dot = ref.referenceName.lastIndexOf('.');
|
|
343
370
|
const receiver = ref.referenceName.slice(0, dot);
|
|
@@ -370,6 +397,8 @@ function matchMemberFunctionRef(ref, context) {
|
|
|
370
397
|
const node = imported && context.getNodeById?.(imported.targetNodeId);
|
|
371
398
|
return node ? result(context.getNodesByQualifiedName(node.qualifiedName).filter(n => n.filePath === node.filePath)) : null;
|
|
372
399
|
}
|
|
400
|
+
if (ref.language === 'csharp')
|
|
401
|
+
return matchCsharpMethodGroup(receiver, member, ref, context);
|
|
373
402
|
if (ref.language === 'go') {
|
|
374
403
|
if (receiver.includes('.'))
|
|
375
404
|
return matchGoFieldChainCall(receiver, member, ref, context);
|
|
@@ -447,6 +476,42 @@ function pythonRefClass(name, ref, context) {
|
|
|
447
476
|
const classes = context.getNodesByName(name).filter(n => n.kind === 'class' && n.filePath === ref.filePath);
|
|
448
477
|
return classes.length === 1 ? classes[0] : null;
|
|
449
478
|
}
|
|
479
|
+
function pythonPatternTypeHolds(match, raw, ref, context) {
|
|
480
|
+
const withItem = /(?:^|[\s;:\0])(async\s+)?with\s[\s\S]*\sas\s+\w+$/.exec(match);
|
|
481
|
+
const throughModule = /^[a-z_]\w*\./.test(raw);
|
|
482
|
+
if (!withItem && !throughModule)
|
|
483
|
+
return true;
|
|
484
|
+
const cls = pythonRefClass(raw, ref, context);
|
|
485
|
+
if (!cls)
|
|
486
|
+
return false;
|
|
487
|
+
if (!withItem)
|
|
488
|
+
return true;
|
|
489
|
+
const enter = pythonClassMethod(cls, withItem[1] ? '__aenter__' : '__enter__', ref, context);
|
|
490
|
+
return !enter || pythonReturnsOnlySelf(enter, context);
|
|
491
|
+
}
|
|
492
|
+
function pythonClassMethod(cls, name, ref, context) {
|
|
493
|
+
const queue = [cls];
|
|
494
|
+
const seen = new Set();
|
|
495
|
+
while (queue.length > 0 && seen.size < 16) {
|
|
496
|
+
const c = queue.shift();
|
|
497
|
+
if (seen.has(c.id))
|
|
498
|
+
continue;
|
|
499
|
+
seen.add(c.id);
|
|
500
|
+
const own = context.getNodesByQualifiedName(`${c.qualifiedName}::${name}`).find(n => n.kind === 'method' && n.filePath === c.filePath);
|
|
501
|
+
if (own)
|
|
502
|
+
return own;
|
|
503
|
+
queue.push(...pythonBases(c, ref, context));
|
|
504
|
+
}
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
function pythonReturnsOnlySelf(method, context) {
|
|
508
|
+
const body = pythonMemberLines(method.filePath, context).slice(method.startLine - 1, method.endLine);
|
|
509
|
+
const values = body.flatMap(l => {
|
|
510
|
+
const m = /(?:^|[:;])\s*return\b(.*?)\s*$/.exec(pythonBlankStrings(l));
|
|
511
|
+
return m ? [m[1].trim()] : [];
|
|
512
|
+
});
|
|
513
|
+
return values.length > 0 && values.every(v => v === 'self');
|
|
514
|
+
}
|
|
450
515
|
function isPythonNameFromOutside(name, filePath, target, context) {
|
|
451
516
|
if (target?.filePath === filePath)
|
|
452
517
|
return false;
|
|
@@ -610,6 +675,9 @@ function pythonStatementStarts(filePath, context) {
|
|
|
610
675
|
return starts;
|
|
611
676
|
}
|
|
612
677
|
function pythonOwnLines(scope, filePath, context) {
|
|
678
|
+
return pythonNameScan(context, `ownlines\0${filePath}\0${scope?.id ?? ''}`, () => pythonOwnLinesUncached(scope, filePath, context));
|
|
679
|
+
}
|
|
680
|
+
function pythonOwnLinesUncached(scope, filePath, context) {
|
|
613
681
|
const count = pythonMemberLines(filePath, context).length;
|
|
614
682
|
const from = scope ? scope.startLine : 1;
|
|
615
683
|
const to = scope ? Math.min(scope.endLine, count) : count;
|
|
@@ -1080,6 +1148,35 @@ function pythonStatementBindsAt(name, ref, context) {
|
|
|
1080
1148
|
function pythonModuleImportKeys(name, filePath, context) {
|
|
1081
1149
|
return new Set(pythonGlobalBindings(name, filePath, context).flatMap((b) => (b.kind === 'import' ? [b.key] : [])));
|
|
1082
1150
|
}
|
|
1151
|
+
function pythonFunctionImportKeys(name, filePath, context) {
|
|
1152
|
+
return pythonNameScan(context, `fnimports\0${filePath}\0${name}`, () => {
|
|
1153
|
+
const lines = pythonMemberLines(filePath, context);
|
|
1154
|
+
const statements = pythonStatementStarts(filePath, context);
|
|
1155
|
+
const keys = new Set();
|
|
1156
|
+
for (const i of pythonFunctionImportLines(filePath, context)) {
|
|
1157
|
+
for (const b of pythonLineBindings(lines, i, statements, name))
|
|
1158
|
+
if (b.kind === 'import')
|
|
1159
|
+
keys.add(b.key);
|
|
1160
|
+
}
|
|
1161
|
+
return keys;
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
function pythonFunctionImportLines(filePath, context) {
|
|
1165
|
+
return pythonNameScan(context, `fnimportlines\0${filePath}`, () => {
|
|
1166
|
+
const lines = pythonMemberLines(filePath, context);
|
|
1167
|
+
const statements = pythonStatementStarts(filePath, context);
|
|
1168
|
+
const inDef = new Uint8Array(lines.length + 1);
|
|
1169
|
+
for (const def of context.getNodesInFile(filePath)) {
|
|
1170
|
+
if (def.kind === 'function' || def.kind === 'method')
|
|
1171
|
+
inDef.fill(1, def.startLine, Math.min(def.endLine, lines.length));
|
|
1172
|
+
}
|
|
1173
|
+
const out = [];
|
|
1174
|
+
for (let i = 0; i < lines.length; i++)
|
|
1175
|
+
if (inDef[i] && statements[i] && /\bimport\b/.test(lines[i]))
|
|
1176
|
+
out.push(i);
|
|
1177
|
+
return out;
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1083
1180
|
function pythonImportKeys(name, filePath, context) {
|
|
1084
1181
|
return pythonNameScan(context, `imports\0${filePath}\0${name}`, () => scanPythonImportKeys(name, filePath, context));
|
|
1085
1182
|
}
|
|
@@ -1502,7 +1599,7 @@ function pythonFieldType(receiver, owner, ref, context) {
|
|
|
1502
1599
|
function matchFunctionRef(ref, context) {
|
|
1503
1600
|
if (ref.referenceName.startsWith('this.'))
|
|
1504
1601
|
return null;
|
|
1505
|
-
if ((ref.language === 'python' || ref.language === 'go') && ref.referenceName.includes('.')) {
|
|
1602
|
+
if ((ref.language === 'python' || ref.language === 'go' || ref.language === 'csharp') && ref.referenceName.includes('.')) {
|
|
1506
1603
|
return matchMemberFunctionRef(ref, context);
|
|
1507
1604
|
}
|
|
1508
1605
|
const bareFnOnly = ref.language === 'typescript' || ref.language === 'tsx' ||
|
|
@@ -1814,6 +1911,46 @@ function isTsTypeInScope(n, ref, context) {
|
|
|
1814
1911
|
return false;
|
|
1815
1912
|
return scope.globalWords.has(`${n.startLine}:${n.startColumn}`);
|
|
1816
1913
|
}
|
|
1914
|
+
const JS_AUTO_IMPORT_PACKAGES = ['nuxt', 'nuxt3', '@nuxt/kit', 'unplugin-auto-import'];
|
|
1915
|
+
function isJsBareGlobalName(ref, context) {
|
|
1916
|
+
if ((ref.referenceKind !== 'calls' && ref.referenceKind !== 'instantiates') || !JS_FAMILY.has(ref.language) ||
|
|
1917
|
+
!js_builtins_1.JS_STANDARD_GLOBALS.has(ref.referenceName) || !TS_JS_FILE.test(ref.filePath) ||
|
|
1918
|
+
context.getImportMappings?.(ref.filePath, ref.language)?.some((m) => m.localName === ref.referenceName))
|
|
1919
|
+
return false;
|
|
1920
|
+
const scope = tsGlobalScope(ref.filePath, context);
|
|
1921
|
+
return !!scope && !scope.script && !scope.importAliases.has(ref.referenceName) &&
|
|
1922
|
+
!JS_AUTO_IMPORT_PACKAGES.some((p) => context.isDeclaredPackage?.(p, ref.filePath) === true) &&
|
|
1923
|
+
isJsWrittenBare(ref, context) && !isJsBoundAtRef(ref, context);
|
|
1924
|
+
}
|
|
1925
|
+
function isJsBoundAtRef(ref, context) {
|
|
1926
|
+
const file = jsScopeFile(ref.filePath, context);
|
|
1927
|
+
if (!file)
|
|
1928
|
+
return isLocallyBoundJsName(ref.referenceName, ref.filePath, context);
|
|
1929
|
+
const at = (file.lineStarts[ref.line - 1] ?? file.code.length) + ref.column;
|
|
1930
|
+
return jsBindingAt(ref.referenceName, file, at) !== null;
|
|
1931
|
+
}
|
|
1932
|
+
function isJsWrittenBare(ref, context) {
|
|
1933
|
+
const line = context.getFileLines?.(ref.filePath)?.[ref.line - 1] ?? context.readFile(ref.filePath)?.split(/\r?\n/)[ref.line - 1] ?? '';
|
|
1934
|
+
if (ref.referenceKind === 'instantiates') {
|
|
1935
|
+
const made = /^new\s+([\w$.]+)/.exec(line.slice(ref.column));
|
|
1936
|
+
if (made)
|
|
1937
|
+
return made[1] === ref.referenceName;
|
|
1938
|
+
}
|
|
1939
|
+
return line.startsWith(ref.referenceName, ref.column) && !isWrittenQualified(ref, context);
|
|
1940
|
+
}
|
|
1941
|
+
function isJsValueInScope(n, ref, context) {
|
|
1942
|
+
if (n.filePath === ref.filePath || !TS_JS_FILE.test(n.filePath))
|
|
1943
|
+
return true;
|
|
1944
|
+
const scope = tsGlobalScope(n.filePath, context);
|
|
1945
|
+
if (!scope)
|
|
1946
|
+
return true;
|
|
1947
|
+
if ((0, query_utils_1.isTestFile)(n.filePath) && !(0, query_utils_1.isTestFile)(ref.filePath))
|
|
1948
|
+
return false;
|
|
1949
|
+
if (scope.globalWords.has(`${n.startLine}:${n.startColumn}`))
|
|
1950
|
+
return true;
|
|
1951
|
+
const line = context.getFileLines?.(n.filePath)?.[n.startLine - 1] ?? context.readFile(n.filePath)?.split(/\r?\n/)[n.startLine - 1] ?? '';
|
|
1952
|
+
return new RegExp(`(?:^|[^\\w$.])(?:window|globalThis|global|self)\\s*\\.\\s*${(0, utils_1.escapeRegExp)(n.name)}\\s*=(?!=)`).test(line);
|
|
1953
|
+
}
|
|
1817
1954
|
function crossesWorkspaceRoot(n, ref, context) {
|
|
1818
1955
|
return JS_FAMILY.has(ref.language) && JS_FAMILY.has(n.language) &&
|
|
1819
1956
|
(0, workspace_packages_1.leavesWorkspaceRoot)(ref.filePath, n.filePath, context.getWorkspacePackages?.());
|
|
@@ -2082,9 +2219,17 @@ function kotlinExtensionOnImportedType(ref, context) {
|
|
|
2082
2219
|
if (!binding)
|
|
2083
2220
|
return null;
|
|
2084
2221
|
const pkg = binding.source.slice(0, binding.source.lastIndexOf('.'));
|
|
2085
|
-
const extensions = context.
|
|
2086
|
-
if (n.kind !== 'method' || n.language !== 'kotlin'
|
|
2222
|
+
const extensions = context.getNodesByName(call[2]).filter((n) => {
|
|
2223
|
+
if (n.kind !== 'method' || n.language !== 'kotlin')
|
|
2087
2224
|
return false;
|
|
2225
|
+
const receiver = n.qualifiedName.slice(0, Math.max(0, n.qualifiedName.lastIndexOf('::')));
|
|
2226
|
+
const alias = context.getImportMappings(n.filePath, 'kotlin').find((m) => m.localName === receiver && m.localName !== m.exportedName);
|
|
2227
|
+
if (alias ? alias.source !== binding.source : receiver !== binding.exportedName)
|
|
2228
|
+
return false;
|
|
2229
|
+
if (!isKotlinTopLevelVisible(n, ref, context))
|
|
2230
|
+
return false;
|
|
2231
|
+
if (alias)
|
|
2232
|
+
return true;
|
|
2088
2233
|
const scope = kotlinFileScope(n.filePath, context);
|
|
2089
2234
|
return scope.imports.has(binding.source) || scope.stars.has(pkg);
|
|
2090
2235
|
});
|
|
@@ -3310,6 +3455,41 @@ function isJavaTypeVisible(candidate, ref, context) {
|
|
|
3310
3455
|
const ownerFqn = fqn.slice(0, fqn.lastIndexOf('.'));
|
|
3311
3456
|
return here.single.has(fqn) || here.demand.has(ownerFqn);
|
|
3312
3457
|
}
|
|
3458
|
+
function javaClassInScope(name, filePath, context) {
|
|
3459
|
+
const all = context.getNodesByName(name).filter((n) => n.language === 'java' && JAVA_TYPE_KINDS_VISIBLE.has(n.kind));
|
|
3460
|
+
if (all.length === 0)
|
|
3461
|
+
return undefined;
|
|
3462
|
+
const pkgOf = (n) => javaFileScope(n.filePath, context).pkg;
|
|
3463
|
+
if (all.some((n) => n.qualifiedName !== (pkgOf(n) ? `${pkgOf(n)}::${name}` : name)))
|
|
3464
|
+
return undefined;
|
|
3465
|
+
const one = (found) => (found.length === 1 ? found[0] : undefined);
|
|
3466
|
+
const own = all.filter((n) => n.filePath === filePath);
|
|
3467
|
+
if (own.length > 0)
|
|
3468
|
+
return one(own);
|
|
3469
|
+
const here = javaFileScope(filePath, context);
|
|
3470
|
+
const imported = all.filter((n) => here.single.has(pkgOf(n) ? `${pkgOf(n)}.${name}` : name));
|
|
3471
|
+
if (imported.length > 0)
|
|
3472
|
+
return one(imported);
|
|
3473
|
+
const local = all.filter((n) => pkgOf(n) === here.pkg);
|
|
3474
|
+
if (local.length > 0)
|
|
3475
|
+
return one(local);
|
|
3476
|
+
const onDemand = all.filter((n) => here.demand.has(pkgOf(n)));
|
|
3477
|
+
if (onDemand.length === 0)
|
|
3478
|
+
return undefined;
|
|
3479
|
+
return new Set(onDemand.map(pkgOf)).size > 1 ? null : one(onDemand);
|
|
3480
|
+
}
|
|
3481
|
+
function javaTypeFqn(n) {
|
|
3482
|
+
return n.qualifiedName.replace(/::/g, '.');
|
|
3483
|
+
}
|
|
3484
|
+
function javaQualifiedReceiverType(written, context) {
|
|
3485
|
+
const segs = written.split('.');
|
|
3486
|
+
const first = segs.findIndex((s) => /^[A-Z]/.test(s));
|
|
3487
|
+
if (first < 1 || !segs.slice(0, first).every((s) => /^[a-z_][\w]*$/.test(s)) || !segs.slice(first).every((s) => /^[A-Z][\w$]*$/.test(s)))
|
|
3488
|
+
return undefined;
|
|
3489
|
+
const qn = `${segs.slice(0, first).join('.')}::${segs.slice(first).join('::')}`;
|
|
3490
|
+
const types = context.getNodesByQualifiedName(qn).filter((n) => n.language === 'java' && JAVA_TYPE_KINDS_VISIBLE.has(n.kind));
|
|
3491
|
+
return types.length === 1 ? types[0] : undefined;
|
|
3492
|
+
}
|
|
3313
3493
|
function javaNestedInQualifier(ref, qualifier, context) {
|
|
3314
3494
|
const owner = qualifier.slice(qualifier.lastIndexOf('.') + 1);
|
|
3315
3495
|
return context.getNodesByName(ref.referenceName).some((n) => {
|
|
@@ -3546,6 +3726,117 @@ function isJsGlobalSelf(head, ref, context) {
|
|
|
3546
3726
|
function isPythonSelfCall(ref, context) {
|
|
3547
3727
|
return ref.language === 'python' && bareCallReceiver(ref, context)?.receiver === 'self';
|
|
3548
3728
|
}
|
|
3729
|
+
function isJsThisCall(ref, context) {
|
|
3730
|
+
return JS_FAMILY.has(ref.language) && bareCallReceiver(ref, context)?.receiver === 'self';
|
|
3731
|
+
}
|
|
3732
|
+
function pythonSelfCallReaches(target, ref, context) {
|
|
3733
|
+
if (ref.language !== 'python' || ref.referenceKind !== 'calls' || target.kind === 'class')
|
|
3734
|
+
return true;
|
|
3735
|
+
if (!/^[A-Za-z_]\w*$/.test(ref.referenceName))
|
|
3736
|
+
return true;
|
|
3737
|
+
const receiver = bareCallReceiver(ref, context)?.receiver;
|
|
3738
|
+
if (receiver !== 'self' && receiver !== 'cls')
|
|
3739
|
+
return true;
|
|
3740
|
+
const owner = context.getNodesInFile(ref.filePath)
|
|
3741
|
+
.filter((n) => n.kind === 'class' && n.startLine <= ref.line && n.endLine >= ref.line)
|
|
3742
|
+
.sort((a, b) => b.startLine - a.startLine)[0];
|
|
3743
|
+
if (!owner)
|
|
3744
|
+
return true;
|
|
3745
|
+
if (target.kind === 'method') {
|
|
3746
|
+
const cut = target.qualifiedName.lastIndexOf('::');
|
|
3747
|
+
const holderName = cut > 0 ? target.qualifiedName.slice(0, cut) : '';
|
|
3748
|
+
if (holderName && pythonClassLineage(owner, ref, context).has(`${target.filePath}\0${holderName}`))
|
|
3749
|
+
return true;
|
|
3750
|
+
const holder = holderName ? context.getNodesByQualifiedName(holderName).find((n) => n.kind === 'class' && n.filePath === target.filePath) : undefined;
|
|
3751
|
+
if (holder && pythonDerivesFrom(holder, owner, ref, context))
|
|
3752
|
+
return true;
|
|
3753
|
+
}
|
|
3754
|
+
const member = ref.referenceName;
|
|
3755
|
+
const values = pythonNameScan(context, `attribute\0${owner.id}\0${member}`, () => pythonAttributeValues(owner, member, ref, context));
|
|
3756
|
+
if (values.length > 0)
|
|
3757
|
+
return values.some((v) => pythonValueNames(v, target, ref, context));
|
|
3758
|
+
if (target.qualifiedName.includes('::'))
|
|
3759
|
+
return true;
|
|
3760
|
+
return target.kind === 'function' && target.filePath === ref.filePath;
|
|
3761
|
+
}
|
|
3762
|
+
function pythonClassLineage(cls, ref, context) {
|
|
3763
|
+
return pythonNameScan(context, `lineage\0${cls.id}`, () => new Set([cls, ...pythonClassLineageNodes(cls, ref, context)].map((c) => `${c.filePath}\0${c.qualifiedName}`)));
|
|
3764
|
+
}
|
|
3765
|
+
function pythonAttributeValues(cls, member, ref, context) {
|
|
3766
|
+
const out = [];
|
|
3767
|
+
const attr = new RegExp(`^\\(?\\s*(?:self|cls)\\s*\\.\\s*${(0, utils_1.escapeRegExp)(member)}\\s*\\)?$`);
|
|
3768
|
+
for (const c of [cls, ...pythonClassLineageNodes(cls, ref, context)]) {
|
|
3769
|
+
const lines = pythonMemberLines(c.filePath, context);
|
|
3770
|
+
const starts = pythonStatementStarts(c.filePath, context);
|
|
3771
|
+
const own = new Set(pythonOwnLines(c, c.filePath, context));
|
|
3772
|
+
for (let i = c.startLine; i < Math.min(c.endLine, lines.length); i++) {
|
|
3773
|
+
if (!starts[i] || !lines[i].includes(member))
|
|
3774
|
+
continue;
|
|
3775
|
+
const assignment = pythonAssignment(pythonBlankStrings(lines[i]));
|
|
3776
|
+
if (!assignment || assignment.augmented)
|
|
3777
|
+
continue;
|
|
3778
|
+
for (const target of assignment.targets) {
|
|
3779
|
+
const t = target.split(':')[0].trim();
|
|
3780
|
+
const parts = pythonTopLevelParts(t.replace(/^\((.*)\)$/, '$1')).map((p) => p.trim());
|
|
3781
|
+
const binds = parts.some((p) => attr.test(p)) || (own.has(i) && parts.includes(member));
|
|
3782
|
+
if (binds)
|
|
3783
|
+
out.push({ value: parts.length === 1 ? assignment.value.trim() : '', filePath: c.filePath, line: i + 1 });
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
return out;
|
|
3788
|
+
}
|
|
3789
|
+
function pythonClassLineageNodes(cls, ref, context) {
|
|
3790
|
+
return pythonNameScan(context, `bases\0${cls.id}`, () => {
|
|
3791
|
+
const out = [];
|
|
3792
|
+
const queue = pythonBases(cls, ref, context);
|
|
3793
|
+
const seen = new Set([cls.id]);
|
|
3794
|
+
while (queue.length > 0 && seen.size < 32) {
|
|
3795
|
+
const c = queue.shift();
|
|
3796
|
+
if (seen.has(c.id))
|
|
3797
|
+
continue;
|
|
3798
|
+
seen.add(c.id);
|
|
3799
|
+
out.push(c);
|
|
3800
|
+
queue.push(...pythonBases(c, ref, context));
|
|
3801
|
+
}
|
|
3802
|
+
return out;
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
function pythonValueNames(bound, target, ref, context) {
|
|
3806
|
+
const value = bound.value.replace(/^(?:static|class)method\s*\(\s*([\s\S]*?)\s*\)$/, '$1');
|
|
3807
|
+
const m = /^((?:[A-Za-z_]\w*\s*\.\s*)*)([A-Za-z_]\w*)$/.exec(value);
|
|
3808
|
+
if (!m || m[2] !== target.name)
|
|
3809
|
+
return false;
|
|
3810
|
+
if (m[1])
|
|
3811
|
+
return true;
|
|
3812
|
+
return pythonReceiverBinding(target.name, { ...ref, filePath: bound.filePath, line: bound.line, column: 0 }, context) !== 'local';
|
|
3813
|
+
}
|
|
3814
|
+
function isLexicalBindingOfJsThisCall(target, ref, context) {
|
|
3815
|
+
if (!JS_FAMILY.has(ref.language) || ref.referenceKind !== 'calls')
|
|
3816
|
+
return false;
|
|
3817
|
+
if (target.kind === 'function') {
|
|
3818
|
+
if (!isJsDeclaredFunction(target, context))
|
|
3819
|
+
return false;
|
|
3820
|
+
const name = target.name.replace(/\$/g, '\\$');
|
|
3821
|
+
if (new RegExp(String.raw `\.\s*${name}\s*=\s*${name}(?![\w$])`).test(context.readFile(ref.filePath) ?? ''))
|
|
3822
|
+
return false;
|
|
3823
|
+
}
|
|
3824
|
+
else if (target.kind !== 'constant' && target.kind !== 'variable') {
|
|
3825
|
+
return false;
|
|
3826
|
+
}
|
|
3827
|
+
const written = bareCallReceiver(ref, context);
|
|
3828
|
+
return written !== null && (written.receiver === 'self' || written.links.length > 0);
|
|
3829
|
+
}
|
|
3830
|
+
function isJsDeclaredFunction(n, context) {
|
|
3831
|
+
const line = (context.getFileLines?.(n.filePath) ?? context.readFile(n.filePath)?.split(/\r?\n/))?.[n.startLine - 1];
|
|
3832
|
+
if (line === undefined)
|
|
3833
|
+
return false;
|
|
3834
|
+
const head = line.slice(Math.max(0, n.startColumn - 200), n.startColumn);
|
|
3835
|
+
if (n.startColumn <= 200 && /^\s*(?:export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?$/.test(head) &&
|
|
3836
|
+
/^(?:export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?function\b/.test(line.slice(n.startColumn, n.startColumn + 64)))
|
|
3837
|
+
return true;
|
|
3838
|
+
return /(?:^|[^\w$.])(?:const|let|var)\s+[\w$]+\s*(?::[^=]*)?=\s*(?:async\s*)?$/.test(head);
|
|
3839
|
+
}
|
|
3549
3840
|
function isCollapsedNonRecursion(ref, context) {
|
|
3550
3841
|
const written = bareCallReceiver(ref, context);
|
|
3551
3842
|
if (!written || written.receiver === 'self')
|
|
@@ -3574,6 +3865,27 @@ function isCollapsedSelfRecursion(chain, ref, context) {
|
|
|
3574
3865
|
function isBareJsCall(ref, context) {
|
|
3575
3866
|
return JS_FAMILY.has(ref.language) && isReceiverLessCall(ref, context);
|
|
3576
3867
|
}
|
|
3868
|
+
function isRefusedDeepThisTarget(result, ref, context) {
|
|
3869
|
+
if (!JS_FAMILY.has(ref.language) || ref.referenceKind !== 'calls' || !/^[A-Za-z_$][\w$]*$/.test(ref.referenceName))
|
|
3870
|
+
return false;
|
|
3871
|
+
const links = bareCallReceiver(ref, context)?.links ?? [];
|
|
3872
|
+
if (links.length < 2)
|
|
3873
|
+
return false;
|
|
3874
|
+
if (result.resolvedBy === 'import')
|
|
3875
|
+
return true;
|
|
3876
|
+
const target = context.getNodeById?.(result.targetNodeId);
|
|
3877
|
+
if (!target)
|
|
3878
|
+
return false;
|
|
3879
|
+
if (js_builtins_1.JS_BUILTIN_METHODS.has(ref.referenceName) && !(target.kind === 'method' && receiverNamesOwner(links[links.length - 1], target, context)))
|
|
3880
|
+
return true;
|
|
3881
|
+
return target.kind === 'enum_member' || ((target.kind === 'property' || target.kind === 'field') && !tsMayBeCallable(target));
|
|
3882
|
+
}
|
|
3883
|
+
function tsMayBeCallable(n) {
|
|
3884
|
+
const type = (n.signature ?? '').trim().slice(0, Math.max(0, (n.signature ?? '').trim().length - n.name.length)).trim();
|
|
3885
|
+
if (type === '')
|
|
3886
|
+
return true;
|
|
3887
|
+
return !/(?:\[\]|^(?:string|number|boolean|bigint|symbol|undefined|null|(?:Readonly)?(?:Array|Map|Set|WeakMap|WeakSet)<.*>))$/.test(type);
|
|
3888
|
+
}
|
|
3577
3889
|
function isBareGoCall(ref, context) {
|
|
3578
3890
|
return ref.language === 'go' && isReceiverLessCall(ref, context);
|
|
3579
3891
|
}
|
|
@@ -3650,6 +3962,8 @@ function isReceiverLessCall(ref, context) {
|
|
|
3650
3962
|
return true;
|
|
3651
3963
|
if (line[end - 1] === ')' && JS_FAMILY.has(ref.language))
|
|
3652
3964
|
return true;
|
|
3965
|
+
if (end >= 3 && line.startsWith('...', end - 3) && JS_FAMILY.has(ref.language))
|
|
3966
|
+
return true;
|
|
3653
3967
|
let start = end;
|
|
3654
3968
|
while (start > 0 && WORD_CHAR.test(line[start - 1]))
|
|
3655
3969
|
start--;
|
|
@@ -3719,11 +4033,15 @@ function fitsPythonCallShape(n, shape, ref, context) {
|
|
|
3719
4033
|
if (shape.kind === 'bare') {
|
|
3720
4034
|
if (n.kind === 'method')
|
|
3721
4035
|
return false;
|
|
3722
|
-
if (n.filePath
|
|
4036
|
+
if (n.filePath !== ref.filePath && isPythonNameImportedFromOutside(ref.referenceName, ref, context))
|
|
4037
|
+
return false;
|
|
4038
|
+
if (isFixtureInReach(n, ref.filePath, context))
|
|
3723
4039
|
return true;
|
|
3724
|
-
if (
|
|
4040
|
+
if (!n.qualifiedName.includes('::') && isPythonBoundAroundCall(ref, context))
|
|
3725
4041
|
return false;
|
|
3726
|
-
|
|
4042
|
+
if (n.filePath === ref.filePath)
|
|
4043
|
+
return true;
|
|
4044
|
+
return !isPythonLocallyBound(ref.referenceName, ref, context);
|
|
3727
4045
|
}
|
|
3728
4046
|
if (n.kind === 'method') {
|
|
3729
4047
|
const cut = n.qualifiedName.lastIndexOf('::');
|
|
@@ -3831,6 +4149,15 @@ function isDecoratedFixture(n, context) {
|
|
|
3831
4149
|
const PY_LOCAL_BINDS = new WeakMap();
|
|
3832
4150
|
const PY_LOCAL_FILE = new WeakMap();
|
|
3833
4151
|
const PY_LOCAL_LAST = new WeakMap();
|
|
4152
|
+
const PY_BOUND_AROUND_LAST = new WeakMap();
|
|
4153
|
+
function isPythonBoundAroundCall(ref, context) {
|
|
4154
|
+
const last = PY_BOUND_AROUND_LAST.get(context);
|
|
4155
|
+
if (last?.ref === ref)
|
|
4156
|
+
return last.bound;
|
|
4157
|
+
const bound = pythonReceiverBinding(ref.referenceName, ref, context) === 'local';
|
|
4158
|
+
PY_BOUND_AROUND_LAST.set(context, { ref, bound });
|
|
4159
|
+
return bound;
|
|
4160
|
+
}
|
|
3834
4161
|
function isPythonLocallyBound(name, ref, context) {
|
|
3835
4162
|
const last = PY_LOCAL_LAST.get(context);
|
|
3836
4163
|
if (last?.ref === ref && last.name === name)
|
|
@@ -4062,8 +4389,9 @@ function isDartConstructor(n, context) {
|
|
|
4062
4389
|
const owner = cut > 0 ? n.qualifiedName.slice(0, cut).split('::').pop() : '';
|
|
4063
4390
|
const lines = context.getFileLines?.(n.filePath) ?? context.readFile(n.filePath)?.split(/\r?\n/) ?? [];
|
|
4064
4391
|
const head = (lines[n.startLine - 1] ?? '').slice(n.startColumn);
|
|
4065
|
-
const
|
|
4066
|
-
|
|
4392
|
+
const name = (0, utils_1.escapeRegExp)(n.name);
|
|
4393
|
+
const constructor = owner !== '' && (new RegExp(String.raw `^(?:(?:const|factory|external)\s+)*${(0, utils_1.escapeRegExp)(owner)}\s*\.\s*${name}(?![\w$])`).test(head) ||
|
|
4394
|
+
new RegExp(String.raw `^(?:(?:const|external)\s+)*(?:new|factory)\s+${name}(?![\w$])|^\.\s*${name}\s*\(`).test(head));
|
|
4067
4395
|
memo.set(n.id, constructor);
|
|
4068
4396
|
return constructor;
|
|
4069
4397
|
}
|
|
@@ -6354,11 +6682,14 @@ function isCsharpMemberInScope(n, ref, context) {
|
|
|
6354
6682
|
const owner = n.qualifiedName.slice(0, cut).split(/::|\./).pop();
|
|
6355
6683
|
if (csharpStaticUsings(ref.filePath, context).has(owner))
|
|
6356
6684
|
return true;
|
|
6685
|
+
return csharpTypesAround(ref, context, owner) !== false;
|
|
6686
|
+
}
|
|
6687
|
+
function csharpTypesAround(ref, context, owner) {
|
|
6357
6688
|
const around = context
|
|
6358
6689
|
.getNodesInFile(ref.filePath)
|
|
6359
6690
|
.filter((t) => CSHARP_TYPE_KINDS.has(t.kind) && t.startLine <= ref.line && t.endLine >= ref.line);
|
|
6360
6691
|
if (around.length === 0)
|
|
6361
|
-
return
|
|
6692
|
+
return undefined;
|
|
6362
6693
|
const seen = new Set();
|
|
6363
6694
|
const queue = around.map((t) => t.name);
|
|
6364
6695
|
while (queue.length > 0 && seen.size < 40) {
|
|
@@ -6372,6 +6703,28 @@ function isCsharpMemberInScope(n, ref, context) {
|
|
|
6372
6703
|
}
|
|
6373
6704
|
return false;
|
|
6374
6705
|
}
|
|
6706
|
+
function matchCsharpCallResultCall(inner, method, ref, context) {
|
|
6707
|
+
const self = /^(?:this|base)\s*\.\s*/.exec(inner);
|
|
6708
|
+
const name = (self ? inner.slice(self[0].length) : inner).replace(/<[\s\S]*>$/, '');
|
|
6709
|
+
if (!/^[A-Za-z_]\w*$/.test(name))
|
|
6710
|
+
return null;
|
|
6711
|
+
const statics = self ? new Set() : csharpStaticUsings(ref.filePath, context);
|
|
6712
|
+
const returnTypes = new Set();
|
|
6713
|
+
for (const n of context.getNodesByName(name)) {
|
|
6714
|
+
if (n.language !== 'csharp' || n.kind !== 'method' || !n.returnType)
|
|
6715
|
+
continue;
|
|
6716
|
+
const cut = n.qualifiedName.lastIndexOf('::');
|
|
6717
|
+
if (cut < 0)
|
|
6718
|
+
continue;
|
|
6719
|
+
const owner = n.qualifiedName.slice(0, cut).split(/::|\./).pop();
|
|
6720
|
+
if (statics.has(owner) || csharpTypesAround(ref, context, owner) === true)
|
|
6721
|
+
returnTypes.add(n.returnType);
|
|
6722
|
+
}
|
|
6723
|
+
if (returnTypes.size !== 1)
|
|
6724
|
+
return null;
|
|
6725
|
+
const ret = [...returnTypes][0];
|
|
6726
|
+
return resolveMethodOnType(ret, method, ref, context, 0.85, 'instance-method', importedFqnOf(ret, ref, context));
|
|
6727
|
+
}
|
|
6375
6728
|
function csharpSupertypesOf(typeName, context) {
|
|
6376
6729
|
let memo = CSHARP_SUPERS.get(context);
|
|
6377
6730
|
if (!memo)
|
|
@@ -8071,6 +8424,70 @@ function phpTypeMethod(qn, name, context) {
|
|
|
8071
8424
|
return found;
|
|
8072
8425
|
}
|
|
8073
8426
|
const PHP_TYPE_METHODS = new WeakMap();
|
|
8427
|
+
function phpClosingParen(text, open) {
|
|
8428
|
+
let depth = 0;
|
|
8429
|
+
for (let i = open; i < text.length; i++) {
|
|
8430
|
+
const c = text[i];
|
|
8431
|
+
if (c === '"' || c === "'") {
|
|
8432
|
+
for (i++; i < text.length && text[i] !== c; i++)
|
|
8433
|
+
if (text[i] === '\\')
|
|
8434
|
+
i++;
|
|
8435
|
+
}
|
|
8436
|
+
else if (c === '(')
|
|
8437
|
+
depth++;
|
|
8438
|
+
else if (c === ')' && --depth === 0)
|
|
8439
|
+
return i;
|
|
8440
|
+
}
|
|
8441
|
+
return -1;
|
|
8442
|
+
}
|
|
8443
|
+
function phpNewReceiverShape(name) {
|
|
8444
|
+
if (!/^\(\s*new\s/i.test(name))
|
|
8445
|
+
return null;
|
|
8446
|
+
const close = phpClosingParen(name, 0);
|
|
8447
|
+
if (close < 0)
|
|
8448
|
+
return null;
|
|
8449
|
+
const method = /^\.(\w+)$/.exec(name.slice(close + 1))?.[1];
|
|
8450
|
+
if (!method)
|
|
8451
|
+
return null;
|
|
8452
|
+
const inner = name.slice(1, close);
|
|
8453
|
+
const head = /^\s*new\s+(\\?[A-Za-z_]\w*(?:\\[A-Za-z_]\w*)*)\s*/i.exec(inner);
|
|
8454
|
+
if (!head || /^class$/i.test(head[1]))
|
|
8455
|
+
return null;
|
|
8456
|
+
const args = inner.slice(head[0].length).trimEnd();
|
|
8457
|
+
if (args !== '' && !(args.startsWith('(') && phpClosingParen(args, 0) === args.length - 1))
|
|
8458
|
+
return null;
|
|
8459
|
+
return { written: head[1], method };
|
|
8460
|
+
}
|
|
8461
|
+
function matchPhpNewReceiverCall(ref, context) {
|
|
8462
|
+
const shape = phpNewReceiverShape(ref.referenceName);
|
|
8463
|
+
if (!shape)
|
|
8464
|
+
return undefined;
|
|
8465
|
+
let qn;
|
|
8466
|
+
if (/^(?:self|static|parent)$/i.test(shape.written)) {
|
|
8467
|
+
if (phpAnonymousClassAt(ref, context))
|
|
8468
|
+
return undefined;
|
|
8469
|
+
const enclosing = context
|
|
8470
|
+
.getNodesInFile(ref.filePath)
|
|
8471
|
+
.filter((n) => PHP_TYPE_KINDS.has(n.kind) && n.startLine <= ref.line && n.endLine >= ref.line)
|
|
8472
|
+
.sort((a, b) => b.startLine - a.startLine)[0];
|
|
8473
|
+
if (!enclosing)
|
|
8474
|
+
return null;
|
|
8475
|
+
if (/^parent$/i.test(shape.written)) {
|
|
8476
|
+
const parent = phpSupertypeQns(enclosing, context).find((qn) => context.getNodesByQualifiedName(qn).some((d) => d.language === 'php' && d.kind === 'class'));
|
|
8477
|
+
if (!parent)
|
|
8478
|
+
return null;
|
|
8479
|
+
qn = parent;
|
|
8480
|
+
}
|
|
8481
|
+
else {
|
|
8482
|
+
qn = enclosing.qualifiedName;
|
|
8483
|
+
}
|
|
8484
|
+
}
|
|
8485
|
+
else {
|
|
8486
|
+
qn = phpTypeQn(shape.written, ref.filePath, context);
|
|
8487
|
+
}
|
|
8488
|
+
const method = phpTypeMethod(qn, shape.method, context)?.method;
|
|
8489
|
+
return method ? { original: ref, targetNodeId: method.id, confidence: 0.9, resolvedBy: 'instance-method' } : null;
|
|
8490
|
+
}
|
|
8074
8491
|
const ELOQUENT_FACTORY_CALL = /^\s*(?:(?:\$\w+\s*=\s*)*)(?:tap\s*\(\s*)?(\\?[A-Z][\w\\]*)::(?:query\(\)\s*->\s*)?(?:create|createQuietly|forceCreate|forceCreateQuietly|createOrFirst|firstOrCreate|firstOrNew|updateOrCreate|incrementOrCreate|find|findOrFail|findOrNew|findSole|firstOrFail|sole)\s*\(/;
|
|
8075
8492
|
function phpModelFactoryLocalType(receiver, ref, context) {
|
|
8076
8493
|
if (!/^\w+$/.test(receiver))
|
|
@@ -8290,7 +8707,7 @@ function rustUsesOf(filePath, context) {
|
|
|
8290
8707
|
return hit;
|
|
8291
8708
|
const uses = {
|
|
8292
8709
|
names: new Set(), globs: new Set(), external: new Set(), bound: new Set(), boundFrom: new Map(),
|
|
8293
|
-
paths: new Map(), stdPaths: new Map(), globPaths: [], blocks: [], pathMods: new Set(), mods: new Set(), main: false, balanced: true, lineStarts: [],
|
|
8710
|
+
paths: new Map(), stdPaths: new Map(), globPaths: [], blocks: [], pathMods: new Set(), mods: new Set(), modDecls: new Map(), main: false, balanced: true, lineStarts: [],
|
|
8294
8711
|
};
|
|
8295
8712
|
const leaves = (tree) => [
|
|
8296
8713
|
...[...tree.matchAll(/([A-Za-z_]\w*)\s*(?=[,}]|$|\s+as\b)|\bas\s+([A-Za-z_]\w*)/g)]
|
|
@@ -8363,6 +8780,11 @@ function rustUsesOf(filePath, context) {
|
|
|
8363
8780
|
if (!pathModAt.has(m.index))
|
|
8364
8781
|
uses.mods.add(m[1]);
|
|
8365
8782
|
}
|
|
8783
|
+
for (const m of text.matchAll(/\bmod\s+(?:r#)?([A-Za-z_]\w*)\s*[;{]/g)) {
|
|
8784
|
+
const key = `${rustBlockAt(layout.blocks, m.index)?.open ?? -1}\0${m[1]}`;
|
|
8785
|
+
const pub = /\bpub(?:\s*\([^()]*\))?\s*$/.test(text.slice(Math.max(0, m.index - 48), m.index));
|
|
8786
|
+
uses.modDecls.set(key, pub || uses.modDecls.get(key) === true);
|
|
8787
|
+
}
|
|
8366
8788
|
uses.main = /^(?:pub\s+)?(?:async\s+)?fn\s+main\s*\(|^[ \t]*#!\[\s*no_main\s*\]/m.test(text);
|
|
8367
8789
|
for (let at = 0; at !== -1; at = text.indexOf('\n', at) + 1 || -1)
|
|
8368
8790
|
uses.lineStarts.push(at);
|
|
@@ -8822,11 +9244,14 @@ function rustLibModule(crateDir, context) {
|
|
|
8822
9244
|
const file = rustCrateGraph(context).crates.get(crateDir)?.lib ?? (crateDir === '' ? 'src/lib.rs' : `${crateDir}/src/lib.rs`);
|
|
8823
9245
|
return context.fileExists(file) ? { file, dir: rustParentDir(file), block: null, root: true } : null;
|
|
8824
9246
|
}
|
|
8825
|
-
function rustSubmodule(m, name, context, depth = 0) {
|
|
9247
|
+
function rustSubmodule(m, name, context, depth = 0, publicOnly = false) {
|
|
8826
9248
|
if (m.choices)
|
|
8827
|
-
return rustCfgChoice(m.choices.map((c) => rustSubmodule(c, name, context, depth)).filter((c) => c !== null));
|
|
9249
|
+
return rustCfgChoice(m.choices.map((c) => rustSubmodule(c, name, context, depth, publicOnly)).filter((c) => c !== null));
|
|
8828
9250
|
const dir = rustJoin(m.dir, name);
|
|
8829
9251
|
const layout = rustUsesOf(m.file, context);
|
|
9252
|
+
const declared = layout.modDecls.get(`${m.block?.open ?? -1}\0${name}`);
|
|
9253
|
+
if (publicOnly && declared === false)
|
|
9254
|
+
return null;
|
|
8830
9255
|
if (layout.pathMods.has(name)) {
|
|
8831
9256
|
const decls = rustPathDeclsIn(m.file, context).filter((d) => d.name === name && rustBlockAt(layout.blocks, d.at) === m.block);
|
|
8832
9257
|
const files = new Set();
|
|
@@ -8840,14 +9265,14 @@ function rustSubmodule(m, name, context, depth = 0) {
|
|
|
8840
9265
|
const block = layout.blocks.find((b) => b.name === name && b.parent === m.block);
|
|
8841
9266
|
if (block)
|
|
8842
9267
|
return { file: m.file, dir, block, root: false };
|
|
8843
|
-
for (const file of [`${dir}.rs`, `${dir}/mod.rs`]) {
|
|
9268
|
+
for (const file of !publicOnly || declared ? [`${dir}.rs`, `${dir}/mod.rs`] : []) {
|
|
8844
9269
|
if (context.fileExists(file))
|
|
8845
9270
|
return { file, dir, block: null, root: false };
|
|
8846
9271
|
}
|
|
8847
9272
|
if (depth >= 8)
|
|
8848
9273
|
return null;
|
|
8849
9274
|
for (const p of layout.paths.get(name) ?? []) {
|
|
8850
|
-
if (p.scope || rustBlockAt(layout.blocks, p.at) !== m.block)
|
|
9275
|
+
if (p.scope || (publicOnly && !p.pub) || rustBlockAt(layout.blocks, p.at) !== m.block)
|
|
8851
9276
|
continue;
|
|
8852
9277
|
const passed = rustWalkModules(p.segs, m, context, depth + 1);
|
|
8853
9278
|
if (passed !== null && passed !== 'outside')
|
|
@@ -8855,6 +9280,33 @@ function rustSubmodule(m, name, context, depth = 0) {
|
|
|
8855
9280
|
}
|
|
8856
9281
|
return null;
|
|
8857
9282
|
}
|
|
9283
|
+
function rustGlobbedSubmodule(m, name, context, depth, publicOnly, seen) {
|
|
9284
|
+
if (m.choices) {
|
|
9285
|
+
return rustCfgChoice(m.choices.map((c) => rustGlobbedSubmodule(c, name, context, depth, publicOnly, seen)).filter((c) => c !== null));
|
|
9286
|
+
}
|
|
9287
|
+
if (depth >= 8)
|
|
9288
|
+
return null;
|
|
9289
|
+
const layout = rustUsesOf(m.file, context);
|
|
9290
|
+
if (layout.globPaths.length === 0)
|
|
9291
|
+
return null;
|
|
9292
|
+
const key = `${m.file}\0${m.block?.open ?? -1}\0${name}\0${publicOnly ? 1 : 0}`;
|
|
9293
|
+
if (seen.has(key))
|
|
9294
|
+
return null;
|
|
9295
|
+
seen.add(key);
|
|
9296
|
+
for (const g of layout.globPaths) {
|
|
9297
|
+
if (g.scope || (publicOnly && !g.pub) || rustBlockAt(layout.blocks, g.at) !== m.block)
|
|
9298
|
+
continue;
|
|
9299
|
+
const globbed = rustWalkModules(g.segs, m, context, depth + 1, false);
|
|
9300
|
+
if (globbed === null || globbed === 'outside')
|
|
9301
|
+
continue;
|
|
9302
|
+
const outside = !rustModuleWithin(m, globbed, context);
|
|
9303
|
+
const found = rustSubmodule(globbed, name, context, depth + 1, outside) ??
|
|
9304
|
+
rustGlobbedSubmodule(globbed, name, context, depth + 1, outside, seen);
|
|
9305
|
+
if (found)
|
|
9306
|
+
return found;
|
|
9307
|
+
}
|
|
9308
|
+
return null;
|
|
9309
|
+
}
|
|
8858
9310
|
function rustCfgChoice(mods) {
|
|
8859
9311
|
return mods.length > 1 ? { ...mods[0], choices: mods } : mods[0] ?? null;
|
|
8860
9312
|
}
|
|
@@ -8874,7 +9326,7 @@ function rustSuperModule(m, context) {
|
|
|
8874
9326
|
}
|
|
8875
9327
|
return null;
|
|
8876
9328
|
}
|
|
8877
|
-
function rustWalkModules(segs, from, context, depth = 0) {
|
|
9329
|
+
function rustWalkModules(segs, from, context, depth = 0, globs = true) {
|
|
8878
9330
|
const [first, ...rest] = segs;
|
|
8879
9331
|
if (first === undefined)
|
|
8880
9332
|
return from;
|
|
@@ -8889,6 +9341,8 @@ function rustWalkModules(segs, from, context, depth = 0) {
|
|
|
8889
9341
|
return 'outside';
|
|
8890
9342
|
else {
|
|
8891
9343
|
at = rustSubmodule(from, first, context, depth);
|
|
9344
|
+
if (at === null && globs)
|
|
9345
|
+
at = rustGlobbedSubmodule(from, first, context, depth, false, new Set());
|
|
8892
9346
|
if (at === null) {
|
|
8893
9347
|
const graph = rustCrateGraph(context);
|
|
8894
9348
|
const own = rustCrateDirOf(from.file, graph);
|
|
@@ -9382,16 +9836,20 @@ function rustPathTarget(ref, context) {
|
|
|
9382
9836
|
const from = rustModuleAt(ref.filePath, offset, context);
|
|
9383
9837
|
const head = segs[0];
|
|
9384
9838
|
const bare = head !== 'crate' && head !== 'self' && head !== 'super';
|
|
9839
|
+
let headUse;
|
|
9385
9840
|
if (bare) {
|
|
9386
9841
|
const bound = rustVisibleUse(head, ref.filePath, offset, context);
|
|
9387
9842
|
if (bound && bound.std.length > 0 && bound.paths.length === 0)
|
|
9388
9843
|
return null;
|
|
9844
|
+
if (bound && bound.block >= 0 && bound.paths.length > 0)
|
|
9845
|
+
headUse = bound;
|
|
9389
9846
|
}
|
|
9390
9847
|
let memo = RUST_PATH_TARGETS.get(context);
|
|
9391
9848
|
if (!memo)
|
|
9392
9849
|
RUST_PATH_TARGETS.set(context, (memo = new Map()));
|
|
9393
9850
|
const scope = ownerUse ? `${ownerUse.block}\0${ownerUse.paths[0].at}` : '';
|
|
9394
|
-
const
|
|
9851
|
+
const headScope = headUse ? `${headUse.block}\0${headUse.paths[0].at}` : '';
|
|
9852
|
+
const key = `${ref.filePath}\0${from.block?.open ?? -1}\0${variants ? 1 : 0}\0${scope}\0${headScope}\0${segs.join('::')}`;
|
|
9395
9853
|
const hit = memo.get(key);
|
|
9396
9854
|
if (hit !== undefined)
|
|
9397
9855
|
return hit === null ? null : context.getNodeById?.(hit) ?? null;
|
|
@@ -9400,6 +9858,16 @@ function rustPathTarget(ref, context) {
|
|
|
9400
9858
|
const ids = rustUseItemsAt(path[0], ref, context);
|
|
9401
9859
|
return ids === null ? null : [...ids].map((id) => context.getNodeById?.(id)).filter((n) => !!n);
|
|
9402
9860
|
}
|
|
9861
|
+
if (headUse) {
|
|
9862
|
+
const found = [];
|
|
9863
|
+
for (const p of headUse.paths) {
|
|
9864
|
+
const items = rustUsePathItems([...p.segs, ...path.slice(1)], rustModuleAt(ref.filePath, p.at, context), context, new Set());
|
|
9865
|
+
if (items === null)
|
|
9866
|
+
return null;
|
|
9867
|
+
found.push(...items);
|
|
9868
|
+
}
|
|
9869
|
+
return found;
|
|
9870
|
+
}
|
|
9403
9871
|
let items = rustUsePathItems(path, from, context, new Set());
|
|
9404
9872
|
if (items === null && bare && !rustUsesOf(from.file, context).pathMods.has(head)) {
|
|
9405
9873
|
const root = rustCrateRootModule(ref.filePath, context);
|
|
@@ -9687,6 +10155,79 @@ function isRustForeignImplCallable(target, ref, context) {
|
|
|
9687
10155
|
const local = impl.traitArgs.find((t) => isRustProjectNamed(t, RUST_DECLARED_TYPE_KINDS, context));
|
|
9688
10156
|
return local === undefined || rustFirstArgIs(local, ref, context);
|
|
9689
10157
|
}
|
|
10158
|
+
function isRustOtherTypesMethod(target, type, context) {
|
|
10159
|
+
if (target.language !== 'rust' || target.kind !== 'method' || type === 'Self')
|
|
10160
|
+
return false;
|
|
10161
|
+
if (target.qualifiedName.split('::').slice(-2, -1)[0] === type || rustTraitOf(target, context) !== null)
|
|
10162
|
+
return false;
|
|
10163
|
+
return context.getNodesByName(type).some((n) => n.language === 'rust' && (n.kind === 'struct' || n.kind === 'enum' || n.kind === 'union'));
|
|
10164
|
+
}
|
|
10165
|
+
function isRustTraitImplMember(method, context) {
|
|
10166
|
+
if (method.language !== 'rust' || method.kind !== 'method')
|
|
10167
|
+
return false;
|
|
10168
|
+
const scopes = rustScopesOf(method.filePath, context);
|
|
10169
|
+
const start = scopes?.lineStarts[method.startLine - 1];
|
|
10170
|
+
if (!scopes || start === undefined)
|
|
10171
|
+
return isRustTraitImplMethod(method, context);
|
|
10172
|
+
const block = (0, rust_scopes_1.rustImplAt)(scopes, start + Math.max(0, method.startColumn));
|
|
10173
|
+
if (!block)
|
|
10174
|
+
return true;
|
|
10175
|
+
if (block.kind === 'trait')
|
|
10176
|
+
return false;
|
|
10177
|
+
let p = block.at + 4;
|
|
10178
|
+
while (/\s/.test(scopes.code[p] ?? ''))
|
|
10179
|
+
p++;
|
|
10180
|
+
if (scopes.code[p] === '<')
|
|
10181
|
+
p += block.generics.length + 2;
|
|
10182
|
+
const head = scopes.code.slice(p, block.from).replace(/\bwhere\b[\s\S]*$/, '');
|
|
10183
|
+
let depth = 0;
|
|
10184
|
+
for (let i = 0; i < head.length; i++) {
|
|
10185
|
+
const c = head[i];
|
|
10186
|
+
if (c === '<' || c === '(' || c === '[')
|
|
10187
|
+
depth++;
|
|
10188
|
+
else if (c === ')' || c === ']' || (c === '>' && head[i - 1] !== '-'))
|
|
10189
|
+
depth--;
|
|
10190
|
+
else if (depth === 0 && c === 'f' && /^for\b(?!\s*<)/.test(head.slice(i)) && !/\w/.test(head[i - 1] ?? ''))
|
|
10191
|
+
return true;
|
|
10192
|
+
}
|
|
10193
|
+
return false;
|
|
10194
|
+
}
|
|
10195
|
+
function rustTakesSelf(method) {
|
|
10196
|
+
const signature = method.signature ?? '';
|
|
10197
|
+
return !signature.startsWith('(') || /^\(\s*(?:&\s*(?:'\w+\s+)?)?(?:mut\s+)?self\b/.test(signature);
|
|
10198
|
+
}
|
|
10199
|
+
const RUST_OWNER_TYPE_KINDS = new Set(['struct', 'enum', 'union']);
|
|
10200
|
+
function rustImplTraitOf(method, context) {
|
|
10201
|
+
const scopes = rustScopesOf(method.filePath, context);
|
|
10202
|
+
const block = scopes ? (0, rust_scopes_1.rustImplAt)(scopes, rustNodeOffset(method, context)) : undefined;
|
|
10203
|
+
if (!scopes || !block || block.kind !== 'impl')
|
|
10204
|
+
return '';
|
|
10205
|
+
return parseRustImplHeader(scopes.code.slice(block.at, block.from))?.trait ?? '';
|
|
10206
|
+
}
|
|
10207
|
+
function isRustCallUnreachable(target, ref, guessed, context) {
|
|
10208
|
+
if (target.language !== 'rust' || target.kind !== 'method' || ref.referenceKind !== 'calls')
|
|
10209
|
+
return false;
|
|
10210
|
+
const path = ref.referenceName.includes('::');
|
|
10211
|
+
if (!path && !rustTakesSelf(target))
|
|
10212
|
+
return true;
|
|
10213
|
+
if (!guessed)
|
|
10214
|
+
return false;
|
|
10215
|
+
const cut = target.qualifiedName.lastIndexOf('::');
|
|
10216
|
+
const owner = cut < 0 ? '' : target.qualifiedName.slice(0, cut).split('::').pop();
|
|
10217
|
+
if (path) {
|
|
10218
|
+
const segments = ref.referenceName.split('::');
|
|
10219
|
+
const named = segments[segments.length - 2];
|
|
10220
|
+
return /^[A-Z]/.test(named) && named !== 'Self' && named !== owner && rustTraitOf(target, context) === null &&
|
|
10221
|
+
isRustProjectNamed(named, RUST_OWNER_TYPE_KINDS, context);
|
|
10222
|
+
}
|
|
10223
|
+
const trait = rustImplTraitOf(target, context);
|
|
10224
|
+
if (trait === '' || isRustProjectNamed(trait, RUST_TRAIT_KIND, context))
|
|
10225
|
+
return false;
|
|
10226
|
+
const chain = RUST_CHAINED_CALLS.get(ref);
|
|
10227
|
+
const dot = ref.referenceName.lastIndexOf('.');
|
|
10228
|
+
const receiver = chain ? chain[chain.length - 1].replace(/\(\)$/, '') : dot > 0 ? receiverLink(ref.referenceName.slice(0, dot)) : '';
|
|
10229
|
+
return receiver !== 'self' && (receiver === '' || !sharesReceiverWord(receiver, target));
|
|
10230
|
+
}
|
|
9690
10231
|
function isRustPathCallReachable(target, ref, context) {
|
|
9691
10232
|
if (target.language !== 'rust')
|
|
9692
10233
|
return true;
|
|
@@ -11548,21 +12089,39 @@ function jsForStatementOpenAtEnd(code, at) {
|
|
|
11548
12089
|
return true;
|
|
11549
12090
|
}
|
|
11550
12091
|
function isImportShadowedByJsBinding(result, ref, context) {
|
|
11551
|
-
if (!JS_FAMILY.has(ref.language) || !JS_LOCAL_REF_KINDS.has(ref.referenceKind)
|
|
12092
|
+
if (!JS_FAMILY.has(ref.language) || !JS_LOCAL_REF_KINDS.has(ref.referenceKind))
|
|
11552
12093
|
return false;
|
|
11553
|
-
const
|
|
11554
|
-
if (!
|
|
12094
|
+
const head = /^([A-Za-z_$][\w$]*)(\.[A-Za-z_$][\w$]*)*$/.exec(ref.referenceName);
|
|
12095
|
+
if (!head)
|
|
11555
12096
|
return false;
|
|
11556
|
-
const
|
|
11557
|
-
|
|
12097
|
+
const name = head[1];
|
|
12098
|
+
const member = name.length < ref.referenceName.length;
|
|
12099
|
+
if (member && ref.referenceKind !== 'calls')
|
|
12100
|
+
return false;
|
|
12101
|
+
const target = context.getNodeById?.(result.targetNodeId);
|
|
12102
|
+
if (!target || (!member && target.name !== name) || target.kind === 'interface' || target.kind === 'type_alias')
|
|
11558
12103
|
return false;
|
|
11559
|
-
if (
|
|
12104
|
+
if (member && context.getImportMappings?.(ref.filePath, ref.language)?.some((m) => m.localName === name) !== true)
|
|
11560
12105
|
return false;
|
|
11561
|
-
if (!isLocallyBoundJsName(
|
|
12106
|
+
if (!isLocallyBoundJsName(name, ref.filePath, context))
|
|
11562
12107
|
return false;
|
|
11563
|
-
if (ref.referenceKind === 'calls' && bareCallReceiver(ref, context) !== null)
|
|
12108
|
+
if (!member && ref.referenceKind === 'calls' && bareCallReceiver(ref, context) !== null)
|
|
11564
12109
|
return false;
|
|
11565
|
-
return
|
|
12110
|
+
return jsBindingAroundReference(name, ref, context, target);
|
|
12111
|
+
}
|
|
12112
|
+
function jsBindingAroundReference(name, ref, context, target) {
|
|
12113
|
+
const scopes = context.getNodesInFile(ref.filePath)
|
|
12114
|
+
.filter((n) => (n.kind === 'function' || n.kind === 'method') &&
|
|
12115
|
+
(n.startLine < ref.line || (n.startLine === ref.line && (n.startColumn ?? 0) <= ref.column)) &&
|
|
12116
|
+
(n.endLine > ref.line || (n.endLine === ref.line && (n.endColumn ?? Infinity) >= ref.column)))
|
|
12117
|
+
.sort((a, b) => (a.endLine - a.startLine) - (b.endLine - b.startLine) || b.startLine - a.startLine);
|
|
12118
|
+
for (const fn of scopes) {
|
|
12119
|
+
if (target && target.filePath === ref.filePath && target.startLine >= fn.startLine && target.startLine <= fn.endLine)
|
|
12120
|
+
return false;
|
|
12121
|
+
if (jsBindingEnclosesReference(name, fn, ref, context))
|
|
12122
|
+
return true;
|
|
12123
|
+
}
|
|
12124
|
+
return false;
|
|
11566
12125
|
}
|
|
11567
12126
|
const JS_FN_CODE = new WeakMap();
|
|
11568
12127
|
const JS_FN_CODE_KEEP = 64;
|
|
@@ -11615,7 +12174,7 @@ const LOCAL_BINDING_PATTERNS = new Map();
|
|
|
11615
12174
|
const LOCAL_BINDING_PATTERNS_CAP = 4096;
|
|
11616
12175
|
const JS_BINDING_NAME = /^[\w$]+$/;
|
|
11617
12176
|
const ARROW_HEAD_CHAR = /[\w$.]/;
|
|
11618
|
-
const IMPORT_BINDING_VALUE = /^\s*(?:await\s+)?(?:require
|
|
12177
|
+
const IMPORT_BINDING_VALUE = /^\s*(?:await\s+)?(?:import\s*\(|require\s*\((?!\s*(['"])[^'"\n]*\1\s*\)\s*\())/;
|
|
11619
12178
|
const PARAM_PAREN = '\\((?:[^()]|\\([^()]*\\))*\\)';
|
|
11620
12179
|
const PARAM_BRACE = '\\{(?:[^{}]|\\{[^{}]*\\})*\\}';
|
|
11621
12180
|
const PARAM_BRACKET = '\\[(?:[^\\[\\]]|\\[[^\\[\\]]*\\])*\\]';
|
|
@@ -11717,6 +12276,29 @@ function bindsAtSites(source, name, sites) {
|
|
|
11717
12276
|
}
|
|
11718
12277
|
return false;
|
|
11719
12278
|
}
|
|
12279
|
+
function jsDeclarationsInScope(candidates, ref, context) {
|
|
12280
|
+
if (candidates.filter((n) => n.filePath === ref.filePath).length < 2)
|
|
12281
|
+
return candidates;
|
|
12282
|
+
const file = jsScopeFile(ref.filePath, context);
|
|
12283
|
+
if (!file)
|
|
12284
|
+
return candidates;
|
|
12285
|
+
const sites = jsBindingSites(ref.referenceName, file);
|
|
12286
|
+
const at = (file.lineStarts[ref.line - 1] ?? file.code.length) + ref.column;
|
|
12287
|
+
return candidates.filter((n) => {
|
|
12288
|
+
if (n.filePath !== ref.filePath)
|
|
12289
|
+
return true;
|
|
12290
|
+
const site = sites.find((s) => (s.kind === 'function' || s.kind === 'declaration') && jsLineOf(file, s.at) === n.startLine);
|
|
12291
|
+
if (!site || file.code.startsWith('var', site.decl ?? site.at) || (site.kind === 'function' && isJsExpressionAt(file.code, site.at)))
|
|
12292
|
+
return true;
|
|
12293
|
+
return site.from <= at && site.to >= at;
|
|
12294
|
+
});
|
|
12295
|
+
}
|
|
12296
|
+
function isJsExpressionAt(code, at) {
|
|
12297
|
+
let before = code.slice(Math.max(0, at - 64), at).replace(/\s+$/, '');
|
|
12298
|
+
if (/(?:^|[^\w$])async$/.test(before))
|
|
12299
|
+
before = before.slice(0, -5).replace(/\s+$/, '');
|
|
12300
|
+
return /(?:[=(,:?[!&|+\-*/%<>~^]|=>|(?:^|[^\w$.])(?:return|yield|await|new|typeof|void|delete|in|of|case))$/.test(before);
|
|
12301
|
+
}
|
|
11720
12302
|
function innerScopeShadows(nodes, ref, context) {
|
|
11721
12303
|
const local = nodes.filter((n) => n.filePath === ref.filePath);
|
|
11722
12304
|
if (local.length === 0)
|
|
@@ -11786,6 +12368,11 @@ function matchEnclosingScopeMember(ref, candidates, context) {
|
|
|
11786
12368
|
? []
|
|
11787
12369
|
: callableFirst(byOwner.get(owner) ?? []);
|
|
11788
12370
|
const typesNamed = (qn) => context.getNodesByQualifiedName(qn).filter((n) => MEMBER_OWNER_KINDS.has(n.kind) && sameLanguageFamily(n.language, ref.language));
|
|
12371
|
+
const ownsMember = (scope) => JS_FAMILY.has(ref.language) &&
|
|
12372
|
+
members(scope).some((c) => c.filePath === ref.filePath && (c.kind === 'method' || c.kind === 'function')) &&
|
|
12373
|
+
context.getNodesByQualifiedName(scope).some((n) => n.filePath === ref.filePath &&
|
|
12374
|
+
(n.kind === 'variable' || n.kind === 'constant' ||
|
|
12375
|
+
(n.kind === 'function' && members(scope).some((c) => c.kind === 'method' && c.filePath === ref.filePath))));
|
|
11789
12376
|
const pick = (owner, isType) => {
|
|
11790
12377
|
const found = members(owner);
|
|
11791
12378
|
if (found.length === 0)
|
|
@@ -11872,11 +12459,19 @@ function matchEnclosingScopeMember(ref, candidates, context) {
|
|
|
11872
12459
|
return null;
|
|
11873
12460
|
};
|
|
11874
12461
|
const segments = caller.qualifiedName.split('::');
|
|
11875
|
-
const start = MEMBER_OWNER_KINDS.has(caller.kind)
|
|
12462
|
+
const start = MEMBER_OWNER_KINDS.has(caller.kind) ||
|
|
12463
|
+
(receiver === 'self' && caller.kind === 'function' && ownsMember(caller.qualifiedName))
|
|
12464
|
+
? segments.length
|
|
12465
|
+
: segments.length - 1;
|
|
11876
12466
|
for (let i = start; i > 0; i--) {
|
|
11877
12467
|
const scope = segments.slice(0, i).join('::');
|
|
11878
12468
|
const isType = typesNamed(scope).length > 0;
|
|
11879
12469
|
if (!isType) {
|
|
12470
|
+
if (receiver === 'self' && i === start && ownsMember(scope)) {
|
|
12471
|
+
const own = pick(scope, false);
|
|
12472
|
+
if (own)
|
|
12473
|
+
return own;
|
|
12474
|
+
}
|
|
11880
12475
|
if (receiver !== 'bare')
|
|
11881
12476
|
continue;
|
|
11882
12477
|
const localFn = members(scope).find((c) => c.filePath === ref.filePath && (c.kind === 'method' || c.kind === 'function'));
|
|
@@ -11978,6 +12573,8 @@ function matchByExactName(ref, context) {
|
|
|
11978
12573
|
let bareTypeName;
|
|
11979
12574
|
let locallyBoundJsName;
|
|
11980
12575
|
const tsBareTypeName = () => (bareTypeName ??= isTsBareTypeName(ref, context));
|
|
12576
|
+
let bareGlobalName;
|
|
12577
|
+
const jsBareGlobalName = () => (bareGlobalName ??= isJsBareGlobalName(ref, context));
|
|
11981
12578
|
const ambientDeclarations = (0, ambient_modules_1.ambientModuleDeclarations)(context);
|
|
11982
12579
|
const sameName = outOfRepoCall
|
|
11983
12580
|
? innerScopeShadows(context.getNodesByName(ref.referenceName), ref, context)
|
|
@@ -12054,6 +12651,7 @@ function matchByExactName(ref, context) {
|
|
|
12054
12651
|
!(ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language) && isVueComponentMethod(n) && !isThisCallInOwnFile(n, ref, context)) &&
|
|
12055
12652
|
(!(inheritanceRef || (ref.language === 'kotlin' && ref.referenceKind === 'instantiates')) || (0, types_2.isSupertypeTarget)(n)) &&
|
|
12056
12653
|
!(n.filePath !== ref.filePath && tsBareTypeName() && !isTsTypeInScope(n, ref, context)) &&
|
|
12654
|
+
!(n.filePath !== ref.filePath && jsBareGlobalName() && !isJsValueInScope(n, ref, context)) &&
|
|
12057
12655
|
!(ambientDeclarations.has(n.id) && !(0, ambient_modules_1.declaringFileAnswers)(n.filePath, ref.filePath, context)) &&
|
|
12058
12656
|
(!importRef || (0, types_2.isImportableKind)(n.kind)) &&
|
|
12059
12657
|
isLexicallyReachable(n, ref, context) &&
|
|
@@ -12069,13 +12667,14 @@ function matchByExactName(ref, context) {
|
|
|
12069
12667
|
(!importRef || n.filePath === ref.filePath ||
|
|
12070
12668
|
!ESM_FAMILY.has(n.language) || !isSealedModule(n.filePath, context)) &&
|
|
12071
12669
|
!(bareJs && n.filePath !== ref.filePath && (locallyBoundJsName ??= isLocallyBoundJsName(ref.referenceName, ref.filePath, context))));
|
|
12072
|
-
const ranked =
|
|
12073
|
-
:
|
|
12074
|
-
:
|
|
12075
|
-
:
|
|
12076
|
-
:
|
|
12077
|
-
:
|
|
12078
|
-
:
|
|
12670
|
+
const ranked = bareJs ? jsDeclarationsInScope(filtered, ref, context)
|
|
12671
|
+
: dartBare ? nearestDartMembers(preferOwnDartLibrary(filtered, ref, context), ref, context)
|
|
12672
|
+
: dartTypeRef && dartPrefix === null ? preferOwnDartLibrary(filtered, ref, context)
|
|
12673
|
+
: swiftShape && swiftShape.shape !== 'chained' ? nearestSwiftMembers(filtered, ref, context)
|
|
12674
|
+
: kotlinBare ? lexicalKotlinMembers(filtered, ref, context)
|
|
12675
|
+
: rubyBare ? rubyMethodsOfCallerKind(filtered, ref, context)
|
|
12676
|
+
: ref.language === 'ruby' ? rubyConstantPool(filtered, ref, context)
|
|
12677
|
+
: objcDeclaredType ? objcTypeDeclarations(filtered, ref) : cppSpecializationPool(filtered, ref, context);
|
|
12079
12678
|
const candidates = ranked.length <= AMBIGUOUS_NAME_CEILING ? withinCppTranslationUnit(ranked, ref, context, true) : ranked;
|
|
12080
12679
|
if (candidates.length === 0) {
|
|
12081
12680
|
return null;
|
|
@@ -12692,6 +13291,9 @@ function holderExtent(container, context) {
|
|
|
12692
13291
|
const lines = context.getFileLines?.(container.filePath) ?? context.readFile(container.filePath)?.split('\n');
|
|
12693
13292
|
if (!lines)
|
|
12694
13293
|
return null;
|
|
13294
|
+
return holderExtentOf(container, lines);
|
|
13295
|
+
}
|
|
13296
|
+
function holderExtentOf(container, lines) {
|
|
12695
13297
|
const extentLines = lines.slice(container.startLine - 1, container.endLine);
|
|
12696
13298
|
if (!extentLines.length)
|
|
12697
13299
|
return null;
|
|
@@ -12700,12 +13302,8 @@ function holderExtent(container, context) {
|
|
|
12700
13302
|
const extent = (0, strip_comments_1.stripCommentsForRegex)(extentLines.join('\n'), 'typescript');
|
|
12701
13303
|
return { lines, extent, code: (0, strip_comments_1.blankStringContents)(extent) };
|
|
12702
13304
|
}
|
|
12703
|
-
function
|
|
12704
|
-
const
|
|
12705
|
-
if (!read)
|
|
12706
|
-
return undefined;
|
|
12707
|
-
const { lines, extent, code } = read;
|
|
12708
|
-
const open = /^[^=]*=\s*(?:(?:Object\.(?:freeze|seal)\s*)?\(\s*)*\{/.exec(code);
|
|
13305
|
+
function objectLiteralMemberSpans(code) {
|
|
13306
|
+
const open = /^(?:export\s+default\s*|[^=]*=\s*)(?:(?:Object\.(?:freeze|seal)\s*)?\(\s*)*\{/.exec(code);
|
|
12709
13307
|
if (!open)
|
|
12710
13308
|
return undefined;
|
|
12711
13309
|
const members = [];
|
|
@@ -12729,23 +13327,60 @@ function objectLiteralProperty(container, member, context) {
|
|
|
12729
13327
|
start = i + 1;
|
|
12730
13328
|
}
|
|
12731
13329
|
}
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
const key = /^(?:(?:async|get|set)\s+)?\*?\s*(?:([A-Za-z_$][\w$]*)|['"]([^'"\\]*)['"])(?=\s*(?:[:(<,=]|$))/.exec(text);
|
|
12740
|
-
if ((key?.[1] ?? key?.[2]) !== member)
|
|
12741
|
-
continue;
|
|
12742
|
-
const value = text.slice(key[0].length).trim();
|
|
12743
|
-
const binding = value === '' ? member : /^:\s*([A-Za-z_$][\w$]*)$/.exec(value)?.[1] ?? null;
|
|
12744
|
-
selected = { ...part, binding };
|
|
12745
|
-
}
|
|
12746
|
-
if (!selected)
|
|
13330
|
+
return members;
|
|
13331
|
+
}
|
|
13332
|
+
const MEMBER_KEY = /^(?:(?:async|get|set)\s+)?\*?\s*(?:([A-Za-z_$][\w$]*)|['"]([^'"\\]*)['"])(?=\s*(?:[:(<,=]|$))/;
|
|
13333
|
+
function objectLiteralMemberOf(text) {
|
|
13334
|
+
const key = MEMBER_KEY.exec(text);
|
|
13335
|
+
const name = key?.[1] ?? key?.[2];
|
|
13336
|
+
if (name === undefined)
|
|
12747
13337
|
return null;
|
|
12748
|
-
const
|
|
13338
|
+
const value = text.slice(key[0].length).trim();
|
|
13339
|
+
return { key: name, binding: value === '' ? name : /^:\s*([A-Za-z_$][\w$]*)$/.exec(value)?.[1] ?? null };
|
|
13340
|
+
}
|
|
13341
|
+
function objectLiteralMembers(holder, lines) {
|
|
13342
|
+
const read = holderExtentOf(holder, lines);
|
|
13343
|
+
if (!read)
|
|
13344
|
+
return null;
|
|
13345
|
+
const spans = objectLiteralMemberSpans(read.code);
|
|
13346
|
+
if (!spans)
|
|
13347
|
+
return null;
|
|
13348
|
+
const members = new Map();
|
|
13349
|
+
for (const part of spans) {
|
|
13350
|
+
const text = read.extent.slice(part.start, part.end).trim();
|
|
13351
|
+
if (text === '')
|
|
13352
|
+
continue;
|
|
13353
|
+
if (/^(?:\.\.\.|\[)/.test(text))
|
|
13354
|
+
return null;
|
|
13355
|
+
const member = objectLiteralMemberOf(text);
|
|
13356
|
+
if (member)
|
|
13357
|
+
members.set(member.key, member.binding);
|
|
13358
|
+
}
|
|
13359
|
+
return members;
|
|
13360
|
+
}
|
|
13361
|
+
function objectLiteralProperty(container, member, context) {
|
|
13362
|
+
const read = holderExtent(container, context);
|
|
13363
|
+
if (!read)
|
|
13364
|
+
return undefined;
|
|
13365
|
+
const { lines, extent, code } = read;
|
|
13366
|
+
const members = objectLiteralMemberSpans(code);
|
|
13367
|
+
if (!members)
|
|
13368
|
+
return undefined;
|
|
13369
|
+
let selected = null;
|
|
13370
|
+
for (const part of members) {
|
|
13371
|
+
const text = extent.slice(part.start, part.end).trim();
|
|
13372
|
+
if (/^(?:\.\.\.|\[)/.test(text)) {
|
|
13373
|
+
selected = null;
|
|
13374
|
+
continue;
|
|
13375
|
+
}
|
|
13376
|
+
const found = objectLiteralMemberOf(text);
|
|
13377
|
+
if (found?.key !== member)
|
|
13378
|
+
continue;
|
|
13379
|
+
selected = { ...part, binding: found.binding };
|
|
13380
|
+
}
|
|
13381
|
+
if (!selected)
|
|
13382
|
+
return null;
|
|
13383
|
+
const offset = (node) => {
|
|
12749
13384
|
let result = node.startColumn - container.startColumn;
|
|
12750
13385
|
for (let line = container.startLine; line < node.startLine; line++)
|
|
12751
13386
|
result += lines[line - 1].length + 1;
|
|
@@ -16456,10 +17091,15 @@ function matchDottedCallChain(ref, context) {
|
|
|
16456
17091
|
const bareMatch = matchByExactName(bareRef, context) ?? matchFuzzy(bareRef, context);
|
|
16457
17092
|
return bareMatch ? { ...bareMatch, original: ref } : null;
|
|
16458
17093
|
}
|
|
17094
|
+
if (ref.language === 'csharp')
|
|
17095
|
+
return matchCsharpCallResultCall(inner, method, ref, context);
|
|
16459
17096
|
if (!CONSTRUCTS_VIA_BARE_CALL.has(ref.language) || !/^[A-Z]/.test(inner))
|
|
16460
17097
|
return null;
|
|
16461
17098
|
return resolveMethodOnType(inner, method, ref, context, 0.85, 'instance-method', importedFqnOf(inner, ref, context));
|
|
16462
17099
|
}
|
|
17100
|
+
if (ref.language === 'csharp' && /^(?:this|base)\s*\.\s*[A-Za-z_]\w*(?:<[\s\S]*>)?$/.test(inner)) {
|
|
17101
|
+
return matchCsharpCallResultCall(inner, method, ref, context);
|
|
17102
|
+
}
|
|
16463
17103
|
const factoryClass = inner.slice(0, lastDot).split('.').pop();
|
|
16464
17104
|
const factoryMethod = inner.slice(lastDot + 1);
|
|
16465
17105
|
if (!factoryClass || !factoryMethod)
|
|
@@ -16487,7 +17127,11 @@ function matchDottedCallChain(ref, context) {
|
|
|
16487
17127
|
}
|
|
16488
17128
|
function importedFqnOf(typeName, ref, context) {
|
|
16489
17129
|
const imports = context.getImportMappings(ref.filePath, ref.language);
|
|
16490
|
-
|
|
17130
|
+
const imported = imports.find((i) => i.localName === typeName)?.source;
|
|
17131
|
+
if (imported !== undefined || ref.language !== 'java' || !/^[A-Z][\w$]*$/.test(typeName))
|
|
17132
|
+
return imported;
|
|
17133
|
+
const scoped = javaClassInScope(typeName, ref.filePath, context);
|
|
17134
|
+
return scoped ? javaTypeFqn(scoped) : undefined;
|
|
16491
17135
|
}
|
|
16492
17136
|
const KOTLIN_CALL_LINES = 8;
|
|
16493
17137
|
const KOTLIN_UNQUALIFIED_CALL = /^(?:this\s*\.\s*)?([a-z_]\w*)\s*(?:<[^<>()]*>)?\s*\(/;
|
|
@@ -16864,6 +17508,11 @@ function javaTypeRef(written, filePath, context) {
|
|
|
16864
17508
|
const pins = pkg
|
|
16865
17509
|
? [`${pkg}.${outer}`]
|
|
16866
17510
|
: context.getImportMappings(filePath, 'java').filter((i) => i.localName === outer).map((i) => i.source);
|
|
17511
|
+
if (pins.length === 0 && /^[A-Z][\w$]*$/.test(outer)) {
|
|
17512
|
+
const scoped = javaClassInScope(outer, filePath, context);
|
|
17513
|
+
if (scoped)
|
|
17514
|
+
pins.push(javaTypeFqn(scoped));
|
|
17515
|
+
}
|
|
16867
17516
|
if (pins.length === 0) {
|
|
16868
17517
|
if (!decls.some((d) => isJavaTypeNameable(d, filePath, context)))
|
|
16869
17518
|
return null;
|
|
@@ -17583,7 +18232,10 @@ function clearNameMatcherMemos(context) {
|
|
|
17583
18232
|
CSHARP_TYPE_ARITY.delete(context);
|
|
17584
18233
|
CSHARP_EXTENSION_METHODS.delete(context);
|
|
17585
18234
|
CSHARP_PARAMETERS.delete(context);
|
|
18235
|
+
CSHARP_EXTENSION_THIS.delete(context);
|
|
18236
|
+
CSHARP_FILE_BASENAMES.delete(context);
|
|
17586
18237
|
JS_ASSIGNED_MEMBERS.delete(context);
|
|
18238
|
+
JS_CONSTRUCTOR_METHODS.delete(context);
|
|
17587
18239
|
CFML_CHAINS.delete(context);
|
|
17588
18240
|
NO_RECEIVER_LINES.delete(context);
|
|
17589
18241
|
OBJC_SUPERS.delete(context);
|
|
@@ -17627,6 +18279,7 @@ function clearNameMatcherMemos(context) {
|
|
|
17627
18279
|
PY_LOCAL_BINDS.delete(context);
|
|
17628
18280
|
PY_LOCAL_FILE.delete(context);
|
|
17629
18281
|
PY_LOCAL_LAST.delete(context);
|
|
18282
|
+
PY_BOUND_AROUND_LAST.delete(context);
|
|
17630
18283
|
OVERLOAD_SETS.delete(context);
|
|
17631
18284
|
SWIFT_PARAMETERS.delete(context);
|
|
17632
18285
|
PHP_FILE_SCOPES.delete(context);
|
|
@@ -17650,6 +18303,7 @@ function clearNameMatcherMemos(context) {
|
|
|
17650
18303
|
JS_READER_TEXT.delete(context);
|
|
17651
18304
|
JS_FUNCTION_WRITTEN_TWICE.delete(context);
|
|
17652
18305
|
TS_RETURNED_TYPES.delete(context);
|
|
18306
|
+
JS_FILE_NAMES_TYPE.delete(context);
|
|
17653
18307
|
JS_GUARDED_NAMES.delete(context);
|
|
17654
18308
|
TS_TYPE_GUARD_NAMES.delete(context);
|
|
17655
18309
|
REACT_LIFECYCLE_MEMO.delete(context);
|
|
@@ -17715,7 +18369,8 @@ function buildLocalReceiverTypePatterns(language, r) {
|
|
|
17715
18369
|
case 'python':
|
|
17716
18370
|
return [
|
|
17717
18371
|
new RegExp(`(?:^|;)\\s*${r}\\s*=(?!=)\\s*([A-Z]\\w*)\\.objects\\.(?:create|get|first|last|latest|earliest|get_by_natural_key)\\s*\\(`),
|
|
17718
|
-
new RegExp(`(?:^|;)\\s*${r}\\s*=(?!=)\\s*([A-Z][\\w.]*)\\s*\\((?![^\\n]*,\\s*$)`),
|
|
18372
|
+
new RegExp(`(?:^|;)\\s*${r}\\s*=(?!=)\\s*((?:[a-z_]\\w*\\.)*[A-Z][\\w.]*)\\s*\\((?![^\\n]*,\\s*$)`),
|
|
18373
|
+
new RegExp(`(?:^|;)\\s*(?:async\\s+)?with\\s+(?:[^#]*?,\\s*)?((?:[a-z_]\\w*\\.)*[A-Z]\\w*)\\s*\\((?:[^()]|\\([^()]*\\))*\\)\\s+as\\s+${r}\\b`),
|
|
17719
18374
|
new RegExp(`\\b${r}\\b\\s*:\\s*["']([A-Z][\\w.]*)["']`),
|
|
17720
18375
|
new RegExp(`\\b${r}\\b\\s*:\\s*([A-Z][\\w.]*)`),
|
|
17721
18376
|
];
|
|
@@ -18038,17 +18693,22 @@ function fileMethodsNamed(file, name, context) {
|
|
|
18038
18693
|
let methods = files.get(file);
|
|
18039
18694
|
if (!methods) {
|
|
18040
18695
|
files.set(file, (methods = new Map()));
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
continue;
|
|
18044
|
-
const named = methods.get(n.name);
|
|
18696
|
+
const add = (key, n) => {
|
|
18697
|
+
const named = methods.get(key);
|
|
18045
18698
|
if (named)
|
|
18046
18699
|
named.push(n);
|
|
18047
18700
|
else
|
|
18048
|
-
methods.set(
|
|
18701
|
+
methods.set(key, [n]);
|
|
18702
|
+
};
|
|
18703
|
+
for (const n of context.getNodesInFile(file)) {
|
|
18704
|
+
if (n.kind !== 'method')
|
|
18705
|
+
continue;
|
|
18706
|
+
add(n.name, n);
|
|
18707
|
+
if (n.language === 'php')
|
|
18708
|
+
add(`\0${n.name.toLowerCase()}`, n);
|
|
18049
18709
|
}
|
|
18050
18710
|
}
|
|
18051
|
-
return methods.get(name) ?? [];
|
|
18711
|
+
return methods.get(`\0${name.toLowerCase()}`) ?? methods.get(name) ?? [];
|
|
18052
18712
|
}
|
|
18053
18713
|
function findInheritedClassMethod(classes, name, context, kind) {
|
|
18054
18714
|
const seen = new Set(classes.map((c) => c.id));
|
|
@@ -18358,6 +19018,8 @@ function inferLocalReceiverType(receiverName, ref, context, decl) {
|
|
|
18358
19018
|
for (const re of i >= ownFrom ? withListed : patterns) {
|
|
18359
19019
|
const m = re.exec(input);
|
|
18360
19020
|
if (m && m[2]) {
|
|
19021
|
+
if (ref.language === 'python' && !pythonPatternTypeHolds(m[0], m[2], ref, context))
|
|
19022
|
+
continue;
|
|
18361
19023
|
let type = ref.language === 'java' ? javaTypeName(m[2]) : normalizeInferredTypeName(m[2]);
|
|
18362
19024
|
if (type && ref.language === 'pascal')
|
|
18363
19025
|
type = pascalPointee(type, context) ?? type;
|
|
@@ -18705,7 +19367,9 @@ function jsBindingSites(name, file) {
|
|
|
18705
19367
|
const scope = file.scopes[jsScopeAt(file, at)];
|
|
18706
19368
|
return { from: scope.start, to: scope.end };
|
|
18707
19369
|
};
|
|
19370
|
+
const inForHead = (at) => /\bfor\s*(?:await\s*)?\(\s*$/.test(code.slice(Math.max(0, at - 16), at));
|
|
18708
19371
|
let resume = 0;
|
|
19372
|
+
const matched = new Set();
|
|
18709
19373
|
for (const at of file.varDecls) {
|
|
18710
19374
|
if (at < resume)
|
|
18711
19375
|
continue;
|
|
@@ -18714,13 +19378,24 @@ function jsBindingSites(name, file) {
|
|
|
18714
19378
|
if (!m)
|
|
18715
19379
|
continue;
|
|
18716
19380
|
resume = at + m[0].length;
|
|
18717
|
-
|
|
19381
|
+
matched.add(at);
|
|
19382
|
+
if (inForHead(at)) {
|
|
18718
19383
|
sites.push({ from: code.lastIndexOf('(', at), to: jsForStatementEnd(code, at), at, kind: 'other' });
|
|
18719
19384
|
continue;
|
|
18720
19385
|
}
|
|
18721
19386
|
const plain = !/^(?:const|let|var)\s+[{[]/.test(m[0]) && !IMPORT_BINDING_VALUE.test(m[1] ?? '');
|
|
18722
19387
|
sites.push({ ...blockOf(at), at, kind: plain ? 'declaration' : 'other' });
|
|
18723
19388
|
}
|
|
19389
|
+
for (const d of jsDeclaredNames(file).get(name) ?? []) {
|
|
19390
|
+
if (matched.has(d.decl))
|
|
19391
|
+
continue;
|
|
19392
|
+
if (inForHead(d.decl)) {
|
|
19393
|
+
sites.push({ from: code.lastIndexOf('(', d.decl), to: jsForStatementEnd(code, d.decl), at: d.at, kind: 'other', decl: d.decl });
|
|
19394
|
+
continue;
|
|
19395
|
+
}
|
|
19396
|
+
const plain = d.plain && !(d.value !== null && IMPORT_BINDING_VALUE.test(code.slice(d.value, d.value + 40)));
|
|
19397
|
+
sites.push({ ...blockOf(d.decl), at: d.at, kind: plain ? 'declaration' : 'other', decl: d.decl });
|
|
19398
|
+
}
|
|
18724
19399
|
for (const at of file.fnDecls) {
|
|
18725
19400
|
fn.lastIndex = at;
|
|
18726
19401
|
if (fn.test(code))
|
|
@@ -18769,6 +19444,270 @@ function jsBindingSites(name, file) {
|
|
|
18769
19444
|
file.bindings.set(name, sites);
|
|
18770
19445
|
return sites;
|
|
18771
19446
|
}
|
|
19447
|
+
function jsDeclaredNames(file) {
|
|
19448
|
+
if (file.declared)
|
|
19449
|
+
return file.declared;
|
|
19450
|
+
const declared = new Map();
|
|
19451
|
+
const add = (name, d) => {
|
|
19452
|
+
const list = declared.get(name);
|
|
19453
|
+
if (list)
|
|
19454
|
+
list.push(d);
|
|
19455
|
+
else
|
|
19456
|
+
declared.set(name, [d]);
|
|
19457
|
+
};
|
|
19458
|
+
const { code } = file;
|
|
19459
|
+
for (const decl of file.varDecls) {
|
|
19460
|
+
let i = decl;
|
|
19461
|
+
while (i < code.length && /[a-z]/.test(code[i]))
|
|
19462
|
+
i++;
|
|
19463
|
+
while (true) {
|
|
19464
|
+
i = jsSkipSpace(code, i);
|
|
19465
|
+
const found = [];
|
|
19466
|
+
let plain = false;
|
|
19467
|
+
if (code[i] === '{' || code[i] === '[') {
|
|
19468
|
+
const close = jsMatchingBracket(code, i);
|
|
19469
|
+
if (close < 0 || !jsPatternNames(code, i, close, found))
|
|
19470
|
+
break;
|
|
19471
|
+
i = close + 1;
|
|
19472
|
+
}
|
|
19473
|
+
else {
|
|
19474
|
+
JS_NAME_AT.lastIndex = i;
|
|
19475
|
+
const id = JS_NAME_AT.exec(code);
|
|
19476
|
+
if (!id)
|
|
19477
|
+
break;
|
|
19478
|
+
found.push({ name: id[0], at: i });
|
|
19479
|
+
plain = true;
|
|
19480
|
+
i += id[0].length;
|
|
19481
|
+
}
|
|
19482
|
+
i = jsSkipSpace(code, i, false);
|
|
19483
|
+
if (code[i] === '!' && code[jsSkipSpace(code, i + 1, false)] === ':')
|
|
19484
|
+
i = jsSkipSpace(code, i + 1, false);
|
|
19485
|
+
if (code[i] === '\n' || code[i] === '\r') {
|
|
19486
|
+
const next = jsSkipSpace(code, i);
|
|
19487
|
+
if (code[next] === ',' || (code[next] === '=' && !/[=>]/.test(code[next + 1] ?? '')))
|
|
19488
|
+
i = next;
|
|
19489
|
+
}
|
|
19490
|
+
if (code[i] === ':') {
|
|
19491
|
+
i = jsTypeEnd(code, i + 1);
|
|
19492
|
+
if (i < 0)
|
|
19493
|
+
break;
|
|
19494
|
+
}
|
|
19495
|
+
let value = null;
|
|
19496
|
+
if (code[i] === '=' && !/[=>]/.test(code[i + 1] ?? '')) {
|
|
19497
|
+
value = i + 1;
|
|
19498
|
+
i = jsDeclaratorValueEnd(file, value);
|
|
19499
|
+
if (i < 0) {
|
|
19500
|
+
for (const f of found)
|
|
19501
|
+
add(f.name, { at: f.at, decl, plain, value });
|
|
19502
|
+
break;
|
|
19503
|
+
}
|
|
19504
|
+
}
|
|
19505
|
+
else if (!(i >= code.length || /[,;)\r\n}]/.test(code[i]) || /^(?:of|in)(?![\w$])/.test(code.slice(i, i + 3)))) {
|
|
19506
|
+
break;
|
|
19507
|
+
}
|
|
19508
|
+
for (const f of found)
|
|
19509
|
+
add(f.name, { at: f.at, decl, plain, value });
|
|
19510
|
+
if (code[i] !== ',')
|
|
19511
|
+
break;
|
|
19512
|
+
i++;
|
|
19513
|
+
}
|
|
19514
|
+
}
|
|
19515
|
+
file.declared = declared;
|
|
19516
|
+
return declared;
|
|
19517
|
+
}
|
|
19518
|
+
const JS_NAME_AT = /[A-Za-z_$][\w$]*/y;
|
|
19519
|
+
const JS_KEY_AT = /[\w$]+/y;
|
|
19520
|
+
function jsSkipSpace(code, i, lines = true) {
|
|
19521
|
+
while (i < code.length) {
|
|
19522
|
+
const c = code[i];
|
|
19523
|
+
if (c === ' ' || c === '\t' || (lines && (c === '\n' || c === '\r')))
|
|
19524
|
+
i++;
|
|
19525
|
+
else
|
|
19526
|
+
break;
|
|
19527
|
+
}
|
|
19528
|
+
return i;
|
|
19529
|
+
}
|
|
19530
|
+
function jsMatchingBracket(code, open) {
|
|
19531
|
+
let depth = 0;
|
|
19532
|
+
for (let i = open; i < code.length; i++) {
|
|
19533
|
+
const c = code[i];
|
|
19534
|
+
if (c === '(' || c === '[' || c === '{')
|
|
19535
|
+
depth++;
|
|
19536
|
+
else if ((c === ')' || c === ']' || c === '}') && --depth === 0)
|
|
19537
|
+
return i;
|
|
19538
|
+
}
|
|
19539
|
+
return -1;
|
|
19540
|
+
}
|
|
19541
|
+
function jsPatternNames(code, open, close, out, depth = 0) {
|
|
19542
|
+
if (depth > 32)
|
|
19543
|
+
return false;
|
|
19544
|
+
const object = code[open] === '{';
|
|
19545
|
+
let i = open + 1;
|
|
19546
|
+
while (true) {
|
|
19547
|
+
i = jsSkipSpace(code, i);
|
|
19548
|
+
while (code[i] === ',')
|
|
19549
|
+
i = jsSkipSpace(code, i + 1);
|
|
19550
|
+
if (i >= close)
|
|
19551
|
+
return true;
|
|
19552
|
+
if (code.startsWith('...', i))
|
|
19553
|
+
i = jsSkipSpace(code, i + 3);
|
|
19554
|
+
if (object) {
|
|
19555
|
+
let key = null;
|
|
19556
|
+
const keyAt = i;
|
|
19557
|
+
if (code[i] === '[') {
|
|
19558
|
+
i = jsMatchingBracket(code, i);
|
|
19559
|
+
if (i < 0 || i > close)
|
|
19560
|
+
return false;
|
|
19561
|
+
i++;
|
|
19562
|
+
}
|
|
19563
|
+
else if (code[i] === '"' || code[i] === "'") {
|
|
19564
|
+
const end = code.indexOf(code[i], i + 1);
|
|
19565
|
+
if (end < 0 || end > close)
|
|
19566
|
+
return false;
|
|
19567
|
+
i = end + 1;
|
|
19568
|
+
}
|
|
19569
|
+
else {
|
|
19570
|
+
JS_KEY_AT.lastIndex = i;
|
|
19571
|
+
const k = JS_KEY_AT.exec(code);
|
|
19572
|
+
if (!k)
|
|
19573
|
+
return false;
|
|
19574
|
+
key = k[0];
|
|
19575
|
+
i += key.length;
|
|
19576
|
+
}
|
|
19577
|
+
i = jsSkipSpace(code, i);
|
|
19578
|
+
if (code[i] === ':') {
|
|
19579
|
+
i = jsSkipSpace(code, i + 1);
|
|
19580
|
+
}
|
|
19581
|
+
else {
|
|
19582
|
+
if (key === null || !/^[A-Za-z_$]/.test(key))
|
|
19583
|
+
return false;
|
|
19584
|
+
out.push({ name: key, at: keyAt });
|
|
19585
|
+
i = jsPatternDefaultEnd(code, i, close);
|
|
19586
|
+
if (i < 0)
|
|
19587
|
+
return false;
|
|
19588
|
+
continue;
|
|
19589
|
+
}
|
|
19590
|
+
}
|
|
19591
|
+
if (code[i] === '{' || code[i] === '[') {
|
|
19592
|
+
const end = jsMatchingBracket(code, i);
|
|
19593
|
+
if (end < 0 || end > close || !jsPatternNames(code, i, end, out, depth + 1))
|
|
19594
|
+
return false;
|
|
19595
|
+
i = end + 1;
|
|
19596
|
+
}
|
|
19597
|
+
else {
|
|
19598
|
+
JS_NAME_AT.lastIndex = i;
|
|
19599
|
+
const id = JS_NAME_AT.exec(code);
|
|
19600
|
+
if (!id)
|
|
19601
|
+
return false;
|
|
19602
|
+
out.push({ name: id[0], at: i });
|
|
19603
|
+
i += id[0].length;
|
|
19604
|
+
}
|
|
19605
|
+
i = jsPatternDefaultEnd(code, i, close);
|
|
19606
|
+
if (i < 0)
|
|
19607
|
+
return false;
|
|
19608
|
+
}
|
|
19609
|
+
}
|
|
19610
|
+
function jsPatternDefaultEnd(code, i, close) {
|
|
19611
|
+
i = jsSkipSpace(code, i);
|
|
19612
|
+
if (code[i] === '=' && !/[=>]/.test(code[i + 1] ?? '')) {
|
|
19613
|
+
let depth = 0;
|
|
19614
|
+
for (i++; i < close; i++) {
|
|
19615
|
+
const c = code[i];
|
|
19616
|
+
if (c === '(' || c === '[' || c === '{')
|
|
19617
|
+
depth++;
|
|
19618
|
+
else if (c === ')' || c === ']' || c === '}')
|
|
19619
|
+
depth--;
|
|
19620
|
+
else if (c === ',' && depth === 0)
|
|
19621
|
+
break;
|
|
19622
|
+
}
|
|
19623
|
+
}
|
|
19624
|
+
return i >= close || code[i] === ',' ? i : -1;
|
|
19625
|
+
}
|
|
19626
|
+
function jsTypeEnd(code, i) {
|
|
19627
|
+
let depth = 0;
|
|
19628
|
+
for (; i < code.length; i++) {
|
|
19629
|
+
const c = code[i];
|
|
19630
|
+
if (c === '=' && code[i + 1] === '>')
|
|
19631
|
+
i++;
|
|
19632
|
+
else if (c === '=' && depth === 0)
|
|
19633
|
+
return i;
|
|
19634
|
+
else if (c === '(' || c === '[' || c === '{' || c === '<')
|
|
19635
|
+
depth++;
|
|
19636
|
+
else if (c === ')' || c === ']' || c === '}' || c === '>') {
|
|
19637
|
+
if (--depth < 0)
|
|
19638
|
+
return i;
|
|
19639
|
+
}
|
|
19640
|
+
else if (depth === 0 && (c === ',' || c === ';'))
|
|
19641
|
+
return i;
|
|
19642
|
+
else if (depth === 0 && c === '\n') {
|
|
19643
|
+
const next = jsSkipSpace(code, i);
|
|
19644
|
+
if (!/[|&=]/.test(code[next] ?? ''))
|
|
19645
|
+
return i;
|
|
19646
|
+
i = next - 1;
|
|
19647
|
+
}
|
|
19648
|
+
}
|
|
19649
|
+
return -1;
|
|
19650
|
+
}
|
|
19651
|
+
function jsDeclaratorValueEnd(file, i) {
|
|
19652
|
+
const { code } = file;
|
|
19653
|
+
let depth = 0;
|
|
19654
|
+
for (; i < code.length; i++) {
|
|
19655
|
+
const c = code[i];
|
|
19656
|
+
if (c === '{') {
|
|
19657
|
+
const end = jsScopeEnd(file, i);
|
|
19658
|
+
if (end < 0)
|
|
19659
|
+
return -1;
|
|
19660
|
+
i = end;
|
|
19661
|
+
}
|
|
19662
|
+
else if (c === '(' || c === '[') {
|
|
19663
|
+
depth++;
|
|
19664
|
+
}
|
|
19665
|
+
else if (c === ')' || c === ']' || c === '}') {
|
|
19666
|
+
if (depth === 0)
|
|
19667
|
+
return i;
|
|
19668
|
+
depth--;
|
|
19669
|
+
}
|
|
19670
|
+
else if (depth > 0) {
|
|
19671
|
+
continue;
|
|
19672
|
+
}
|
|
19673
|
+
else if (c === ',' || c === ';') {
|
|
19674
|
+
return i;
|
|
19675
|
+
}
|
|
19676
|
+
else if (c === '<') {
|
|
19677
|
+
const before = jsPrevNonSpace(code, i);
|
|
19678
|
+
if (before < 0 || !JS_OPERAND_END.test(code[before]))
|
|
19679
|
+
return -1;
|
|
19680
|
+
JS_CALL_TYPE_ARGUMENTS.lastIndex = i;
|
|
19681
|
+
const typed = JS_CALL_TYPE_ARGUMENTS.exec(code);
|
|
19682
|
+
if (typed)
|
|
19683
|
+
i += typed[0].length - 1;
|
|
19684
|
+
}
|
|
19685
|
+
else if (c === '\n') {
|
|
19686
|
+
const before = jsPrevNonSpace(code, i);
|
|
19687
|
+
const after = jsSkipSpace(code, i);
|
|
19688
|
+
if (JS_OPERAND_END.test(code[before] ?? '') && (after === code.length || JS_OPERAND_START.test(code[after])))
|
|
19689
|
+
return i;
|
|
19690
|
+
i = after - 1;
|
|
19691
|
+
}
|
|
19692
|
+
}
|
|
19693
|
+
return code.length;
|
|
19694
|
+
}
|
|
19695
|
+
const JS_CALL_TYPE_ARGUMENTS = /<(?:[\w$. \t,|&[\]'"?]|<[\w$. \t,|&[\]'"?]{0,200}>){0,200}>(?=[ \t]*\()/y;
|
|
19696
|
+
function jsScopeEnd(file, open) {
|
|
19697
|
+
const { scopes } = file;
|
|
19698
|
+
let lo = 1, hi = scopes.length - 1;
|
|
19699
|
+
while (lo <= hi) {
|
|
19700
|
+
const mid = (lo + hi) >>> 1;
|
|
19701
|
+
const start = scopes[mid].start;
|
|
19702
|
+
if (start === open)
|
|
19703
|
+
return scopes[mid].end < file.code.length ? scopes[mid].end : -1;
|
|
19704
|
+
if (start < open)
|
|
19705
|
+
lo = mid + 1;
|
|
19706
|
+
else
|
|
19707
|
+
hi = mid - 1;
|
|
19708
|
+
}
|
|
19709
|
+
return -1;
|
|
19710
|
+
}
|
|
18772
19711
|
function jsForStatementEnd(code, at) {
|
|
18773
19712
|
let depth = 0;
|
|
18774
19713
|
for (let i = at; i < code.length; i++) {
|
|
@@ -18859,7 +19798,7 @@ function jsParameterReading(name, site, file) {
|
|
|
18859
19798
|
}
|
|
18860
19799
|
function jsDeclarationReading(name, site, file) {
|
|
18861
19800
|
const { code } = file;
|
|
18862
|
-
const head = new RegExp(`(?:const|let|var)\\s
|
|
19801
|
+
const head = new RegExp(`(?:(?:const|let|var)\\s+)?${(0, utils_1.escapeRegExp)(name)}(?![\\w$])\\s*(?:!?\\s*:\\s*${TS_ANNOTATED_TYPE})?`, 'y');
|
|
18863
19802
|
head.lastIndex = site.at;
|
|
18864
19803
|
const m = head.exec(code);
|
|
18865
19804
|
if (!m)
|
|
@@ -18873,6 +19812,11 @@ function jsDeclarationReading(name, site, file) {
|
|
|
18873
19812
|
const type = normalizeInferredTypeName(m[1]);
|
|
18874
19813
|
return type ? { type, raw: m[1], line } : null;
|
|
18875
19814
|
}
|
|
19815
|
+
const cast = jsCastValueType(rest);
|
|
19816
|
+
if (cast) {
|
|
19817
|
+
const type = normalizeInferredTypeName(cast);
|
|
19818
|
+
return type ? { type, raw: cast, line } : null;
|
|
19819
|
+
}
|
|
18876
19820
|
const made = /^\s*=\s*new\s+([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)\s*(?:<[^;(){}]*>\s*)?\(/.exec(rest);
|
|
18877
19821
|
if (!made)
|
|
18878
19822
|
return null;
|
|
@@ -19148,8 +20092,21 @@ function jsReaderText(filePath, context) {
|
|
|
19148
20092
|
}
|
|
19149
20093
|
const JS_READER_TEXT = new WeakMap();
|
|
19150
20094
|
const JS_RECEIVER_CANDIDATES = new WeakMap();
|
|
19151
|
-
const JS_CALL_DECLARATION = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:([A-Za-z_$][\w$]*)\s*\(|(?!(?:this|super)\s*\.)[A-Za-z_$][\w$]*\s*\.\s*[A-Za-z_$][\w$]*\s*\(
|
|
20095
|
+
const JS_CALL_DECLARATION = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:([A-Za-z_$][\w$]*)\s*\(|(?!(?:this|super)\s*\.)[A-Za-z_$][\w$]*\s*\.\s*[A-Za-z_$][\w$]*\s*\()/y;
|
|
19152
20096
|
const JS_NOT_TYPED_CALLEE = new Set(['require', 'import', 'await', 'typeof', 'new', 'function', 'async', 'super']);
|
|
20097
|
+
const JS_CALLED_REQUIRE = /^require\s*\(\s*(['"])(\.[^'"]*)\1\s*\)\s*\(/;
|
|
20098
|
+
function requiredModuleFunction(specifier, where, context) {
|
|
20099
|
+
const file = context.resolveModuleFile?.(specifier, where.filePath, where.language);
|
|
20100
|
+
if (!file)
|
|
20101
|
+
return null;
|
|
20102
|
+
const source = context.readFile(file) ?? '';
|
|
20103
|
+
const name = /(?:^|[^\w$.])module\.exports\s*=\s*(?:(?:async\s+)?function\s*\*?\s*)?([A-Za-z_$][\w$]*)\s*[;(\r\n]/m.exec(source)?.[1] ??
|
|
20104
|
+
/^[ \t]*export\s+default\s+(?:(?:async\s+)?function\s*\*?\s*)?([A-Za-z_$][\w$]*)/m.exec(source)?.[1];
|
|
20105
|
+
if (!name)
|
|
20106
|
+
return null;
|
|
20107
|
+
const fns = (context.getNodesInFileNamed?.(file, name) ?? context.getNodesInFile(file)).filter((n) => n.kind === 'function' && n.name === name);
|
|
20108
|
+
return fns.length === 1 && fns[0].signature && ESM_FAMILY.has(fns[0].language) ? fns[0] : null;
|
|
20109
|
+
}
|
|
19153
20110
|
function jsReceiverCandidates(filePath, language, context) {
|
|
19154
20111
|
let files = JS_RECEIVER_CANDIDATES.get(context);
|
|
19155
20112
|
if (!files)
|
|
@@ -19174,7 +20131,9 @@ function jsReceiverCandidates(filePath, language, context) {
|
|
|
19174
20131
|
for (const at of sites.varDecls) {
|
|
19175
20132
|
JS_CALL_DECLARATION.lastIndex = at;
|
|
19176
20133
|
const m = JS_CALL_DECLARATION.exec(source);
|
|
19177
|
-
|
|
20134
|
+
const calledRequire = m?.[2] === 'require' &&
|
|
20135
|
+
JS_CALLED_REQUIRE.test(source.slice(at + m[0].lastIndexOf('require'), at + m[0].length + 300));
|
|
20136
|
+
if (m && (calledRequire || !(m[2] && (JS_NOT_TYPED_CALLEE.has(m[2]) || !callees.has(m[2])))))
|
|
19178
20137
|
calls.add(m[1]);
|
|
19179
20138
|
}
|
|
19180
20139
|
const add = (fnStart, open, close) => {
|
|
@@ -19448,7 +20407,19 @@ function tsValueType(file, at, where, context, walk, top) {
|
|
|
19448
20407
|
return null;
|
|
19449
20408
|
const open = at + lead + match[0].length - 1;
|
|
19450
20409
|
const close = jsCloseOf(code, open);
|
|
19451
|
-
if (close < 0
|
|
20410
|
+
if (close < 0)
|
|
20411
|
+
return null;
|
|
20412
|
+
if (!made && called[1] === 'require' && !called[2]) {
|
|
20413
|
+
const required = JS_CALLED_REQUIRE.exec((context.readFile(where.filePath) ?? '').slice(at + lead, at + lead + 300));
|
|
20414
|
+
const callOpen = required ? at + lead + required[0].length - 1 : -1;
|
|
20415
|
+
const callClose = callOpen < 0 ? -1 : jsCloseOf(code, callOpen);
|
|
20416
|
+
if (callClose < 0 || !JS_WHOLE_VALUE_END.test(code.slice(callClose + 1, callClose + 200)))
|
|
20417
|
+
return null;
|
|
20418
|
+
const fn = requiredModuleFunction(required[2], where, context);
|
|
20419
|
+
const read = fn ? tsReturnedType(fn, context, walk) : null;
|
|
20420
|
+
return read && { ...read, from: [...read.from, fn.filePath] };
|
|
20421
|
+
}
|
|
20422
|
+
if (!JS_WHOLE_VALUE_END.test(code.slice(close + 1, close + 200)))
|
|
19452
20423
|
return null;
|
|
19453
20424
|
if (made) {
|
|
19454
20425
|
const raw = made[1].replace(/\s+/g, '');
|
|
@@ -19468,6 +20439,13 @@ function tsValueType(file, at, where, context, walk, top) {
|
|
|
19468
20439
|
if (head === 'this' || head === 'super')
|
|
19469
20440
|
return null;
|
|
19470
20441
|
const site = jsBindingAt(head, file, at);
|
|
20442
|
+
if (!site && /^[A-Z]/.test(head)) {
|
|
20443
|
+
const cls = tsNamedType(head, { filePath: where.filePath, language: where.language, id: '' }, where, context);
|
|
20444
|
+
if (!cls || cls === 'outside' || cls.kind !== 'class')
|
|
20445
|
+
return null;
|
|
20446
|
+
const read = tsStaticReturnedType(cls, member, where, context);
|
|
20447
|
+
return read && { ...read, from: [...read.from, cls.filePath] };
|
|
20448
|
+
}
|
|
19471
20449
|
const reading = site ? jsBindingReading(head, site, file) : null;
|
|
19472
20450
|
const owner = reading ? tsNamedType(reading.raw.replace(/\s*<[\s\S]*$/, ''), { filePath: where.filePath, language: where.language, id: '' }, where, context) : null;
|
|
19473
20451
|
if (!owner || owner === 'outside' || owner.kind !== 'class')
|
|
@@ -19502,7 +20480,109 @@ function jsCallResultReading(name, site, file, ref, context) {
|
|
|
19502
20480
|
from: valueAt,
|
|
19503
20481
|
};
|
|
19504
20482
|
}
|
|
19505
|
-
const JS_DECLARATION_HEAD = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*/y;
|
|
20483
|
+
const JS_DECLARATION_HEAD = /(?:(?:const|let|var)\s+)?([A-Za-z_$][\w$]*)\s*=\s*/y;
|
|
20484
|
+
function tsStaticReturnedType(cls, name, at, context) {
|
|
20485
|
+
const methods = tsClassMethods(cls, name, at, context, 0);
|
|
20486
|
+
const method = methods.length === 1 && methods[0].isStatic ? methods[0] : null;
|
|
20487
|
+
if (!method)
|
|
20488
|
+
return null;
|
|
20489
|
+
const lines = context.getFileLines?.(method.filePath) ?? context.readFile(method.filePath)?.split(/\r?\n/) ?? [];
|
|
20490
|
+
const head = lines.slice(method.startLine - 1, method.startLine + 2).join('\n');
|
|
20491
|
+
const written = head.match(new RegExp(`(?<![\\w$.])${(0, utils_1.escapeRegExp)(name)}\\s*([<(])`, 'g')) ?? [];
|
|
20492
|
+
if (written.length !== 1 || written[0].endsWith('<'))
|
|
20493
|
+
return null;
|
|
20494
|
+
const signature = (0, strip_comments_1.stripCommentsForRegex)(method.signature ?? '', 'typescript').trim();
|
|
20495
|
+
const close = signature.startsWith('(') ? jsCloseOf(signature, 0) : -1;
|
|
20496
|
+
const annotation = close < 0 ? undefined : /^\s*:\s*([\s\S]*\S)\s*$/.exec(signature.slice(close + 1))?.[1];
|
|
20497
|
+
if (annotation === undefined || /^(?:asserts\b|(?:this|[A-Za-z_$][\w$]*)\s+is\b)/.test(annotation) || tsHidesMembers(annotation, context))
|
|
20498
|
+
return null;
|
|
20499
|
+
const raw = new RegExp(`^${TS_ANNOTATED_TYPE}`).exec(annotation)?.[1];
|
|
20500
|
+
if (!raw || raw.endsWith(']') || !tsOneType(annotation, raw) || raw === 'this')
|
|
20501
|
+
return null;
|
|
20502
|
+
const owner = context.getNodesInFile(method.filePath).find((n) => n.kind === 'class' && n.startLine <= method.startLine && n.endLine >= method.endLine);
|
|
20503
|
+
if (owner && tsClassTypeParameter(owner, raw.split(/[.<\s]/)[0], context))
|
|
20504
|
+
return null;
|
|
20505
|
+
return { raw, file: method.filePath, language: method.language, line: method.startLine, from: [method.filePath] };
|
|
20506
|
+
}
|
|
20507
|
+
function jsOutsideCallValue(file, at, where, context) {
|
|
20508
|
+
const { code } = file;
|
|
20509
|
+
const text = code.slice(at, at + 300);
|
|
20510
|
+
const lead = /^\s*/.exec(text)[0].length;
|
|
20511
|
+
const called = /^([A-Za-z_$][\w$]*)(?:\s*\.\s*([A-Za-z_$][\w$]*))?\s*\(/.exec(text.slice(lead));
|
|
20512
|
+
if (!called)
|
|
20513
|
+
return false;
|
|
20514
|
+
const open = at + lead + called[0].length - 1;
|
|
20515
|
+
const close = jsCloseOf(code, open);
|
|
20516
|
+
if (close < 0 || !JS_WHOLE_VALUE_END.test(code.slice(close + 1, close + 200).replace(/^\s*!/, '')))
|
|
20517
|
+
return false;
|
|
20518
|
+
const [, head, member] = called;
|
|
20519
|
+
if (JS_NOT_CALLEE.has(head) || head === 'this' || head === 'super')
|
|
20520
|
+
return false;
|
|
20521
|
+
const argText = code.slice(open + 1, close);
|
|
20522
|
+
if (/^use[A-Z]/.test(member ?? head) && /=>|\bfunction\b/.test(argText))
|
|
20523
|
+
return false;
|
|
20524
|
+
const args = [];
|
|
20525
|
+
for (let depth = 0, from = 0, i = 0; i <= argText.length; i++) {
|
|
20526
|
+
const c = argText[i];
|
|
20527
|
+
if (c === '(' || c === '[' || c === '{')
|
|
20528
|
+
depth++;
|
|
20529
|
+
else if (c === ')' || c === ']' || c === '}')
|
|
20530
|
+
depth--;
|
|
20531
|
+
else if ((c === ',' && depth === 0) || i === argText.length) {
|
|
20532
|
+
args.push(argText.slice(from, i));
|
|
20533
|
+
from = i + 1;
|
|
20534
|
+
}
|
|
20535
|
+
}
|
|
20536
|
+
if (args.some((a) => /^\s*[A-Z][\w$]*\s*$/.test(a) &&
|
|
20537
|
+
context.getNodesByName(a.trim()).some((n) => n.qualifiedName === n.name && n.kind !== 'import' && n.kind !== 'file')))
|
|
20538
|
+
return false;
|
|
20539
|
+
const local = jsBindingAt(head, file, at);
|
|
20540
|
+
if (!local)
|
|
20541
|
+
return isOutOfRepoBinding(head, where, context);
|
|
20542
|
+
if (!member)
|
|
20543
|
+
return false;
|
|
20544
|
+
const reading = jsBindingReading(head, local, file);
|
|
20545
|
+
const raw = reading?.raw.trim();
|
|
20546
|
+
if (!raw || !/^[A-Za-z_$][\w$]*$/.test(raw) || js_builtins_1.JS_BUILT_INS.has(raw) || js_builtins_1.TS_PRIMITIVE_TYPES.has(raw))
|
|
20547
|
+
return false;
|
|
20548
|
+
if (new RegExp(`(?:\\bnew\\s+|:\\s*)${(0, utils_1.escapeRegExp)(raw)}\\s*<`).test(code.slice(local.at, local.at + 300)))
|
|
20549
|
+
return false;
|
|
20550
|
+
return tsImportedTypeFile(raw, where, context) === undefined && isUndeclaredTypeName(raw, where, context);
|
|
20551
|
+
}
|
|
20552
|
+
function jsOutsideValueBinding(name, ref, context) {
|
|
20553
|
+
if (!jsReceiverCandidates(ref.filePath, ref.language, context).calls.has(name))
|
|
20554
|
+
return null;
|
|
20555
|
+
const file = jsScopeFile(ref.filePath, context);
|
|
20556
|
+
if (!file)
|
|
20557
|
+
return null;
|
|
20558
|
+
const site = jsBindingAt(name, file, (file.lineStarts[ref.line - 1] ?? file.code.length) + ref.column);
|
|
20559
|
+
if (!site || site.kind !== 'declaration')
|
|
20560
|
+
return null;
|
|
20561
|
+
JS_DECLARATION_HEAD.lastIndex = site.at;
|
|
20562
|
+
const head = JS_DECLARATION_HEAD.exec(file.code);
|
|
20563
|
+
if (!head || head[1] !== name)
|
|
20564
|
+
return null;
|
|
20565
|
+
return jsOutsideCallValue(file, site.at + head[0].length, ref, context) ? jsLineOf(file, site.at) : null;
|
|
20566
|
+
}
|
|
20567
|
+
function jsCastValueType(rest) {
|
|
20568
|
+
return /^\s*=\s*[^;\n]*?\sas\s+([A-Z][\w.$]*)\s*;?[ \t]*(?:\r?\n|$)/.exec(rest)?.[1] ?? null;
|
|
20569
|
+
}
|
|
20570
|
+
function jsCastLocalReading(name, ref, context) {
|
|
20571
|
+
const file = jsScopeFile(ref.filePath, context);
|
|
20572
|
+
if (!file)
|
|
20573
|
+
return null;
|
|
20574
|
+
const site = jsBindingAt(name, file, (file.lineStarts[ref.line - 1] ?? file.code.length) + ref.column);
|
|
20575
|
+
if (!site || site.kind !== 'declaration')
|
|
20576
|
+
return null;
|
|
20577
|
+
JS_DECLARATION_HEAD.lastIndex = site.at;
|
|
20578
|
+
const head = JS_DECLARATION_HEAD.exec(file.code);
|
|
20579
|
+
if (!head || head[1] !== name)
|
|
20580
|
+
return null;
|
|
20581
|
+
const eq = site.at + head[0].lastIndexOf('=');
|
|
20582
|
+
const raw = jsCastValueType(file.code.slice(eq, eq + 400));
|
|
20583
|
+
const type = raw ? normalizeInferredTypeName(raw) : null;
|
|
20584
|
+
return raw && type ? { type, raw, line: jsLineOf(file, site.at) } : null;
|
|
20585
|
+
}
|
|
19506
20586
|
const JS_GUARD_CONDITION = /\bif\s*\(\s*!?\s*(?:([A-Za-z_$][\w$]*)\s*\.\s*([A-Za-z_$][\w$]*)\s*\(\s*\)|([A-Za-z_$][\w$]*)\s*\(\s*([A-Za-z_$][\w$]*)\s*\))\s*\)/g;
|
|
19507
20587
|
const JS_GUARDED_NAMES = new WeakMap();
|
|
19508
20588
|
const TS_TYPE_GUARD_NAMES = new WeakMap();
|
|
@@ -19864,6 +20944,11 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
19864
20944
|
if (ref.language === 'python' && ref.referenceKind === 'calls' && /\]\.\w+$/.test(ref.referenceName)) {
|
|
19865
20945
|
return matchPythonElementCall(ref, context);
|
|
19866
20946
|
}
|
|
20947
|
+
if (ref.language === 'csharp') {
|
|
20948
|
+
const literal = matchCsharpLiteralCall(ref, context);
|
|
20949
|
+
if (literal !== undefined)
|
|
20950
|
+
return literal;
|
|
20951
|
+
}
|
|
19867
20952
|
const dotMatch = (JS_FAMILY.has(ref.language) ? ref.referenceName.match(/^([\w.]+)\.([\w$]+)$/) : null) ??
|
|
19868
20953
|
(ref.language === 'ruby' ? ref.referenceName.match(/^([\w.]+)\.(\w+[!?])$/) : null) ??
|
|
19869
20954
|
ref.referenceName.match(/^([\w.]+)\.(\w+:?(?:\w+:)*)$/) ??
|
|
@@ -19952,6 +21037,7 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
19952
21037
|
let localInferred = false;
|
|
19953
21038
|
let javaDeclared;
|
|
19954
21039
|
let declaredReceiver = false;
|
|
21040
|
+
let propertyOwner = null;
|
|
19955
21041
|
let csharpBuiltInReceiver = false;
|
|
19956
21042
|
if (inferableReceiver) {
|
|
19957
21043
|
if (ref.language === 'vbnet' && dotMatch) {
|
|
@@ -19964,6 +21050,12 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
19964
21050
|
let inferredType = nmTimedT('mc-infer', ref, () => ref.language === 'cpp'
|
|
19965
21051
|
? inferCppReceiverType(objectOrClass, ref, context, 0, cppDecl)
|
|
19966
21052
|
: inferLocalReceiverType(objectOrClass, ref, context, decl));
|
|
21053
|
+
if (ref.language === 'python' && dotMatch && inferredType && decl.raw && /^[a-z_]\w*\./.test(decl.raw)) {
|
|
21054
|
+
const cls = pythonRefClass(decl.raw, ref, context);
|
|
21055
|
+
const method = cls ? pythonClassMethod(cls, methodName, ref, context) : null;
|
|
21056
|
+
if (method)
|
|
21057
|
+
return { original: ref, targetNodeId: method.id, confidence: 0.9, resolvedBy: 'instance-method' };
|
|
21058
|
+
}
|
|
19967
21059
|
if (rustBindingLine !== undefined && inferredType && decl.line !== rustBindingLine) {
|
|
19968
21060
|
if (isUndeclaredTypeName(inferredType.split('.').pop(), ref, context))
|
|
19969
21061
|
return null;
|
|
@@ -19994,6 +21086,12 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
19994
21086
|
}
|
|
19995
21087
|
if (!inferredType && ref.language === 'python' && dotMatch && isPythonOutsideModuleReceiver(objectOrClass, ref, context))
|
|
19996
21088
|
return null;
|
|
21089
|
+
if (!inferredType && ref.language === 'python' && dotMatch && /^[A-Za-z_]\w*$/.test(objectOrClass) &&
|
|
21090
|
+
objectOrClass !== 'self' && objectOrClass !== 'cls') {
|
|
21091
|
+
const typed = matchPythonLocalClassCall(objectOrClass, methodName, ref, context);
|
|
21092
|
+
if (typed !== undefined)
|
|
21093
|
+
return typed;
|
|
21094
|
+
}
|
|
19997
21095
|
if (!inferredType && ref.language === 'python' && dotMatch && /^\w+$/.test(objectOrClass)) {
|
|
19998
21096
|
const viaGlobal = pythonGlobalReceiverTarget(objectOrClass, methodName, ref, context, true);
|
|
19999
21097
|
if (viaGlobal)
|
|
@@ -20040,6 +21138,17 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20040
21138
|
typedFrom = reading.from;
|
|
20041
21139
|
}
|
|
20042
21140
|
}
|
|
21141
|
+
if (jsPlainReceiver && readersOn && typedAt === undefined) {
|
|
21142
|
+
const outside = nmTimedT('mc-jsoutside', ref, () => jsOutsideValueBinding(objectOrClass, ref, context));
|
|
21143
|
+
if (outside !== null && (!inferredType || decl.line === undefined || decl.line < outside))
|
|
21144
|
+
return null;
|
|
21145
|
+
const cast = inferredType ? null : jsCastLocalReading(objectOrClass, ref, context);
|
|
21146
|
+
if (cast) {
|
|
21147
|
+
inferredType = cast.type;
|
|
21148
|
+
decl.raw = cast.raw;
|
|
21149
|
+
decl.line = cast.line;
|
|
21150
|
+
}
|
|
21151
|
+
}
|
|
20043
21152
|
const awaited = !inferredType && ESM_FAMILY.has(ref.language)
|
|
20044
21153
|
? inferEsmAwaitedCallType(objectOrClass, ref, context) : null;
|
|
20045
21154
|
if (awaited) {
|
|
@@ -20107,15 +21216,17 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20107
21216
|
return null;
|
|
20108
21217
|
if (decl.valued && goValuedHasNoProjectMethods(decl.valued, context))
|
|
20109
21218
|
return null;
|
|
20110
|
-
let importedFqn = ref.language === 'java'
|
|
20111
|
-
? context
|
|
20112
|
-
|
|
20113
|
-
|
|
20114
|
-
|
|
20115
|
-
|
|
20116
|
-
:
|
|
20117
|
-
?
|
|
20118
|
-
:
|
|
21219
|
+
let importedFqn = ref.language === 'java'
|
|
21220
|
+
? importedFqnOf(inferredType, ref, context)
|
|
21221
|
+
: ref.language === 'kotlin'
|
|
21222
|
+
? context
|
|
21223
|
+
.getImportMappings(ref.filePath, ref.language)
|
|
21224
|
+
.find((i) => i.localName === inferredType)?.source
|
|
21225
|
+
: ref.language === 'go'
|
|
21226
|
+
? goDeclaredTypePackage(decl.raw, decl.file ?? ref.filePath, context)
|
|
21227
|
+
: ESM_FAMILY.has(ref.language) && !awaited
|
|
21228
|
+
? nmTimedT('mc-tsimport', ref, () => tsImportedTypeFile(decl.raw ?? inferredType, typedAt ?? ref, context))
|
|
21229
|
+
: undefined;
|
|
20119
21230
|
if (ESM_FAMILY.has(ref.language) && !awaited && importedFqn === undefined) {
|
|
20120
21231
|
const outside = nmTimedT('mc-tsoutside', ref, () => tsOutsideTypeDeclaration(decl.raw ?? inferredType, inferredType, typedAt ?? ref, context));
|
|
20121
21232
|
if (outside === null)
|
|
@@ -20126,6 +21237,8 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20126
21237
|
const known = tsKnownTypeCall(inferredType, importedFqn ?? ref.filePath, methodName, ref, typedAt ?? ref, context, 0.9, typedAt !== undefined);
|
|
20127
21238
|
if (known)
|
|
20128
21239
|
return withTypeFrom(known, typedFrom);
|
|
21240
|
+
if (known === undefined)
|
|
21241
|
+
propertyOwner = tsPropertyOwner(inferredType, importedFqn ?? ref.filePath, methodName, typedAt ?? ref, context);
|
|
20129
21242
|
if (typedAt) {
|
|
20130
21243
|
if (js_builtins_1.JS_BUILT_INS.has(inferredType) || js_builtins_1.TS_PRIMITIVE_TYPES.has(inferredType))
|
|
20131
21244
|
return null;
|
|
@@ -20172,6 +21285,11 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20172
21285
|
}
|
|
20173
21286
|
if (awaited)
|
|
20174
21287
|
return null;
|
|
21288
|
+
if (ref.language === 'csharp') {
|
|
21289
|
+
const extension = nmTimedT('mc-csext', ref, () => matchCsharpExtensionCall(inferredType, methodName, ref, context));
|
|
21290
|
+
if (extension !== undefined)
|
|
21291
|
+
return extension;
|
|
21292
|
+
}
|
|
20175
21293
|
if (ESM_FAMILY.has(ref.language) &&
|
|
20176
21294
|
(js_builtins_1.JS_BUILT_INS.has(inferredType) || js_builtins_1.TS_PRIMITIVE_TYPES.has(inferredType))) {
|
|
20177
21295
|
return null;
|
|
@@ -20287,6 +21405,13 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20287
21405
|
if (bounded !== undefined)
|
|
20288
21406
|
return bounded;
|
|
20289
21407
|
}
|
|
21408
|
+
const javaClass = ref.language === 'java' && dotMatch
|
|
21409
|
+
? objectOrClass.includes('.')
|
|
21410
|
+
? javaQualifiedReceiverType(objectOrClass, context)
|
|
21411
|
+
: /^[A-Z][\w$]*$/.test(objectOrClass) ? javaClassInScope(objectOrClass, ref.filePath, context) : undefined
|
|
21412
|
+
: undefined;
|
|
21413
|
+
if (javaClass === null)
|
|
21414
|
+
return null;
|
|
20290
21415
|
const strat1 = nmTimedT('mc-class', ref, () => {
|
|
20291
21416
|
if (ref.language === 'ruby' && /^[A-Z]\w*$/.test(objectOrClass)) {
|
|
20292
21417
|
const decls = rubyBareConstantDeclarations(objectOrClass, ref, context);
|
|
@@ -20307,6 +21432,8 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20307
21432
|
const named = classCandidates.filter((c) => phpFileNamesClass(c, ref.filePath, context));
|
|
20308
21433
|
classCandidates = [...named, ...classCandidates.filter((c) => !named.includes(c))];
|
|
20309
21434
|
}
|
|
21435
|
+
if (javaClass)
|
|
21436
|
+
classCandidates = [javaClass];
|
|
20310
21437
|
const productionCaller = !(0, query_utils_1.isTestPath)(ref.filePath);
|
|
20311
21438
|
for (const classNode of classCandidates) {
|
|
20312
21439
|
if (classNode.language !== ref.language)
|
|
@@ -20354,9 +21481,16 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20354
21481
|
objectOrClass !== 'this' && objectOrClass !== 'super' &&
|
|
20355
21482
|
js_builtins_1.JS_BUILTIN_METHODS.has(methodName))
|
|
20356
21483
|
return null;
|
|
20357
|
-
if (ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language) &&
|
|
21484
|
+
if (ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language) &&
|
|
21485
|
+
(isImportedModuleReceiver(objectOrClass, ref, context) || isImportedFunctionReceiver(objectOrClass, ref, context))) {
|
|
20358
21486
|
return null;
|
|
20359
21487
|
}
|
|
21488
|
+
if (ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language)) {
|
|
21489
|
+
const ownModule = projectModuleDefaultBinding(objectOrClass, ref, context);
|
|
21490
|
+
const settled = ownModule ? projectModuleMemberCall(ownModule, methodName, ref, context) : undefined;
|
|
21491
|
+
if (settled !== undefined)
|
|
21492
|
+
return settled;
|
|
21493
|
+
}
|
|
20360
21494
|
const aliased = ref.language === 'csharp' ? csharpUsingAlias(objectOrClass, ref, context) : null;
|
|
20361
21495
|
if (aliased) {
|
|
20362
21496
|
return resolveMethodOnType(aliased, methodName, ref, context, 0.9, 'instance-method', undefined);
|
|
@@ -20483,6 +21617,13 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20483
21617
|
rubySuiteNarrowed = kept.length !== targetMethods.length;
|
|
20484
21618
|
targetMethods = kept;
|
|
20485
21619
|
}
|
|
21620
|
+
if (propertyOwner) {
|
|
21621
|
+
const owner = propertyOwner;
|
|
21622
|
+
const subtypes = targetMethods.filter((m) => tsMethodOwnerIsSubtype(m, owner, ref, context));
|
|
21623
|
+
const naming = targetMethods.filter((m) => !subtypes.includes(m) && jsFileNamesType(m.filePath, owner, context));
|
|
21624
|
+
narrowed ||= naming.length > 0 && subtypes.length + naming.length !== targetMethods.length;
|
|
21625
|
+
targetMethods = [...subtypes, ...naming];
|
|
21626
|
+
}
|
|
20486
21627
|
const reachable = targetMethods.filter((m) => isLexicallyReachable(m, ref, context));
|
|
20487
21628
|
const scopedOut = targetMethods.some((m) => !reachable.includes(m) && !(m.language === 'kotlin' && isAnonymousMember(m)));
|
|
20488
21629
|
targetMethods = reachable;
|
|
@@ -20496,9 +21637,17 @@ function matchMethodCallOn(ref, context, read, readers = true) {
|
|
|
20496
21637
|
narrowed ||= kept.length !== targetMethods.length;
|
|
20497
21638
|
targetMethods = kept;
|
|
20498
21639
|
}
|
|
21640
|
+
if (JS_FAMILY.has(ref.language)) {
|
|
21641
|
+
const kept = targetMethods.filter((m) => m.filePath === ref.filePath || !(0, query_utils_1.isTestPath)(m.filePath) || !isConstructorFunctionMethod(m, context));
|
|
21642
|
+
narrowed ||= kept.length !== targetMethods.length;
|
|
21643
|
+
targetMethods = kept;
|
|
21644
|
+
}
|
|
20499
21645
|
const pythonChain = ref.language === 'python' && objectOrClass.includes('.');
|
|
20500
21646
|
if (targetMethods.length === 1 && !narrowed && !rubySuiteNarrowed && !scopedOut && !pythonChain && targetMethods[0].language === ref.language &&
|
|
20501
21647
|
!(JS_FAMILY.has(ref.language) && targetMethods[0].filePath !== ref.filePath && jsFileAssignsMember(ref.filePath, methodName, context)) &&
|
|
21648
|
+
!(JS_FAMILY.has(ref.language) && targetMethods[0].filePath !== ref.filePath &&
|
|
21649
|
+
!/^(?:this|self|super)$/.test(objectOrClass) && !sharesReceiverWord(objectOrClass, targetMethods[0]) &&
|
|
21650
|
+
isConstructorFunctionMethod(targetMethods[0], context)) &&
|
|
20502
21651
|
!isUnnamedTestDouble(targetMethods[0], objectOrClass, ref, context) &&
|
|
20503
21652
|
!((ref.language === 'lua' || ref.language === 'luau') && isLuaLibraryCall(objectOrClass, methodName, ref, targetMethods[0])) &&
|
|
20504
21653
|
!(isStdMethodName(ref.language, methodName) &&
|
|
@@ -20593,7 +21742,39 @@ function isImportedModuleReceiver(receiver, ref, context) {
|
|
|
20593
21742
|
const binding = context.getImportMappings?.(ref.filePath, ref.language)?.find((m) => m.localName === root);
|
|
20594
21743
|
if (!binding)
|
|
20595
21744
|
return false;
|
|
20596
|
-
|
|
21745
|
+
if (binding.isNamespace || context.isOutOfRepoImport?.(binding.source, ref.filePath, ref.language) === true)
|
|
21746
|
+
return true;
|
|
21747
|
+
if (binding.isDefault || !JS_FAMILY.has(ref.language))
|
|
21748
|
+
return false;
|
|
21749
|
+
const bound = context.resolveImport?.({ ...ref, referenceName: root, referenceKind: 'imports' });
|
|
21750
|
+
return !!bound && context.getNodeById?.(bound.targetNodeId)?.kind === 'file';
|
|
21751
|
+
}
|
|
21752
|
+
function projectModuleDefaultBinding(receiver, ref, context) {
|
|
21753
|
+
if (receiver.includes('.'))
|
|
21754
|
+
return null;
|
|
21755
|
+
const binding = context.getImportMappings?.(ref.filePath, ref.language)?.find((m) => m.localName === receiver);
|
|
21756
|
+
if (!binding?.isDefault || binding.isNamespace)
|
|
21757
|
+
return null;
|
|
21758
|
+
if (isLocallyBoundJsName(receiver, ref.filePath, context) && jsBindingAroundReference(receiver, ref, context))
|
|
21759
|
+
return null;
|
|
21760
|
+
const file = context.resolveModuleFile?.(binding.source, ref.filePath, ref.language);
|
|
21761
|
+
return file && (context.isIndexedFile?.(file) ?? context.fileExists(file)) ? file : null;
|
|
21762
|
+
}
|
|
21763
|
+
const MODULE_EXPORTS_DEFAULT = /(?:^|[^\w$.])module\.exports\s*=(?![=>])\s*(new\s+([A-Za-z_$][\w$]*)\s*[(<;\r\n]|\{)?/m;
|
|
21764
|
+
const ESM_DEFAULT_EXPORT_STATEMENT = /^[ \t]*export\s+(?:default\b|=)|\bas\s+default\b/m;
|
|
21765
|
+
function projectModuleMemberCall(file, methodName, ref, context) {
|
|
21766
|
+
const source = context.readFile(file) ?? '';
|
|
21767
|
+
const commonJs = source.includes('module.exports') ? MODULE_EXPORTS_DEFAULT.exec(source) : null;
|
|
21768
|
+
const made = commonJs?.[2];
|
|
21769
|
+
if (made) {
|
|
21770
|
+
const language = context.getNodesInFile(file)[0]?.language ?? ref.language;
|
|
21771
|
+
const declaring = tsImportedTypeFile(made, { ...ref, filePath: file, language }, context) ?? file;
|
|
21772
|
+
return resolveMethodOnType(made, methodName, ref, context, 0.85, 'instance-method', declaring);
|
|
21773
|
+
}
|
|
21774
|
+
if (commonJs)
|
|
21775
|
+
return commonJs[1] === '{' ? null : undefined;
|
|
21776
|
+
const esmDefault = (source.includes('default') || source.includes('export =')) && ESM_DEFAULT_EXPORT_STATEMENT.test(source);
|
|
21777
|
+
return esmDefault ? undefined : null;
|
|
20597
21778
|
}
|
|
20598
21779
|
const JS_ASSIGNED_MEMBERS = new WeakMap();
|
|
20599
21780
|
function jsFileAssignsMember(file, name, context) {
|
|
@@ -20643,7 +21824,18 @@ function isThisCallInOwnFile(n, ref, context) {
|
|
|
20643
21824
|
}
|
|
20644
21825
|
function isImportBinding(receiver, ref, context) {
|
|
20645
21826
|
const root = receiver.split('.')[0];
|
|
20646
|
-
|
|
21827
|
+
if (context.getImportMappings?.(ref.filePath, ref.language)?.some((m) => m.localName === root) !== true)
|
|
21828
|
+
return false;
|
|
21829
|
+
return !(JS_FAMILY.has(ref.language) && isLocallyBoundJsName(root, ref.filePath, context) && jsBindingAroundReference(root, ref, context));
|
|
21830
|
+
}
|
|
21831
|
+
function isImportedFunctionReceiver(receiver, ref, context) {
|
|
21832
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(receiver) || !isImportBinding(receiver, ref, context))
|
|
21833
|
+
return false;
|
|
21834
|
+
const binding = context.getImportMappings?.(ref.filePath, ref.language)?.find((m) => m.localName === receiver);
|
|
21835
|
+
if (!binding || binding.isNamespace || binding.isDefault || context.isOutOfRepoImport?.(binding.source, ref.filePath, ref.language) === true)
|
|
21836
|
+
return false;
|
|
21837
|
+
const bound = context.resolveImport?.({ ...ref, referenceName: receiver });
|
|
21838
|
+
return !!bound && context.getNodeById?.(bound.targetNodeId)?.kind === 'function';
|
|
20647
21839
|
}
|
|
20648
21840
|
function reExportSource(name, ref, context) {
|
|
20649
21841
|
let source;
|
|
@@ -20856,6 +22048,146 @@ function csharpExtensionOverload(picked, ref, context) {
|
|
|
20856
22048
|
return fitting[0];
|
|
20857
22049
|
return fitting.some((n) => n.id === picked.id) ? picked : null;
|
|
20858
22050
|
}
|
|
22051
|
+
const CSHARP_KEYWORD_TYPES = new Map([
|
|
22052
|
+
['string', 'String'], ['object', 'Object'], ['bool', 'Boolean'], ['char', 'Char'], ['byte', 'Byte'], ['sbyte', 'SByte'],
|
|
22053
|
+
['short', 'Int16'], ['ushort', 'UInt16'], ['int', 'Int32'], ['uint', 'UInt32'], ['long', 'Int64'], ['ulong', 'UInt64'],
|
|
22054
|
+
['nint', 'IntPtr'], ['nuint', 'UIntPtr'], ['float', 'Single'], ['double', 'Double'], ['decimal', 'Decimal'],
|
|
22055
|
+
]);
|
|
22056
|
+
const CSHARP_LITERAL_CALL = /^(@?"(?:[^"\\]|\\.|"")*"|'(?:[^'\\]|\\.)+'|\d[\w.]*?|true|false)\.([A-Za-z_]\w*)$/;
|
|
22057
|
+
function csharpLiteralType(literal) {
|
|
22058
|
+
if (literal.startsWith('"') || literal.startsWith('@'))
|
|
22059
|
+
return 'string';
|
|
22060
|
+
if (literal.startsWith("'"))
|
|
22061
|
+
return 'char';
|
|
22062
|
+
if (literal === 'true' || literal === 'false')
|
|
22063
|
+
return 'bool';
|
|
22064
|
+
const number = literal.toLowerCase().replace(/_/g, '');
|
|
22065
|
+
if (/^0x[\da-f]+(?:ul|lu|u|l)?$/.test(number) || /^0b[01]+(?:ul|lu|u|l)?$/.test(number) || /^\d+(?:ul|lu|u|l)?$/.test(number)) {
|
|
22066
|
+
if (/(?:ul|lu)$/.test(number))
|
|
22067
|
+
return 'ulong';
|
|
22068
|
+
if (number.endsWith('l'))
|
|
22069
|
+
return 'long';
|
|
22070
|
+
if (number.endsWith('u'))
|
|
22071
|
+
return 'uint';
|
|
22072
|
+
return 'int';
|
|
22073
|
+
}
|
|
22074
|
+
if (/^(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?[fdm]?$/.test(number)) {
|
|
22075
|
+
if (number.endsWith('f'))
|
|
22076
|
+
return 'float';
|
|
22077
|
+
if (number.endsWith('m'))
|
|
22078
|
+
return 'decimal';
|
|
22079
|
+
return 'double';
|
|
22080
|
+
}
|
|
22081
|
+
return null;
|
|
22082
|
+
}
|
|
22083
|
+
const CSHARP_EXTENSION_THIS = new WeakMap();
|
|
22084
|
+
function csharpExtensionThisType(method, context) {
|
|
22085
|
+
let memo = CSHARP_EXTENSION_THIS.get(context);
|
|
22086
|
+
if (!memo)
|
|
22087
|
+
CSHARP_EXTENSION_THIS.set(context, (memo = new Map()));
|
|
22088
|
+
const hit = memo.get(method.id);
|
|
22089
|
+
if (hit !== undefined)
|
|
22090
|
+
return hit;
|
|
22091
|
+
let found = null;
|
|
22092
|
+
const source = csharpDeclarationSource(method, context);
|
|
22093
|
+
const head = new RegExp(String.raw `\b${(0, utils_1.escapeRegExp)(method.name)}\s*(?:<([^()]*)>\s*)?\(`).exec(source);
|
|
22094
|
+
if (head) {
|
|
22095
|
+
const at = csharpPastAttributes(source, head.index + head[0].length);
|
|
22096
|
+
const param = /^(?:(?:ref|in|scoped|readonly)\s+)*this\s+(?:(?:ref|in|scoped|readonly)\s+)*((?:global::)?[A-Za-z_][\w.]*)\s*(<[^()]*?>)?\s*(\[[\s,]*\])?\s*\??\s+@?[A-Za-z_]\w*/.exec(source.slice(at));
|
|
22097
|
+
if (param && !param[3]) {
|
|
22098
|
+
const type = param[1].split(/::|\./).pop();
|
|
22099
|
+
const typeParams = (head[1] ?? '').split(',').map((t) => t.trim());
|
|
22100
|
+
found = { type, generic: !param[2] && typeParams.includes(type) };
|
|
22101
|
+
}
|
|
22102
|
+
}
|
|
22103
|
+
memo.set(method.id, found);
|
|
22104
|
+
return found;
|
|
22105
|
+
}
|
|
22106
|
+
function isCsharpExtensionVisible(n, file, context) {
|
|
22107
|
+
const segments = n.qualifiedName.split('::');
|
|
22108
|
+
if (segments.length < 3)
|
|
22109
|
+
return true;
|
|
22110
|
+
const namespace = segments.slice(0, -2).join('.');
|
|
22111
|
+
const scope = csharpNamespaceScope(file, context);
|
|
22112
|
+
if (scope.usings.has(namespace))
|
|
22113
|
+
return true;
|
|
22114
|
+
return scope.namespaces.some((ns) => ns === namespace || ns.startsWith(`${namespace}.`));
|
|
22115
|
+
}
|
|
22116
|
+
function matchCsharpExtensionCall(receiverType, methodName, ref, context) {
|
|
22117
|
+
const bare = receiverType.replace(/<[\s\S]*>$/, '').replace(/\?$/, '').split(/::|\./).pop();
|
|
22118
|
+
const keyword = CSHARP_KEYWORD_TYPES.get(bare);
|
|
22119
|
+
const names = new Set([bare, keyword ?? bare]);
|
|
22120
|
+
for (const [k, v] of CSHARP_KEYWORD_TYPES)
|
|
22121
|
+
if (v === bare)
|
|
22122
|
+
names.add(k);
|
|
22123
|
+
const candidates = context.getNodesByName(methodName).filter((n) => n.language === 'csharp' && n.kind === 'method' && n.id !== ref.fromNodeId &&
|
|
22124
|
+
isCsharpExtensionMethod(n, context) && isCsharpExtensionVisible(n, ref.filePath, context));
|
|
22125
|
+
const outside = keyword !== undefined || CSHARP_KEYWORD_TYPES.has(bare.toLowerCase());
|
|
22126
|
+
if (candidates.length === 0)
|
|
22127
|
+
return outside ? null : undefined;
|
|
22128
|
+
const types = context.getNodesByName(bare).filter((t) => t.language === 'csharp' && CSHARP_TYPE_KINDS.has(t.kind));
|
|
22129
|
+
if (!outside && types.length === 0 && csharpFileBasenames(context).has(`${bare}.cs`))
|
|
22130
|
+
return undefined;
|
|
22131
|
+
const ancestors = new Set();
|
|
22132
|
+
for (const t of types)
|
|
22133
|
+
for (const a of csharpAncestorNames(t.qualifiedName, context))
|
|
22134
|
+
ancestors.add(a);
|
|
22135
|
+
const tiers = [[], [], []];
|
|
22136
|
+
for (const n of candidates) {
|
|
22137
|
+
const self = csharpExtensionThisType(n, context);
|
|
22138
|
+
if (!self)
|
|
22139
|
+
continue;
|
|
22140
|
+
if (!self.generic && names.has(self.type))
|
|
22141
|
+
tiers[0].push(n);
|
|
22142
|
+
else if (!self.generic && ancestors.has(self.type))
|
|
22143
|
+
tiers[1].push(n);
|
|
22144
|
+
else if (self.generic || self.type === 'object' || self.type === 'Object')
|
|
22145
|
+
tiers[2].push(n);
|
|
22146
|
+
}
|
|
22147
|
+
const list = cppParenListAfter(ref.filePath, ref.line, Math.max(0, ref.column), methodName, context);
|
|
22148
|
+
const args = list === null ? null : list.trim() === '' ? [] : splitCppTopLevel(cppWithoutComments(list));
|
|
22149
|
+
const fits = (n) => {
|
|
22150
|
+
const params = args === null ? null : csharpParameters(n, context);
|
|
22151
|
+
return args === null || (!!params && csharpArgumentsFit(params.slice(1), args));
|
|
22152
|
+
};
|
|
22153
|
+
const tier = tiers.map((t) => t.filter(fits)).find((t) => t.length > 0);
|
|
22154
|
+
if (!tier)
|
|
22155
|
+
return outside ? null : undefined;
|
|
22156
|
+
if (args !== null && tier.length > 1) {
|
|
22157
|
+
const exact = (n) => (csharpParameters(n, context) ?? []).slice(1).filter((p) => !p.optional && !p.variadic).length === args.length;
|
|
22158
|
+
tier.sort((a, b) => Number(exact(b)) - Number(exact(a)));
|
|
22159
|
+
}
|
|
22160
|
+
if (!tier.every((n) => n.qualifiedName === tier[0].qualifiedName))
|
|
22161
|
+
return undefined;
|
|
22162
|
+
let pick = tier[0];
|
|
22163
|
+
let nearest = -1;
|
|
22164
|
+
for (const n of tier) {
|
|
22165
|
+
const shared = n.filePath === ref.filePath ? Number.MAX_SAFE_INTEGER : sharedDirDepth(ref.filePath, n.filePath);
|
|
22166
|
+
if (shared > nearest) {
|
|
22167
|
+
nearest = shared;
|
|
22168
|
+
pick = n;
|
|
22169
|
+
}
|
|
22170
|
+
}
|
|
22171
|
+
return { original: ref, targetNodeId: pick.id, confidence: 0.85, resolvedBy: 'instance-method' };
|
|
22172
|
+
}
|
|
22173
|
+
const CSHARP_FILE_BASENAMES = new WeakMap();
|
|
22174
|
+
function csharpFileBasenames(context) {
|
|
22175
|
+
let names = CSHARP_FILE_BASENAMES.get(context);
|
|
22176
|
+
if (!names) {
|
|
22177
|
+
names = new Set(context.getAllFiles().filter((f) => f.endsWith('.cs')).map((f) => path.posix.basename(f)));
|
|
22178
|
+
CSHARP_FILE_BASENAMES.set(context, names);
|
|
22179
|
+
}
|
|
22180
|
+
return names;
|
|
22181
|
+
}
|
|
22182
|
+
function matchCsharpLiteralCall(ref, context) {
|
|
22183
|
+
if (ref.language !== 'csharp' || ref.referenceKind !== 'calls')
|
|
22184
|
+
return undefined;
|
|
22185
|
+
const m = CSHARP_LITERAL_CALL.exec(ref.referenceName);
|
|
22186
|
+
const type = m ? csharpLiteralType(m[1]) : null;
|
|
22187
|
+
if (!m || !type)
|
|
22188
|
+
return undefined;
|
|
22189
|
+
return matchCsharpExtensionCall(type, m[2], ref, context) ?? null;
|
|
22190
|
+
}
|
|
20859
22191
|
function goPackageDir(filePath) {
|
|
20860
22192
|
return path.posix.dirname(filePath.replace(/\\/g, '/'));
|
|
20861
22193
|
}
|
|
@@ -20989,6 +22321,19 @@ function isPythonFromImportModule(ref, context) {
|
|
|
20989
22321
|
return name.length < text.length && name.startsWith(ref.referenceName) &&
|
|
20990
22322
|
/^\s+import\b/.test(name.slice(ref.referenceName.length));
|
|
20991
22323
|
}
|
|
22324
|
+
function isPythonImportStatementModule(ref, context) {
|
|
22325
|
+
if (ref.language !== 'python' || ref.referenceKind !== 'imports')
|
|
22326
|
+
return false;
|
|
22327
|
+
const lines = context.getFileLines?.(ref.filePath) ?? context.readFile(ref.filePath)?.split(/\r?\n/);
|
|
22328
|
+
const line = lines?.[ref.line - 1];
|
|
22329
|
+
if (line === undefined)
|
|
22330
|
+
return false;
|
|
22331
|
+
let before = line.slice(0, ref.column);
|
|
22332
|
+
for (let above = ref.line - 2; above >= 0 && above >= ref.line - 4 && /\\\s*$/.test(lines[above] ?? ''); above--) {
|
|
22333
|
+
before = lines[above].replace(/\\\s*$/, ' ') + before;
|
|
22334
|
+
}
|
|
22335
|
+
return /(?:^|[;:])\s*import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*$/.test(before);
|
|
22336
|
+
}
|
|
20992
22337
|
function matchGoAssertedCall(ref, context) {
|
|
20993
22338
|
if (ref.language !== 'go' || ref.referenceKind !== 'calls' || !/^[A-Za-z_]\w*$/.test(ref.referenceName))
|
|
20994
22339
|
return undefined;
|
|
@@ -21601,6 +22946,18 @@ function matchGoChainedCall(ref, context) {
|
|
|
21601
22946
|
const receiver = goReceiverChainType(links.slice(0, k), code[at] === '(', at, ref.filePath, index, context, 0);
|
|
21602
22947
|
return receiver ? goMethodOnElement(receiver, ref, context) ?? null : null;
|
|
21603
22948
|
}
|
|
22949
|
+
const GO_BUILTIN_RECEIVER_CALL = /^(?:new|make)\((.+)\)\.([A-Za-z_]\w*)$/;
|
|
22950
|
+
function matchGoBuiltinReceiverCall(ref, context) {
|
|
22951
|
+
if (ref.language !== 'go' || ref.referenceKind !== 'calls')
|
|
22952
|
+
return undefined;
|
|
22953
|
+
const m = GO_BUILTIN_RECEIVER_CALL.exec(ref.referenceName);
|
|
22954
|
+
if (!m)
|
|
22955
|
+
return undefined;
|
|
22956
|
+
const index = goScopeIndex(ref.filePath, context);
|
|
22957
|
+
const at = index && ref.line > 0 ? (index.lineStarts[ref.line - 1] ?? index.code.length) + Math.max(ref.column, 0) : 0;
|
|
22958
|
+
const found = goMethodOnElement(goTypeTextAt(m[1], ref.filePath, at, index, context), { ...ref, referenceName: m[2] }, context);
|
|
22959
|
+
return found ? { ...found, original: ref } : null;
|
|
22960
|
+
}
|
|
21604
22961
|
function goMethodOnElement(t, ref, context) {
|
|
21605
22962
|
let text = t.text.replace(/^\*/, '');
|
|
21606
22963
|
if (text.startsWith('*') || GO_TYPE_LITERAL.test(text))
|
|
@@ -22474,6 +23831,8 @@ function pythonConditionalArms(raw) {
|
|
|
22474
23831
|
}
|
|
22475
23832
|
function pythonValueEvidence(raw, signature) {
|
|
22476
23833
|
let v = raw.trim();
|
|
23834
|
+
for (let inner = pythonParenthesized(v); inner !== null; inner = pythonParenthesized(v))
|
|
23835
|
+
v = inner;
|
|
22477
23836
|
const arms = pythonConditionalArms(v);
|
|
22478
23837
|
if (arms) {
|
|
22479
23838
|
const [a, b] = arms.map((arm) => pythonValueEvidence(arm, signature));
|
|
@@ -22518,13 +23877,25 @@ function pythonJoinedValue(lines, ln, first, lastLine) {
|
|
|
22518
23877
|
return { text: first, end: ln };
|
|
22519
23878
|
}
|
|
22520
23879
|
function pythonValueCallees(value) {
|
|
22521
|
-
|
|
23880
|
+
let v = value.trim();
|
|
23881
|
+
for (let inner = pythonParenthesized(v); inner !== null; inner = pythonParenthesized(v))
|
|
23882
|
+
v = inner;
|
|
23883
|
+
const arms = pythonConditionalArms(v);
|
|
22522
23884
|
if (arms)
|
|
22523
23885
|
return arms.flatMap(pythonValueCallees);
|
|
22524
|
-
const shape = pythonExprShape(
|
|
23886
|
+
const shape = pythonExprShape(v.replace(/^await\s+/, ''));
|
|
22525
23887
|
const call = shape && /^([A-Za-z_][\w.]*) ?\(\)$/.exec(shape);
|
|
22526
23888
|
return call ? [call[1]] : [];
|
|
22527
23889
|
}
|
|
23890
|
+
function pythonParenthesized(v) {
|
|
23891
|
+
if (!v.startsWith('(') || !v.endsWith(')') || pythonExprShape(v) !== '()')
|
|
23892
|
+
return null;
|
|
23893
|
+
const inner = v.slice(1, -1).trim();
|
|
23894
|
+
if (!inner || pythonTopLevelParts(inner).length > 1)
|
|
23895
|
+
return null;
|
|
23896
|
+
const shape = pythonExprShape(inner);
|
|
23897
|
+
return shape === null || /(?:^|\s)for\s/.test(shape) ? null : inner;
|
|
23898
|
+
}
|
|
22528
23899
|
function pythonBlankStrings(line) {
|
|
22529
23900
|
const out = line.split('');
|
|
22530
23901
|
for (let i = 0; i < line.length; i++) {
|
|
@@ -22950,7 +24321,8 @@ function pythonFactoryTypeUncached(callee, awaited, fromFile, context, read, dep
|
|
|
22950
24321
|
return null;
|
|
22951
24322
|
if (/^(?:typing(?:_extensions)?\.)?Self$/.test(ann.type))
|
|
22952
24323
|
return receiver;
|
|
22953
|
-
return pythonClassNamed(ann.type, fn.filePath, context)
|
|
24324
|
+
return pythonClassNamed(ann.type, fn.filePath, context) ??
|
|
24325
|
+
(isPythonOutsideModuleName(ann.type.split('.')[0], fn.filePath, context) ? 'runtime' : null);
|
|
22954
24326
|
}
|
|
22955
24327
|
const nested = context
|
|
22956
24328
|
.getNodesInFile(fn.filePath)
|
|
@@ -23130,6 +24502,22 @@ function matchPythonTypedLocalCall(ref, context) {
|
|
|
23130
24502
|
read.delete(ref.filePath);
|
|
23131
24503
|
return read.size > 0 ? { ...hit, metadata: { typeFrom: [...read].sort() } } : hit;
|
|
23132
24504
|
}
|
|
24505
|
+
function matchPythonLocalClassCall(receiver, methodName, ref, context) {
|
|
24506
|
+
const scope = pythonBindingScope(receiver, ref, context);
|
|
24507
|
+
if (!scope)
|
|
24508
|
+
return undefined;
|
|
24509
|
+
const read = new Set();
|
|
24510
|
+
const cls = pythonLocalClass(scope, receiver, ref, context, read);
|
|
24511
|
+
if (cls === null)
|
|
24512
|
+
return undefined;
|
|
24513
|
+
if (cls === 'runtime')
|
|
24514
|
+
return null;
|
|
24515
|
+
const hit = pythonMethodOnClass(cls, methodName, ref, context, read) ?? pythonSubclassMethod(cls, methodName, ref, context);
|
|
24516
|
+
if (!hit)
|
|
24517
|
+
return null;
|
|
24518
|
+
read.delete(ref.filePath);
|
|
24519
|
+
return read.size > 0 ? { ...hit, metadata: { typeFrom: [...read].sort() } } : hit;
|
|
24520
|
+
}
|
|
23133
24521
|
const PY_FILE_DEFS = new WeakMap();
|
|
23134
24522
|
function pythonFileDefs(filePath, context) {
|
|
23135
24523
|
const memo = pyMemo(PY_FILE_DEFS, context);
|
|
@@ -23255,10 +24643,11 @@ function pythonLocalClass(scope, name, ref, context, read) {
|
|
|
23255
24643
|
read.add(f);
|
|
23256
24644
|
return hit.answer;
|
|
23257
24645
|
}
|
|
23258
|
-
function pythonLocalClassUncached(scope, name, ref, context, read) {
|
|
24646
|
+
function pythonLocalClassUncached(scope, name, ref, context, read, viaLocalCalls = true) {
|
|
23259
24647
|
const filePath = scope.filePath;
|
|
23260
24648
|
const { param, bindings } = pythonScopeBindings(scope, name, context);
|
|
23261
24649
|
const evidence = [];
|
|
24650
|
+
const made = [];
|
|
23262
24651
|
if (param !== undefined) {
|
|
23263
24652
|
const ev = param === null ? null : pythonAnnotationEvidence(param);
|
|
23264
24653
|
if (!ev)
|
|
@@ -23286,6 +24675,14 @@ function pythonLocalClassUncached(scope, name, ref, context, read) {
|
|
|
23286
24675
|
}
|
|
23287
24676
|
else {
|
|
23288
24677
|
const at = { ...ref, line: b.line + 1 };
|
|
24678
|
+
const call = viaLocalCalls ? pythonLocalMethodCall(b.value) : null;
|
|
24679
|
+
if (call && call.head !== name && pythonBindsLocally(call.head, at, context, false)) {
|
|
24680
|
+
const result = pythonLocalMethodResult(call, at, context, read);
|
|
24681
|
+
if (result === null)
|
|
24682
|
+
return null;
|
|
24683
|
+
made.push(result);
|
|
24684
|
+
continue;
|
|
24685
|
+
}
|
|
23289
24686
|
if (pythonValueCallees(b.value).some((c) => pythonBindsLocally(c.split('.')[0], at, context, false)))
|
|
23290
24687
|
return null;
|
|
23291
24688
|
ev = pythonValueEvidence(b.value, null);
|
|
@@ -23294,8 +24691,9 @@ function pythonLocalClassUncached(scope, name, ref, context, read) {
|
|
|
23294
24691
|
return null;
|
|
23295
24692
|
evidence.push(ev);
|
|
23296
24693
|
}
|
|
23297
|
-
if (!evidence.some((ev) => ev !== 'runtime'))
|
|
23298
|
-
return evidence.length > 0 ? 'runtime' : null;
|
|
24694
|
+
if (!evidence.some((ev) => ev !== 'runtime') && !made.some((m) => m !== 'runtime')) {
|
|
24695
|
+
return evidence.length + made.length > 0 ? 'runtime' : null;
|
|
24696
|
+
}
|
|
23299
24697
|
if (pythonFileDefs(filePath, context).some((n) => n.id !== scope.id && n.name === name &&
|
|
23300
24698
|
n.startLine > scope.startLine && n.endLine <= scope.endLine) ||
|
|
23301
24699
|
pythonFileClasses(filePath, context).some((n) => n.name === name &&
|
|
@@ -23310,7 +24708,25 @@ function pythonLocalClassUncached(scope, name, ref, context, read) {
|
|
|
23310
24708
|
if (line.includes(name) && (nonlocal.test(line) || asTuple.test(line)))
|
|
23311
24709
|
return null;
|
|
23312
24710
|
}
|
|
23313
|
-
return pythonAgree(evidence.map((ev) => pythonEvidenceClass(ev, filePath, context, read, 0, null)));
|
|
24711
|
+
return pythonAgree([...evidence.map((ev) => pythonEvidenceClass(ev, filePath, context, read, 0, null)), ...made]);
|
|
24712
|
+
}
|
|
24713
|
+
function pythonLocalMethodCall(value) {
|
|
24714
|
+
let v = value.trim();
|
|
24715
|
+
const awaited = /^await\s/.test(v);
|
|
24716
|
+
if (awaited)
|
|
24717
|
+
v = v.replace(/^await\s+/, '');
|
|
24718
|
+
const shape = pythonExprShape(v);
|
|
24719
|
+
const m = shape ? /^([A-Za-z_]\w*)\.([A-Za-z_]\w*) ?\(\)$/.exec(shape) : null;
|
|
24720
|
+
return m && m[1] !== 'self' && m[1] !== 'cls' ? { head: m[1], method: m[2], awaited } : null;
|
|
24721
|
+
}
|
|
24722
|
+
function pythonLocalMethodResult(call, at, context, read) {
|
|
24723
|
+
const scope = pythonBindingScope(call.head, at, context);
|
|
24724
|
+
if (!scope)
|
|
24725
|
+
return null;
|
|
24726
|
+
const owner = pythonLocalClassUncached(scope, call.head, at, context, read, false);
|
|
24727
|
+
if (!owner || owner === 'runtime')
|
|
24728
|
+
return null;
|
|
24729
|
+
return pythonFactoryType(`${owner.name}.${call.method}`, call.awaited, owner.filePath, context, read);
|
|
23314
24730
|
}
|
|
23315
24731
|
function matchPythonFactoryChain(ref, context) {
|
|
23316
24732
|
const m = /^([A-Za-z_][\w.]*)\(\)\.(\w+)$/.exec(ref.referenceName);
|
|
@@ -24388,6 +25804,68 @@ function tsMethodUpChain(cls, name, at, context, depth = 0, instanceOnly = false
|
|
|
24388
25804
|
}
|
|
24389
25805
|
return { method: null, complete };
|
|
24390
25806
|
}
|
|
25807
|
+
function tsPropertyOwner(typeName, file, name, at, context) {
|
|
25808
|
+
let known = tsTypeDeclaredIn(file, typeName, context);
|
|
25809
|
+
if (!known) {
|
|
25810
|
+
const named = tsNamedType(typeName, { filePath: at.filePath, language: at.language, id: '' }, at, context);
|
|
25811
|
+
known = named && named !== 'outside' ? named : !named ? tsAliasedType(typeName, file, at, context) : null;
|
|
25812
|
+
}
|
|
25813
|
+
return known ? tsPropertyUpChain(known, name, at, context, 0) : null;
|
|
25814
|
+
}
|
|
25815
|
+
function tsPropertyUpChain(cls, name, at, context, depth) {
|
|
25816
|
+
const members = context.getNodesInFile(cls.filePath).filter((n) => n.name === name && n.startLine >= cls.startLine && n.endLine <= cls.endLine &&
|
|
25817
|
+
n.qualifiedName.slice(0, Math.max(0, n.qualifiedName.lastIndexOf('::'))).split(/::|\./).pop() === cls.name);
|
|
25818
|
+
if (members.some((n) => n.kind === 'method'))
|
|
25819
|
+
return null;
|
|
25820
|
+
if (members.some((n) => n.kind === 'property' || n.kind === 'field'))
|
|
25821
|
+
return cls;
|
|
25822
|
+
if (depth >= TS_BASE_WALK_DEPTH)
|
|
25823
|
+
return null;
|
|
25824
|
+
for (const written of tsHeadSupertypes(cls, context) ?? []) {
|
|
25825
|
+
const base = tsNamedType(written, cls, at, context);
|
|
25826
|
+
if (!base || base === 'outside' || base.id === cls.id)
|
|
25827
|
+
continue;
|
|
25828
|
+
const found = tsPropertyUpChain(base, name, at, context, depth + 1);
|
|
25829
|
+
if (found)
|
|
25830
|
+
return found;
|
|
25831
|
+
}
|
|
25832
|
+
return null;
|
|
25833
|
+
}
|
|
25834
|
+
const JS_FILE_NAMES_TYPE = new WeakMap();
|
|
25835
|
+
function jsFileNamesType(file, type, context) {
|
|
25836
|
+
if (file === type.filePath)
|
|
25837
|
+
return true;
|
|
25838
|
+
let memo = JS_FILE_NAMES_TYPE.get(context);
|
|
25839
|
+
if (!memo)
|
|
25840
|
+
JS_FILE_NAMES_TYPE.set(context, (memo = new Map()));
|
|
25841
|
+
const key = `${file}\0${type.name}`;
|
|
25842
|
+
let hit = memo.get(key);
|
|
25843
|
+
if (hit === undefined) {
|
|
25844
|
+
const code = jsScopeFile(file, context)?.code ?? '';
|
|
25845
|
+
hit = new RegExp(`(?<![\\w$.])${(0, utils_1.escapeRegExp)(type.name)}(?![\\w$])`).test(code);
|
|
25846
|
+
if (memo.size >= PATTERN_MEMO_CAP)
|
|
25847
|
+
memo.delete(memo.keys().next().value);
|
|
25848
|
+
memo.set(key, hit);
|
|
25849
|
+
}
|
|
25850
|
+
return hit;
|
|
25851
|
+
}
|
|
25852
|
+
function tsMethodOwnerIsSubtype(method, type, at, context) {
|
|
25853
|
+
const ownerName = method.qualifiedName.slice(0, Math.max(0, method.qualifiedName.lastIndexOf('::'))).split(/::|\./).pop();
|
|
25854
|
+
const owner = context.getNodesInFile(method.filePath).find((n) => TS_MEMBER_OWNER_KINDS.has(n.kind) && n.name === ownerName && n.startLine <= method.startLine && n.endLine >= method.endLine);
|
|
25855
|
+
const walk = (cls, depth) => {
|
|
25856
|
+
if (cls.id === type.id)
|
|
25857
|
+
return true;
|
|
25858
|
+
if (depth >= TS_BASE_WALK_DEPTH)
|
|
25859
|
+
return false;
|
|
25860
|
+
for (const written of tsHeadSupertypes(cls, context) ?? []) {
|
|
25861
|
+
const base = tsNamedType(written, cls, at, context);
|
|
25862
|
+
if (base && base !== 'outside' && base.id !== cls.id && walk(base, depth + 1))
|
|
25863
|
+
return true;
|
|
25864
|
+
}
|
|
25865
|
+
return false;
|
|
25866
|
+
};
|
|
25867
|
+
return !!owner && walk(owner, 0);
|
|
25868
|
+
}
|
|
24391
25869
|
function tsAliasValueName(alias, context) {
|
|
24392
25870
|
const lines = (context.getFileLines?.(alias.filePath) ?? context.readFile(alias.filePath)?.split(/\r?\n/) ?? [])
|
|
24393
25871
|
.slice(alias.startLine - 1, alias.endLine);
|
|
@@ -24701,8 +26179,20 @@ function findOwnMethod(nodesInFile, classNode, methodName, kind) {
|
|
|
24701
26179
|
const methods = rubyMethodsOfKindFirst(nodesInFile.filter((n) => n.kind === 'method' && n.name === methodName), kind);
|
|
24702
26180
|
const exact = `${classNode.qualifiedName}::${methodName}`;
|
|
24703
26181
|
const byName = `${classNode.name}::${methodName}`;
|
|
24704
|
-
|
|
24705
|
-
methods.find((n) => n.qualifiedName === byName || n.qualifiedName.endsWith(`::${byName}`))
|
|
26182
|
+
const found = methods.find((n) => n.qualifiedName === exact) ??
|
|
26183
|
+
methods.find((n) => n.qualifiedName === byName || n.qualifiedName.endsWith(`::${byName}`));
|
|
26184
|
+
if (found || classNode.language !== 'php')
|
|
26185
|
+
return found;
|
|
26186
|
+
const lower = methodName.toLowerCase();
|
|
26187
|
+
const spellings = new Set(nodesInFile
|
|
26188
|
+
.filter((n) => n.kind === 'method' && n.language === 'php' && n.name !== methodName && n.name.toLowerCase() === lower)
|
|
26189
|
+
.map((n) => n.name));
|
|
26190
|
+
for (const declared of spellings) {
|
|
26191
|
+
const own = findOwnMethod(nodesInFile, classNode, declared, kind);
|
|
26192
|
+
if (own)
|
|
26193
|
+
return own;
|
|
26194
|
+
}
|
|
26195
|
+
return undefined;
|
|
24706
26196
|
}
|
|
24707
26197
|
function classStrategyMethod(classNode, methodName, context, kind, from) {
|
|
24708
26198
|
const own = findOwnMethod(context.getNodesInFile(classNode.filePath), classNode, methodName, kind);
|
|
@@ -24793,7 +26283,8 @@ function matchJavaCsharpNewReceiverCall(cls, written, method, ref, context) {
|
|
|
24793
26283
|
const fqn = written.includes('.') ? written : importedFqnOf(cls, ref, context);
|
|
24794
26284
|
const byPath = (n) => n.filePath.replace(/\.java$/, '').endsWith('/' + fqn.replace(/\./g, '/'));
|
|
24795
26285
|
const ownPackage = twins.filter((n) => dirOf(n.filePath) === dirOf(ref.filePath));
|
|
24796
|
-
chosen = fqn ? twins.find(
|
|
26286
|
+
chosen = fqn ? twins.find((n) => n.language === 'java' && javaTypeFqn(n) === fqn) ?? twins.find(byPath)
|
|
26287
|
+
: ownPackage.length === 1 ? ownPackage[0] : undefined;
|
|
24797
26288
|
}
|
|
24798
26289
|
if (!chosen)
|
|
24799
26290
|
return null;
|
|
@@ -25254,6 +26745,22 @@ function namesOwnerType(receiver, method) {
|
|
|
25254
26745
|
return false;
|
|
25255
26746
|
return flatWord(receiver.split('.').pop()) === flatWord(method.qualifiedName.slice(0, cut).split(/::|\./).pop());
|
|
25256
26747
|
}
|
|
26748
|
+
const JS_CONSTRUCTOR_METHODS = new WeakMap();
|
|
26749
|
+
function isConstructorFunctionMethod(method, context) {
|
|
26750
|
+
const cut = method.qualifiedName.lastIndexOf('::');
|
|
26751
|
+
if (method.kind !== 'method' || cut <= 0)
|
|
26752
|
+
return false;
|
|
26753
|
+
let memo = JS_CONSTRUCTOR_METHODS.get(context);
|
|
26754
|
+
if (!memo)
|
|
26755
|
+
JS_CONSTRUCTOR_METHODS.set(context, (memo = new Map()));
|
|
26756
|
+
let owned = memo.get(method.id);
|
|
26757
|
+
if (owned === undefined) {
|
|
26758
|
+
owned = context.getNodesByQualifiedName(method.qualifiedName.slice(0, cut))
|
|
26759
|
+
.some((n) => n.kind === 'function' && n.filePath === method.filePath);
|
|
26760
|
+
memo.set(method.id, owned);
|
|
26761
|
+
}
|
|
26762
|
+
return owned;
|
|
26763
|
+
}
|
|
25257
26764
|
function flatWord(w) {
|
|
25258
26765
|
return w.replace(/[^A-Za-z0-9]/g, '').replace(/\d+$/, '').toLowerCase();
|
|
25259
26766
|
}
|
|
@@ -25479,6 +26986,7 @@ function matchFuzzy(ref, context) {
|
|
|
25479
26986
|
(finalCandidates[0].filePath !== ref.filePath && isLocallyBoundJsName(ref.referenceName, ref.filePath, context)))) &&
|
|
25480
26987
|
!(JS_FAMILY.has(ref.language) && isOutOfRepoBinding(ref.referenceName, ref, context)) &&
|
|
25481
26988
|
!(finalCandidates[0].filePath !== ref.filePath && isTsBareTypeName(ref, context) && !isTsTypeInScope(finalCandidates[0], ref, context)) &&
|
|
26989
|
+
!(finalCandidates[0].filePath !== ref.filePath && isJsBareGlobalName(ref, context) && !isJsValueInScope(finalCandidates[0], ref, context)) &&
|
|
25482
26990
|
!(finalCandidates[0].kind === 'method' && isBareGoCall(ref, context)) &&
|
|
25483
26991
|
!(finalCandidates[0].kind !== 'function' && isBarePhpCall(ref, context)) &&
|
|
25484
26992
|
isLexicallyReachable(finalCandidates[0], ref, context) &&
|
|
@@ -25779,6 +27287,9 @@ function matchReferenceInner(ref, context) {
|
|
|
25779
27287
|
const anonymous = matchPhpAnonymousClassCall(ref, context);
|
|
25780
27288
|
if (anonymous !== undefined)
|
|
25781
27289
|
return anonymous;
|
|
27290
|
+
const constructed = matchPhpNewReceiverCall(ref, context);
|
|
27291
|
+
if (constructed !== undefined)
|
|
27292
|
+
return constructed;
|
|
25782
27293
|
}
|
|
25783
27294
|
if (ref.language === 'python' && ref.referenceKind === 'imports' && isPythonNameImportedFromOutside(ref.referenceName, ref, context)) {
|
|
25784
27295
|
return null;
|