@colbymchenry/codegraph-win32-arm64 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph +5 -0
- package/lib/dist/.test-build-engine.json +1 -0
- package/lib/dist/.test-build-viewer.json +1 -0
- package/lib/dist/bin/codegraph.d.ts +1 -0
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +744 -320
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/viewer-gate.d.ts +17 -0
- package/lib/dist/bin/viewer-gate.d.ts.map +1 -0
- package/lib/dist/bin/viewer-gate.js +31 -0
- package/lib/dist/bin/viewer-gate.js.map +1 -0
- package/lib/dist/context/formatter.d.ts +7 -1
- package/lib/dist/context/formatter.d.ts.map +1 -1
- package/lib/dist/context/formatter.js +12 -6
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +12 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +103 -16
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +58 -2
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +187 -32
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +64 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +583 -6
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +1417 -57
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +27 -4
- package/lib/dist/db/sqlite-adapter.d.ts +2 -0
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +56 -7
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/synthesis-stage.d.ts +12 -0
- package/lib/dist/db/synthesis-stage.d.ts.map +1 -0
- package/lib/dist/db/synthesis-stage.js +89 -0
- package/lib/dist/db/synthesis-stage.js.map +1 -0
- package/lib/dist/db/wal-valve.d.ts +32 -12
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +65 -22
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/db/wsl-shared-index.d.ts +53 -0
- package/lib/dist/db/wsl-shared-index.d.ts.map +1 -0
- package/lib/dist/db/wsl-shared-index.js +121 -0
- package/lib/dist/db/wsl-shared-index.js.map +1 -0
- package/lib/dist/directory.d.ts +130 -2
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +306 -23
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/errors.d.ts +14 -0
- package/lib/dist/errors.d.ts.map +1 -1
- package/lib/dist/errors.js +16 -1
- package/lib/dist/errors.js.map +1 -1
- package/lib/dist/extraction/cfml-extractor.d.ts +1 -0
- package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/cfml-extractor.js +15 -3
- package/lib/dist/extraction/cfml-extractor.js.map +1 -1
- package/lib/dist/extraction/dfm-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/dfm-extractor.js +14 -10
- package/lib/dist/extraction/dfm-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 +6 -4
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +41 -14
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.d.ts +48 -12
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +176 -11
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +38 -0
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +115 -3
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +218 -14
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +874 -176
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.d.ts +58 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +310 -19
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +8 -3
- package/lib/dist/extraction/languages/dart.js.map +1 -1
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
- package/lib/dist/extraction/languages/erlang.js +58 -22
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/javascript.js +1 -1
- package/lib/dist/extraction/languages/javascript.js.map +1 -1
- package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/lib/dist/extraction/languages/kotlin.js +169 -36
- package/lib/dist/extraction/languages/kotlin.js.map +1 -1
- package/lib/dist/extraction/languages/lua.d.ts.map +1 -1
- package/lib/dist/extraction/languages/lua.js +4 -1
- package/lib/dist/extraction/languages/lua.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +4 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/python.d.ts.map +1 -1
- package/lib/dist/extraction/languages/python.js +71 -0
- package/lib/dist/extraction/languages/python.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +50 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/languages/scala.d.ts.map +1 -1
- package/lib/dist/extraction/languages/scala.js +18 -3
- package/lib/dist/extraction/languages/scala.js.map +1 -1
- package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/typescript.js +9 -2
- package/lib/dist/extraction/languages/typescript.js.map +1 -1
- package/lib/dist/extraction/liquid-extractor.d.ts +18 -0
- package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/liquid-extractor.js +98 -22
- package/lib/dist/extraction/liquid-extractor.js.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.js +6 -4
- package/lib/dist/extraction/mybatis-extractor.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +7 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +20 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/syntax-tokens.d.ts +103 -0
- package/lib/dist/extraction/syntax-tokens.d.ts.map +1 -0
- package/lib/dist/extraction/syntax-tokens.js +381 -0
- package/lib/dist/extraction/syntax-tokens.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-helpers.d.ts +5 -0
- package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.js +17 -0
- package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts +31 -3
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +101 -18
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +926 -132
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
- package/lib/dist/file-limits.d.ts +40 -0
- package/lib/dist/file-limits.d.ts.map +1 -0
- package/lib/dist/file-limits.js +147 -0
- package/lib/dist/file-limits.js.map +1 -0
- package/lib/dist/graph/branch-guards.d.ts +248 -0
- package/lib/dist/graph/branch-guards.d.ts.map +1 -0
- package/lib/dist/graph/branch-guards.js +2231 -0
- package/lib/dist/graph/branch-guards.js.map +1 -0
- package/lib/dist/graph/dead-code.d.ts +251 -0
- package/lib/dist/graph/dead-code.d.ts.map +1 -0
- package/lib/dist/graph/dead-code.js +776 -0
- package/lib/dist/graph/dead-code.js.map +1 -0
- package/lib/dist/graph/dynamic-boundary-report.d.ts +121 -0
- package/lib/dist/graph/dynamic-boundary-report.d.ts.map +1 -0
- package/lib/dist/graph/dynamic-boundary-report.js +283 -0
- package/lib/dist/graph/dynamic-boundary-report.js.map +1 -0
- package/lib/dist/graph/index.d.ts +4 -0
- package/lib/dist/graph/index.d.ts.map +1 -1
- package/lib/dist/graph/index.js +16 -1
- package/lib/dist/graph/index.js.map +1 -1
- package/lib/dist/graph/named-symbol-flow.d.ts +125 -0
- package/lib/dist/graph/named-symbol-flow.d.ts.map +1 -0
- package/lib/dist/graph/named-symbol-flow.js +552 -0
- package/lib/dist/graph/named-symbol-flow.js.map +1 -0
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -0
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/symbol-lookup.d.ts +83 -0
- package/lib/dist/graph/symbol-lookup.d.ts.map +1 -0
- package/lib/dist/graph/symbol-lookup.js +181 -0
- package/lib/dist/graph/symbol-lookup.js.map +1 -0
- package/lib/dist/graph/traversal.d.ts +9 -0
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +62 -36
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/graph/type-hierarchy.d.ts +155 -0
- package/lib/dist/graph/type-hierarchy.d.ts.map +1 -0
- package/lib/dist/graph/type-hierarchy.js +382 -0
- package/lib/dist/graph/type-hierarchy.js.map +1 -0
- package/lib/dist/index.d.ts +273 -11
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +511 -34
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +11 -8
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/antigravity.d.ts.map +1 -1
- package/lib/dist/installer/targets/antigravity.js +14 -2
- package/lib/dist/installer/targets/antigravity.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts +3 -0
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +72 -12
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +23 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +74 -47
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-cli.js +215 -0
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.js +219 -0
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/lib/dist/installer/targets/opencode.d.ts +16 -5
- package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
- package/lib/dist/installer/targets/opencode.js +73 -22
- package/lib/dist/installer/targets/opencode.js.map +1 -1
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +6 -0
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/shared.d.ts +14 -3
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +39 -11
- package/lib/dist/installer/targets/shared.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +6 -5
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +99 -20
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +12 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/mcp/answer-freshness.d.ts +10 -0
- package/lib/dist/mcp/answer-freshness.d.ts.map +1 -0
- package/lib/dist/mcp/answer-freshness.js +68 -0
- package/lib/dist/mcp/answer-freshness.js.map +1 -0
- package/lib/dist/mcp/daemon-manager.d.ts +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +17 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +8 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +65 -2
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +17 -4
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +133 -23
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +26 -13
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +126 -32
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.d.ts +1 -10
- package/lib/dist/mcp/dynamic-boundaries.d.ts.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.js +46 -42
- package/lib/dist/mcp/dynamic-boundaries.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +31 -9
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +190 -64
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +140 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +239 -0
- package/lib/dist/mcp/explore-dedup.js.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.js +558 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.d.ts +217 -0
- package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +322 -0
- package/lib/dist/mcp/explore-session-state.js.map +1 -0
- package/lib/dist/mcp/index-freshness-worker.d.ts +2 -0
- package/lib/dist/mcp/index-freshness-worker.d.ts.map +1 -0
- package/lib/dist/mcp/index-freshness-worker.js +30 -0
- package/lib/dist/mcp/index-freshness-worker.js.map +1 -0
- package/lib/dist/mcp/index-freshness.d.ts +7 -0
- package/lib/dist/mcp/index-freshness.d.ts.map +1 -0
- package/lib/dist/mcp/index-freshness.js +94 -0
- package/lib/dist/mcp/index-freshness.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +27 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +159 -14
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +4 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +14 -3
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/project-lifecycle.d.ts +9 -0
- package/lib/dist/mcp/project-lifecycle.d.ts.map +1 -0
- package/lib/dist/mcp/project-lifecycle.js +181 -0
- package/lib/dist/mcp/project-lifecycle.js.map +1 -0
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +15 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +2 -2
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +9 -7
- package/lib/dist/mcp/query-pool.js.map +1 -1
- package/lib/dist/mcp/query-worker.js +2 -2
- package/lib/dist/mcp/query-worker.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +2 -2
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +13 -5
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +16 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +36 -13
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/startup-handshake.d.ts +3 -1
- package/lib/dist/mcp/startup-handshake.d.ts.map +1 -1
- package/lib/dist/mcp/startup-handshake.js +10 -2
- package/lib/dist/mcp/startup-handshake.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +544 -38
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +4246 -770
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/writer-lock.d.ts +61 -0
- package/lib/dist/mcp/writer-lock.d.ts.map +1 -0
- package/lib/dist/mcp/writer-lock.js +260 -0
- package/lib/dist/mcp/writer-lock.js.map +1 -0
- package/lib/dist/project-config.d.ts +23 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +39 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/alias-binding.d.ts +56 -0
- package/lib/dist/resolution/alias-binding.d.ts.map +1 -0
- package/lib/dist/resolution/alias-binding.js +127 -0
- package/lib/dist/resolution/alias-binding.js.map +1 -0
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +21 -19
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +23 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +330 -154
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cpp-constructor.d.ts +4 -0
- package/lib/dist/resolution/cpp-constructor.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-constructor.js +123 -0
- package/lib/dist/resolution/cpp-constructor.js.map +1 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts +12 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-macro-visibility.js +342 -0
- package/lib/dist/resolution/cpp-macro-visibility.js.map +1 -0
- package/lib/dist/resolution/expo-router-synthesizer.d.ts +32 -0
- package/lib/dist/resolution/expo-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/expo-router-synthesizer.js +189 -0
- package/lib/dist/resolution/expo-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/csharp.js +96 -2
- package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
- package/lib/dist/resolution/frameworks/expo-router.d.ts +189 -0
- package/lib/dist/resolution/frameworks/expo-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/expo-router.js +785 -0
- package/lib/dist/resolution/frameworks/expo-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +251 -16
- package/lib/dist/resolution/frameworks/express.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +5 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +29 -1
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/java.js +79 -47
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/nestjs.js +6 -14
- package/lib/dist/resolution/frameworks/nestjs.js.map +1 -1
- package/lib/dist/resolution/frameworks/nextjs.d.ts +76 -0
- package/lib/dist/resolution/frameworks/nextjs.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/nextjs.js +328 -0
- package/lib/dist/resolution/frameworks/nextjs.js.map +1 -0
- package/lib/dist/resolution/frameworks/object-literal.d.ts +32 -0
- package/lib/dist/resolution/frameworks/object-literal.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/object-literal.js +139 -0
- package/lib/dist/resolution/frameworks/object-literal.js.map +1 -0
- package/lib/dist/resolution/frameworks/package-deps.d.ts +14 -0
- package/lib/dist/resolution/frameworks/package-deps.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/package-deps.js +78 -0
- package/lib/dist/resolution/frameworks/package-deps.js.map +1 -0
- package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/python.js +166 -0
- package/lib/dist/resolution/frameworks/python.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.d.ts +26 -0
- package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.js +153 -14
- package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-router.d.ts +46 -0
- package/lib/dist/resolution/frameworks/react-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/react-router.js +187 -0
- package/lib/dist/resolution/frameworks/react-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/react.d.ts +2 -1
- package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react.js +188 -139
- package/lib/dist/resolution/frameworks/react.js.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.js +6 -1
- package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
- package/lib/dist/resolution/frameworks/sveltekit-router.d.ts +36 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.js +156 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +11 -1
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/frameworks/tanstack-router.d.ts +84 -0
- package/lib/dist/resolution/frameworks/tanstack-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/tanstack-router.js +437 -0
- package/lib/dist/resolution/frameworks/tanstack-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/vue-router.d.ts +82 -0
- package/lib/dist/resolution/frameworks/vue-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/vue-router.js +377 -0
- package/lib/dist/resolution/frameworks/vue-router.js.map +1 -0
- package/lib/dist/resolution/import-resolver.d.ts +38 -0
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +394 -28
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +89 -25
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +567 -149
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/js-builtins.d.ts +13 -0
- package/lib/dist/resolution/js-builtins.d.ts.map +1 -0
- package/lib/dist/resolution/js-builtins.js +46 -0
- package/lib/dist/resolution/js-builtins.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +99 -22
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +2192 -87
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/next-router-synthesizer.d.ts +27 -0
- package/lib/dist/resolution/next-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/next-router-synthesizer.js +113 -0
- package/lib/dist/resolution/next-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/path-aliases.d.ts +6 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +125 -17
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/react-router-synthesizer.d.ts +33 -0
- package/lib/dist/resolution/react-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/react-router-synthesizer.js +126 -0
- package/lib/dist/resolution/react-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/resolver-pool.d.ts +2 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -1
- package/lib/dist/resolution/resolver-pool.js +4 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -1
- package/lib/dist/resolution/strip-comments.d.ts +6 -0
- package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
- package/lib/dist/resolution/strip-comments.js +58 -0
- package/lib/dist/resolution/strip-comments.js.map +1 -1
- package/lib/dist/resolution/sveltekit-synthesizer.d.ts +58 -0
- package/lib/dist/resolution/sveltekit-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/sveltekit-synthesizer.js +173 -0
- package/lib/dist/resolution/sveltekit-synthesizer.js.map +1 -0
- package/lib/dist/resolution/synth-utils.d.ts +26 -0
- package/lib/dist/resolution/synth-utils.d.ts.map +1 -0
- package/lib/dist/resolution/synth-utils.js +75 -0
- package/lib/dist/resolution/synth-utils.js.map +1 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.d.ts +31 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.js +114 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/tier-synthesizer.d.ts +49 -0
- package/lib/dist/resolution/tier-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/tier-synthesizer.js +931 -0
- package/lib/dist/resolution/tier-synthesizer.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +78 -2
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/types.js +64 -0
- package/lib/dist/resolution/types.js.map +1 -1
- package/lib/dist/resolution/vue-router-synthesizer.d.ts +30 -0
- package/lib/dist/resolution/vue-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/vue-router-synthesizer.js +115 -0
- package/lib/dist/resolution/vue-router-synthesizer.js.map +1 -0
- package/lib/dist/search/identifier-segments.d.ts +10 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.js +29 -0
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-paths.d.ts +106 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +513 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +16 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +48 -10
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watch-policy.d.ts +14 -0
- package/lib/dist/sync/watch-policy.d.ts.map +1 -1
- package/lib/dist/sync/watch-policy.js +19 -0
- package/lib/dist/sync/watch-policy.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +74 -35
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +281 -99
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/telemetry/index.d.ts +4 -2
- package/lib/dist/telemetry/index.d.ts.map +1 -1
- package/lib/dist/telemetry/index.js +92 -41
- package/lib/dist/telemetry/index.js.map +1 -1
- package/lib/dist/types.d.ts +21 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +2 -0
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui-server/api/deadcode.d.ts +84 -0
- package/lib/dist/ui-server/api/deadcode.d.ts.map +1 -0
- package/lib/dist/ui-server/api/deadcode.js +136 -0
- package/lib/dist/ui-server/api/deadcode.js.map +1 -0
- package/lib/dist/ui-server/api/effects.d.ts +87 -0
- package/lib/dist/ui-server/api/effects.d.ts.map +1 -0
- package/lib/dist/ui-server/api/effects.js +499 -0
- package/lib/dist/ui-server/api/effects.js.map +1 -0
- package/lib/dist/ui-server/api/entrypoints.d.ts +86 -0
- package/lib/dist/ui-server/api/entrypoints.d.ts.map +1 -0
- package/lib/dist/ui-server/api/entrypoints.js +279 -0
- package/lib/dist/ui-server/api/entrypoints.js.map +1 -0
- package/lib/dist/ui-server/api/events.d.ts +183 -0
- package/lib/dist/ui-server/api/events.d.ts.map +1 -0
- package/lib/dist/ui-server/api/events.js +430 -0
- package/lib/dist/ui-server/api/events.js.map +1 -0
- package/lib/dist/ui-server/api/file.d.ts +66 -0
- package/lib/dist/ui-server/api/file.d.ts.map +1 -0
- package/lib/dist/ui-server/api/file.js +235 -0
- package/lib/dist/ui-server/api/file.js.map +1 -0
- package/lib/dist/ui-server/api/filecode.d.ts +126 -0
- package/lib/dist/ui-server/api/filecode.d.ts.map +1 -0
- package/lib/dist/ui-server/api/filecode.js +205 -0
- package/lib/dist/ui-server/api/filecode.js.map +1 -0
- package/lib/dist/ui-server/api/flow.d.ts +226 -0
- package/lib/dist/ui-server/api/flow.d.ts.map +1 -0
- package/lib/dist/ui-server/api/flow.js +612 -0
- package/lib/dist/ui-server/api/flow.js.map +1 -0
- package/lib/dist/ui-server/api/hierarchy.d.ts +81 -0
- package/lib/dist/ui-server/api/hierarchy.d.ts.map +1 -0
- package/lib/dist/ui-server/api/hierarchy.js +92 -0
- package/lib/dist/ui-server/api/hierarchy.js.map +1 -0
- package/lib/dist/ui-server/api/index.d.ts +90 -0
- package/lib/dist/ui-server/api/index.d.ts.map +1 -0
- package/lib/dist/ui-server/api/index.js +332 -0
- package/lib/dist/ui-server/api/index.js.map +1 -0
- package/lib/dist/ui-server/api/map.d.ts +238 -0
- package/lib/dist/ui-server/api/map.d.ts.map +1 -0
- package/lib/dist/ui-server/api/map.js +681 -0
- package/lib/dist/ui-server/api/map.js.map +1 -0
- package/lib/dist/ui-server/api/node.d.ts +81 -0
- package/lib/dist/ui-server/api/node.d.ts.map +1 -0
- package/lib/dist/ui-server/api/node.js +388 -0
- package/lib/dist/ui-server/api/node.js.map +1 -0
- package/lib/dist/ui-server/api/nodes.d.ts +25 -0
- package/lib/dist/ui-server/api/nodes.d.ts.map +1 -0
- package/lib/dist/ui-server/api/nodes.js +45 -0
- package/lib/dist/ui-server/api/nodes.js.map +1 -0
- package/lib/dist/ui-server/api/program.d.ts +139 -0
- package/lib/dist/ui-server/api/program.d.ts.map +1 -0
- package/lib/dist/ui-server/api/program.js +315 -0
- package/lib/dist/ui-server/api/program.js.map +1 -0
- package/lib/dist/ui-server/api/respond.d.ts +76 -0
- package/lib/dist/ui-server/api/respond.d.ts.map +1 -0
- package/lib/dist/ui-server/api/respond.js +186 -0
- package/lib/dist/ui-server/api/respond.js.map +1 -0
- package/lib/dist/ui-server/api/route-roots.d.ts +39 -0
- package/lib/dist/ui-server/api/route-roots.d.ts.map +1 -0
- package/lib/dist/ui-server/api/route-roots.js +96 -0
- package/lib/dist/ui-server/api/route-roots.js.map +1 -0
- package/lib/dist/ui-server/api/routes.d.ts +59 -0
- package/lib/dist/ui-server/api/routes.d.ts.map +1 -0
- package/lib/dist/ui-server/api/routes.js +108 -0
- package/lib/dist/ui-server/api/routes.js.map +1 -0
- package/lib/dist/ui-server/api/screens.d.ts +117 -0
- package/lib/dist/ui-server/api/screens.d.ts.map +1 -0
- package/lib/dist/ui-server/api/screens.js +611 -0
- package/lib/dist/ui-server/api/screens.js.map +1 -0
- package/lib/dist/ui-server/api/search.d.ts +29 -0
- package/lib/dist/ui-server/api/search.d.ts.map +1 -0
- package/lib/dist/ui-server/api/search.js +232 -0
- package/lib/dist/ui-server/api/search.js.map +1 -0
- package/lib/dist/ui-server/api/session.d.ts +52 -0
- package/lib/dist/ui-server/api/session.d.ts.map +1 -0
- package/lib/dist/ui-server/api/session.js +196 -0
- package/lib/dist/ui-server/api/session.js.map +1 -0
- package/lib/dist/ui-server/api/source.d.ts +200 -0
- package/lib/dist/ui-server/api/source.d.ts.map +1 -0
- package/lib/dist/ui-server/api/source.js +422 -0
- package/lib/dist/ui-server/api/source.js.map +1 -0
- package/lib/dist/ui-server/api/stats.d.ts +27 -0
- package/lib/dist/ui-server/api/stats.d.ts.map +1 -0
- package/lib/dist/ui-server/api/stats.js +164 -0
- package/lib/dist/ui-server/api/stats.js.map +1 -0
- package/lib/dist/ui-server/api/steps.d.ts +274 -0
- package/lib/dist/ui-server/api/steps.d.ts.map +1 -0
- package/lib/dist/ui-server/api/steps.js +1446 -0
- package/lib/dist/ui-server/api/steps.js.map +1 -0
- package/lib/dist/ui-server/api/trail-store.d.ts +142 -0
- package/lib/dist/ui-server/api/trail-store.d.ts.map +1 -0
- package/lib/dist/ui-server/api/trail-store.js +323 -0
- package/lib/dist/ui-server/api/trail-store.js.map +1 -0
- package/lib/dist/ui-server/api/trails.d.ts +163 -0
- package/lib/dist/ui-server/api/trails.d.ts.map +1 -0
- package/lib/dist/ui-server/api/trails.js +369 -0
- package/lib/dist/ui-server/api/trails.js.map +1 -0
- package/lib/dist/ui-server/api/when.d.ts +125 -0
- package/lib/dist/ui-server/api/when.d.ts.map +1 -0
- package/lib/dist/ui-server/api/when.js +251 -0
- package/lib/dist/ui-server/api/when.js.map +1 -0
- package/lib/dist/ui-server/api/wire.d.ts +179 -0
- package/lib/dist/ui-server/api/wire.d.ts.map +1 -0
- package/lib/dist/ui-server/api/wire.js +231 -0
- package/lib/dist/ui-server/api/wire.js.map +1 -0
- package/lib/dist/ui-server/assets.d.ts +40 -0
- package/lib/dist/ui-server/assets.d.ts.map +1 -0
- package/lib/dist/ui-server/assets.js +110 -0
- package/lib/dist/ui-server/assets.js.map +1 -0
- package/lib/dist/ui-server/constants.d.ts +32 -0
- package/lib/dist/ui-server/constants.d.ts.map +1 -0
- package/lib/dist/ui-server/constants.js +35 -0
- package/lib/dist/ui-server/constants.js.map +1 -0
- package/lib/dist/ui-server/highlight/index.d.ts +113 -0
- package/lib/dist/ui-server/highlight/index.d.ts.map +1 -0
- package/lib/dist/ui-server/highlight/index.js +307 -0
- package/lib/dist/ui-server/highlight/index.js.map +1 -0
- package/lib/dist/ui-server/highlight/languages.d.ts +36 -0
- package/lib/dist/ui-server/highlight/languages.d.ts.map +1 -0
- package/lib/dist/ui-server/highlight/languages.js +50 -0
- package/lib/dist/ui-server/highlight/languages.js.map +1 -0
- package/lib/dist/ui-server/index.d.ts +92 -0
- package/lib/dist/ui-server/index.d.ts.map +1 -0
- package/lib/dist/ui-server/index.js +399 -0
- package/lib/dist/ui-server/index.js.map +1 -0
- package/lib/dist/ui-server/open-browser.d.ts +31 -0
- package/lib/dist/ui-server/open-browser.d.ts.map +1 -0
- package/lib/dist/ui-server/open-browser.js +79 -0
- package/lib/dist/ui-server/open-browser.js.map +1 -0
- package/lib/dist/ui-server/security.d.ts +127 -0
- package/lib/dist/ui-server/security.d.ts.map +1 -0
- package/lib/dist/ui-server/security.js +332 -0
- package/lib/dist/ui-server/security.js.map +1 -0
- package/lib/dist/ui-server/static.d.ts +45 -0
- package/lib/dist/ui-server/static.d.ts.map +1 -0
- package/lib/dist/ui-server/static.js +165 -0
- package/lib/dist/ui-server/static.js.map +1 -0
- package/lib/dist/utils.d.ts +14 -2
- package/lib/dist/utils.d.ts.map +1 -1
- package/lib/dist/utils.js +25 -10
- package/lib/dist/utils.js.map +1 -1
- package/lib/dist/viewer/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
- package/lib/dist/viewer/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
- package/lib/dist/viewer/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-italic-2syK4fUT.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-italic-CBJ8pzag.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-600-normal-CTOM6hUh.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-600-normal-fLZuRloM.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-italic-B4oTjJdl.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-italic-CBjNughH.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-600-normal-9HEixskS.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-600-normal-V-xxqcpd.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-italic-66oory27.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-italic-BqAiT5Ww.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-italic-B7_fu1kp.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-italic-Bg0ZHwF4.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-600-normal-D38SheWl.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-600-normal-DmB0ttJJ.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-italic-D6eaYXMU.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-italic-DRuN92E5.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-600-normal-D2EvbN8M.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-600-normal-iLQfcSjf.woff +0 -0
- package/lib/dist/viewer/assets/index-CF9yvio6.css +1 -0
- package/lib/dist/viewer/assets/index-D4S7YUPf.js +97 -0
- package/lib/dist/viewer/index.html +16 -0
- package/lib/kernel/codegraph-kernel.node +2 -2
- package/lib/node_modules/.package-lock.json +4 -4
- package/lib/node_modules/picomatch/README.md +56 -51
- package/lib/node_modules/picomatch/lib/constants.js +4 -0
- package/lib/node_modules/picomatch/lib/parse.js +341 -1
- package/lib/node_modules/picomatch/lib/picomatch.js +25 -5
- package/lib/node_modules/picomatch/lib/scan.js +30 -18
- package/lib/node_modules/picomatch/package.json +4 -4
- package/lib/package.json +9 -2
- package/package.json +1 -1
|
@@ -4,15 +4,52 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Handles symbol name matching for reference resolution.
|
|
6
6
|
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
7
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
41
|
exports.matchByFilePath = matchByFilePath;
|
|
9
42
|
exports.sameLanguageFamily = sameLanguageFamily;
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
43
|
+
exports.crossesCodeBoundary = crossesCodeBoundary;
|
|
44
|
+
exports.gateLanguageMatch = gateLanguageMatch;
|
|
12
45
|
exports.matchFunctionRef = matchFunctionRef;
|
|
46
|
+
exports.isVisibleAcrossFiles = isVisibleAcrossFiles;
|
|
13
47
|
exports.matchByExactName = matchByExactName;
|
|
14
48
|
exports.matchByQualifiedName = matchByQualifiedName;
|
|
15
49
|
exports.preferCallSiteFile = preferCallSiteFile;
|
|
50
|
+
exports.resolveObjectLiteralMember = resolveObjectLiteralMember;
|
|
51
|
+
exports.objectLiteralMemberBinding = objectLiteralMemberBinding;
|
|
52
|
+
exports.resolveObjectLiteralBinding = resolveObjectLiteralBinding;
|
|
16
53
|
exports.resolveMethodOnType = resolveMethodOnType;
|
|
17
54
|
exports.matchCppCallChain = matchCppCallChain;
|
|
18
55
|
exports.matchScopedCallChain = matchScopedCallChain;
|
|
@@ -21,9 +58,16 @@ exports.normalizeInferredTypeName = normalizeInferredTypeName;
|
|
|
21
58
|
exports.clearNameMatcherMemos = clearNameMatcherMemos;
|
|
22
59
|
exports.localReceiverTypePatterns = localReceiverTypePatterns;
|
|
23
60
|
exports.matchMethodCall = matchMethodCall;
|
|
61
|
+
exports.rustFieldTypeName = rustFieldTypeName;
|
|
62
|
+
exports.matchJsStoreBindingCall = matchJsStoreBindingCall;
|
|
63
|
+
exports.isUnresolvedJsMemberCall = isUnresolvedJsMemberCall;
|
|
24
64
|
exports.matchFuzzy = matchFuzzy;
|
|
25
65
|
exports.dumpNameMatcherProfile = dumpNameMatcherProfile;
|
|
26
66
|
exports.matchReference = matchReference;
|
|
67
|
+
const path = __importStar(require("path"));
|
|
68
|
+
const types_1 = require("./types");
|
|
69
|
+
const strip_comments_1 = require("./strip-comments");
|
|
70
|
+
const js_builtins_1 = require("./js-builtins");
|
|
27
71
|
/**
|
|
28
72
|
* Ceiling on how many same-named definitions a FUZZY name-match strategy will
|
|
29
73
|
* score. A name defined more times than this is "ubiquitous" — a method/symbol
|
|
@@ -143,14 +187,16 @@ function pickClosestFileNode(candidates, ref) {
|
|
|
143
187
|
*/
|
|
144
188
|
const LANGUAGE_FAMILY = {
|
|
145
189
|
java: 'jvm', kotlin: 'jvm', scala: 'jvm',
|
|
146
|
-
swift: '
|
|
190
|
+
swift: 'native', objc: 'native',
|
|
147
191
|
// ArkTS is a TS superset — every HarmonyOS project mixes `.ets` UI with
|
|
148
192
|
// `.ts` logic modules, so refs must cross freely between them.
|
|
149
193
|
typescript: 'web', tsx: 'web', javascript: 'web', jsx: 'web', arkts: 'web',
|
|
150
|
-
c: '
|
|
194
|
+
c: 'native', cpp: 'native',
|
|
151
195
|
// Razor/Blazor markup names C# types — same family so `@model Foo` /
|
|
152
196
|
// `<MyComponent/>` resolve to their `.cs` class through the cross-family gate.
|
|
153
|
-
csharp: 'dotnet', razor: 'dotnet',
|
|
197
|
+
csharp: 'dotnet', razor: 'dotnet', vbnet: 'dotnet',
|
|
198
|
+
svelte: 'web', vue: 'web', astro: 'web',
|
|
199
|
+
cfml: 'cfml', cfscript: 'cfml',
|
|
154
200
|
};
|
|
155
201
|
function sameLanguageFamily(a, b) {
|
|
156
202
|
if (a === b)
|
|
@@ -158,62 +204,324 @@ function sameLanguageFamily(a, b) {
|
|
|
158
204
|
const fa = LANGUAGE_FAMILY[a];
|
|
159
205
|
return fa !== undefined && fa === LANGUAGE_FAMILY[b];
|
|
160
206
|
}
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
function
|
|
169
|
-
return
|
|
207
|
+
/** Config/markup transitions stay open; every other code language has a family. */
|
|
208
|
+
const CODE_FAMILY = {
|
|
209
|
+
...LANGUAGE_FAMILY,
|
|
210
|
+
python: 'python', go: 'go', rust: 'rust', php: 'php', ruby: 'ruby', dart: 'dart',
|
|
211
|
+
lua: 'lua', luau: 'lua', r: 'r', erlang: 'erlang', pascal: 'pascal', solidity: 'solidity',
|
|
212
|
+
nix: 'nix', cobol: 'cobol',
|
|
213
|
+
};
|
|
214
|
+
function crossesCodeBoundary(a, b) {
|
|
215
|
+
return CODE_FAMILY[a] !== undefined && CODE_FAMILY[b] !== undefined &&
|
|
216
|
+
CODE_FAMILY[a] !== CODE_FAMILY[b];
|
|
170
217
|
}
|
|
171
218
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* React` matching a Swift `import React`, a C++ `#include "X.h"` matching a
|
|
175
|
-
* same-named ObjC header on another platform). The both-*known* test is
|
|
176
|
-
* deliberately weaker than {@link sameLanguageFamily}'s negation: a
|
|
177
|
-
* single-file-component language that carries its own tag (`vue`/`svelte`)
|
|
178
|
-
* importing a `.ts` module, or any singleton-family language (php/go/ruby/…),
|
|
179
|
-
* returns `false` here and is left alone.
|
|
219
|
+
* Cross-family name matches need a framework export or an actual ABI boundary,
|
|
220
|
+
* not merely a native caller. ABI evidence is scoped to the named free function.
|
|
180
221
|
*/
|
|
181
|
-
function
|
|
182
|
-
|
|
222
|
+
function hasBridgeEvidence(candidate, ref, context) {
|
|
223
|
+
if (ref.referenceKind !== 'calls')
|
|
224
|
+
return false;
|
|
225
|
+
// Expo's extractor creates explicit JS exports, resolved by the ordinary
|
|
226
|
+
// name matcher rather than a framework resolve() branch.
|
|
227
|
+
if (CODE_FAMILY[ref.language] === 'web' && candidate.id.startsWith('expo-module:') &&
|
|
228
|
+
candidate.isExported && (candidate.language === 'swift' || candidate.language === 'kotlin'))
|
|
229
|
+
return true;
|
|
230
|
+
if (candidate.kind !== 'function')
|
|
231
|
+
return false;
|
|
232
|
+
const name = candidate.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
233
|
+
if (CODE_FAMILY[ref.language] === 'native') {
|
|
234
|
+
const source = context.readFile(candidate.filePath);
|
|
235
|
+
if (!source)
|
|
236
|
+
return false;
|
|
237
|
+
if (candidate.language === 'go') {
|
|
238
|
+
const declaration = source.split('\n').slice(Math.max(0, candidate.startLine - 2), candidate.endLine).join('\n');
|
|
239
|
+
return /\bimport\s+(?:\(\s*)?"C"/.test((0, strip_comments_1.stripCommentsForRegex)(source, 'go')) &&
|
|
240
|
+
new RegExp('^//export ' + name + '\\r?\\nfunc ' + name + '\\s*\\(', 'm').test(declaration);
|
|
241
|
+
}
|
|
242
|
+
if (candidate.language === 'rust') {
|
|
243
|
+
const declaration = source.split('\n').slice(candidate.startLine - 1, candidate.endLine).join('\n');
|
|
244
|
+
return new RegExp('\\bpub\\s+extern\\s+"C"\\s+fn\\s+' + name + '\\b')
|
|
245
|
+
.test((0, strip_comments_1.stripCommentsForRegex)(declaration, 'rust'));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (candidate.language === 'c' || candidate.language === 'cpp') {
|
|
249
|
+
const source = context.readFile(ref.filePath);
|
|
250
|
+
if (!source)
|
|
251
|
+
return false;
|
|
252
|
+
if (ref.language === 'go') {
|
|
253
|
+
return /\bimport\s+(?:\(\s*)?"C"/.test((0, strip_comments_1.stripCommentsForRegex)(source, 'go')) &&
|
|
254
|
+
ref.referenceName === 'C.' + candidate.name;
|
|
255
|
+
}
|
|
256
|
+
if (ref.language === 'rust') {
|
|
257
|
+
return new RegExp('extern\\s+"C"\\s*\\{[^}]*\\bfn\\s+' + name + '\\s*\\(')
|
|
258
|
+
.test((0, strip_comments_1.stripCommentsForRegex)(source, 'rust'));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
183
262
|
}
|
|
184
263
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* - `imports` (import binding): an `import`/`#include` never crosses two
|
|
191
|
-
* KNOWN families (TS `import React` ↮ Swift `import React`). Weaker
|
|
192
|
-
* both-known filter so `.vue`/`.svelte` (own tag) importing `.ts` survives.
|
|
264
|
+
* Per-context memo: node id → its language, for gateLanguageMatch. Matches
|
|
265
|
+
* land on ~5 refs per target on vscode, and each check otherwise fetched the
|
|
266
|
+
* whole node (a point read + row decode past the query layer's small cache)
|
|
267
|
+
* only to read one field. Nodes are fixed within a resolution pass; the memo
|
|
268
|
+
* drops with clearNameMatcherMemos.
|
|
193
269
|
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
270
|
+
const TARGET_LANGUAGE = new WeakMap();
|
|
271
|
+
/** Reject the chosen result without shrinking a pool or trying a replacement. */
|
|
272
|
+
function gateLanguageMatch(result, ref, context) {
|
|
273
|
+
if (!result)
|
|
274
|
+
return result;
|
|
275
|
+
// No code family on the reference's side: no target can cross a boundary.
|
|
276
|
+
if (CODE_FAMILY[ref.language] === undefined)
|
|
277
|
+
return result;
|
|
278
|
+
if (context.getNodeById) {
|
|
279
|
+
let languages = TARGET_LANGUAGE.get(context);
|
|
280
|
+
if (!languages) {
|
|
281
|
+
languages = new Map();
|
|
282
|
+
TARGET_LANGUAGE.set(context, languages);
|
|
283
|
+
}
|
|
284
|
+
let language = languages.get(result.targetNodeId);
|
|
285
|
+
if (language === undefined) {
|
|
286
|
+
const node = context.getNodeById(result.targetNodeId);
|
|
287
|
+
if (node) {
|
|
288
|
+
language = node.language;
|
|
289
|
+
if (languages.size >= 400_000)
|
|
290
|
+
languages.clear();
|
|
291
|
+
languages.set(result.targetNodeId, language);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (language !== undefined) {
|
|
295
|
+
if (!crossesCodeBoundary(ref.language, language))
|
|
296
|
+
return result;
|
|
297
|
+
const target = context.getNodeById(result.targetNodeId);
|
|
298
|
+
return target && !hasBridgeEvidence(target, ref, context) ? null : result;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const target = context.getNodeById?.(result.targetNodeId) ??
|
|
302
|
+
context.getNodesByName(ref.referenceName).find((n) => n.id === result.targetNodeId);
|
|
303
|
+
if (target && crossesCodeBoundary(ref.language, target.language) &&
|
|
304
|
+
!hasBridgeEvidence(target, ref, context))
|
|
305
|
+
return null;
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
/** Member values retain their receiver; never break ties by file order (#1820). */
|
|
309
|
+
function matchMemberFunctionRef(ref, context) {
|
|
310
|
+
const dot = ref.referenceName.lastIndexOf('.');
|
|
311
|
+
const receiver = ref.referenceName.slice(0, dot);
|
|
312
|
+
const member = ref.referenceName.slice(dot + 1);
|
|
313
|
+
const result = (nodes, confidence = 0.9) => {
|
|
314
|
+
const pool = nodes.filter(n => sameLanguageFamily(n.language, ref.language));
|
|
315
|
+
const target = pool.length === 1 ? pool[0] : undefined;
|
|
316
|
+
return target && (target.kind === 'function' || target.kind === 'method') &&
|
|
317
|
+
target.id !== ref.fromNodeId && !isPythonProperty(target, context)
|
|
318
|
+
? { original: ref, targetNodeId: target.id, confidence, resolvedBy: 'function-ref' }
|
|
319
|
+
: null;
|
|
320
|
+
};
|
|
321
|
+
const imports = context.getImportMappings(ref.filePath, ref.language);
|
|
322
|
+
// An import is authoritative even when it points outside the project.
|
|
323
|
+
if (imports.some(i => i.localName === receiver.split('.')[0])) {
|
|
324
|
+
if (ref.language === 'python') {
|
|
325
|
+
const cls = pythonRefClass(receiver, ref, context);
|
|
326
|
+
if (cls)
|
|
327
|
+
return result(pythonMembers(cls, member, ref, context));
|
|
328
|
+
}
|
|
329
|
+
const imported = context.resolveImport?.(ref);
|
|
330
|
+
const node = imported && context.getNodeById?.(imported.targetNodeId);
|
|
331
|
+
return node ? result(context.getNodesByQualifiedName(node.qualifiedName).filter(n => n.filePath === node.filePath)) : null;
|
|
332
|
+
}
|
|
333
|
+
if (ref.language === 'go') {
|
|
334
|
+
if (receiver.includes('.'))
|
|
335
|
+
return matchGoFieldChainCall(receiver, member, ref, context);
|
|
336
|
+
const type = inferLocalReceiverType(receiver, ref, context);
|
|
337
|
+
if (type)
|
|
338
|
+
return resolveMethodOnType(type, member, ref, context, 0.9, 'function-ref');
|
|
339
|
+
const types = context.getNodesByName(receiver).filter(n => n.language === 'go' && (n.kind === 'struct' || n.kind === 'interface'));
|
|
340
|
+
if (types.length)
|
|
341
|
+
return types.length === 1 ? resolveMethodOnType(receiver, member, ref, context, 0.9, 'function-ref') : null;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const owner = context.getNodesInFile(ref.filePath).filter(n => n.kind === 'class' && n.startLine <= ref.line && n.endLine >= ref.line)
|
|
345
|
+
.sort((a, b) => b.startLine - a.startLine)[0];
|
|
346
|
+
let type = null;
|
|
347
|
+
if (receiver === 'self' || receiver === 'cls') {
|
|
348
|
+
return owner ? result(pythonMembers(owner, member, ref, context)) : null;
|
|
349
|
+
}
|
|
350
|
+
if (/^(self|cls)\.\w+$/.test(receiver)) {
|
|
351
|
+
if (!owner)
|
|
352
|
+
return null;
|
|
353
|
+
type = pythonFieldType(receiver, owner, ref, context);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
type = pythonLocalType(receiver, ref, context);
|
|
357
|
+
}
|
|
358
|
+
// A type name used directly (`Store.fetch`) is scoped just like an annotation.
|
|
359
|
+
if (!type && /^[A-Z]\w*$/.test(receiver))
|
|
360
|
+
type = receiver;
|
|
361
|
+
if (type && type !== 'object' && type !== 'Any') {
|
|
362
|
+
const cls = pythonRefClass(type, ref, context);
|
|
363
|
+
if (!cls)
|
|
364
|
+
return null;
|
|
365
|
+
const members = pythonMembers(cls, member, ref, context);
|
|
366
|
+
if (members.length)
|
|
367
|
+
return result(members);
|
|
368
|
+
// A base-typed field can hold a subclass-only method (the reported case).
|
|
369
|
+
// Keep only descendants of THAT base; unrelated same-name methods cannot win.
|
|
370
|
+
const candidates = context.getNodesByName(member).filter(n => n.kind === 'method' && n.language === 'python');
|
|
371
|
+
const descendants = candidates.filter(n => {
|
|
372
|
+
const parent = context.getNodesInFile(n.filePath).find(c => c.kind === 'class' && n.qualifiedName === `${c.qualifiedName}::${member}`);
|
|
373
|
+
return parent && pythonDerivesFrom(parent, cls, ref, context);
|
|
374
|
+
});
|
|
375
|
+
return result(descendants, 0.8);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
// Unknown receivers retain the old unique-or-drop discipline, across ALL
|
|
379
|
+
// files. Tests and abstract-looking bodies are candidates too.
|
|
380
|
+
return result(context.getNodesByName(member), 0.8);
|
|
381
|
+
}
|
|
382
|
+
function pythonRefClass(name, ref, context) {
|
|
383
|
+
const imports = context.getImportMappings(ref.filePath, 'python');
|
|
384
|
+
if (imports.some(i => i.localName === name.split('.')[0])) {
|
|
385
|
+
const hit = context.resolveImport?.({ ...ref, referenceName: name, referenceKind: 'references' });
|
|
386
|
+
const node = hit && context.getNodeById?.(hit.targetNodeId);
|
|
387
|
+
return node?.kind === 'class' && context.getNodesByQualifiedName(node.qualifiedName)
|
|
388
|
+
.filter(n => n.kind === 'class' && n.filePath === node.filePath).length === 1 ? node : null;
|
|
389
|
+
}
|
|
390
|
+
const classes = context.getNodesByName(name).filter(n => n.kind === 'class' && n.filePath === ref.filePath);
|
|
391
|
+
return classes.length === 1 ? classes[0] : null;
|
|
392
|
+
}
|
|
393
|
+
function pythonBases(cls, ref, context) {
|
|
394
|
+
const line = context.getFileLines?.(cls.filePath)?.[cls.startLine - 1]
|
|
395
|
+
?? context.readFile(cls.filePath)?.split('\n')[cls.startLine - 1] ?? '';
|
|
396
|
+
const bases = line.match(/^\s*class\s+\w+\s*\(([^)]*)\)/)?.[1];
|
|
397
|
+
return (bases?.split(',') ?? []).flatMap(name => {
|
|
398
|
+
const base = pythonRefClass(name.trim(), { ...ref, filePath: cls.filePath }, context);
|
|
399
|
+
return base ? [base] : [];
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function pythonDerivesFrom(cls, base, ref, context, seen = new Set()) {
|
|
403
|
+
if (seen.has(cls.id) || seen.size >= 16)
|
|
404
|
+
return false;
|
|
405
|
+
seen.add(cls.id);
|
|
406
|
+
return pythonBases(cls, ref, context).some(p => p.id === base.id || pythonDerivesFrom(p, base, ref, context, seen));
|
|
407
|
+
}
|
|
408
|
+
function pythonMembers(cls, member, ref, context, seen = new Set()) {
|
|
409
|
+
if (seen.has(cls.id) || seen.size >= 16)
|
|
410
|
+
return [];
|
|
411
|
+
seen.add(cls.id);
|
|
412
|
+
// Instance assignments also shadow methods, even though they are not nodes.
|
|
413
|
+
const body = pythonMemberLines(cls.filePath, context).slice(cls.startLine - 1, cls.endLine).join('\n');
|
|
414
|
+
if (new RegExp(`^\\s*(?:(?:self|cls)\\.)?${member}\\s*(?:=|:)`, 'm').test(body))
|
|
415
|
+
return [cls];
|
|
416
|
+
const own = context.getNodesByQualifiedName(`${cls.qualifiedName}::${member}`).filter(n => n.filePath === cls.filePath);
|
|
417
|
+
if (own.length)
|
|
418
|
+
return own;
|
|
419
|
+
return [...new Map(pythonBases(cls, ref, context).flatMap(p => pythonMembers(p, member, ref, context, seen)).map(n => [n.id, n])).values()];
|
|
420
|
+
}
|
|
421
|
+
function isPythonProperty(node, context) {
|
|
422
|
+
if (node.language !== 'python' || node.kind !== 'method')
|
|
423
|
+
return false;
|
|
424
|
+
const lines = context.getFileLines?.(node.filePath) ?? context.readFile(node.filePath)?.split('\n') ?? [];
|
|
425
|
+
for (let i = node.startLine - 2; i >= 0 && lines[i].trim().startsWith('@'); i--) {
|
|
426
|
+
if (/^\s*@(?:property|(?:functools\.)?cached_property)\s*$/.test(lines[i]))
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
const PYTHON_MEMBER_LINES = new WeakMap();
|
|
432
|
+
function pythonMemberLines(filePath, context) {
|
|
433
|
+
let files = PYTHON_MEMBER_LINES.get(context);
|
|
434
|
+
if (!files) {
|
|
435
|
+
files = new Map();
|
|
436
|
+
PYTHON_MEMBER_LINES.set(context, files);
|
|
437
|
+
}
|
|
438
|
+
let lines = files.get(filePath);
|
|
439
|
+
if (!lines) {
|
|
440
|
+
lines = (0, strip_comments_1.stripCommentsForRegex)(context.readFile(filePath) ?? '', 'python').split('\n');
|
|
441
|
+
files.set(filePath, lines);
|
|
442
|
+
}
|
|
443
|
+
return lines;
|
|
444
|
+
}
|
|
445
|
+
function pythonLocalType(receiver, ref, context) {
|
|
446
|
+
if (!/^\w+$/.test(receiver))
|
|
447
|
+
return null;
|
|
448
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
449
|
+
const lines = pythonMemberLines(ref.filePath, context);
|
|
450
|
+
const declaration = new RegExp(`^\\s*${receiver}\\s*(?::\\s*["']?([\\w.]+)["']?)?\\s*=\\s*(.*)$`);
|
|
451
|
+
const annotation = new RegExp(`^\\s*${receiver}\\s*:\\s*["']?([\\w.]+)`);
|
|
452
|
+
for (let i = ref.line - 1; i >= (caller?.startLine ?? 1) - 1; i--) {
|
|
453
|
+
const line = lines[i] ?? '';
|
|
454
|
+
const assigned = line.match(declaration);
|
|
455
|
+
if (assigned)
|
|
456
|
+
return assigned[1] ?? assigned[2].match(/^([A-Z][\w.]*)\s*\(/)?.[1] ?? '<unknown>';
|
|
457
|
+
const declared = line.match(annotation)?.[1];
|
|
458
|
+
if (declared)
|
|
459
|
+
return declared;
|
|
197
460
|
}
|
|
198
|
-
|
|
199
|
-
|
|
461
|
+
return caller?.signature?.match(new RegExp(`\\b${receiver}\\s*:\\s*["']?([\\w.]+)`))?.[1] ?? null;
|
|
462
|
+
}
|
|
463
|
+
/** Read a field's own annotation/initializer, or a constructor parameter assigned to it. */
|
|
464
|
+
function pythonFieldType(receiver, owner, ref, context) {
|
|
465
|
+
const lines = pythonMemberLines(ref.filePath, context);
|
|
466
|
+
const field = receiver.split('.')[1];
|
|
467
|
+
const assignment = new RegExp(`^\\s*(?:self|cls)\\.${field}\\s*(?::\\s*["']?([\\w.]+)["']?)?\\s*=\\s*(.*)$`);
|
|
468
|
+
const annotation = new RegExp(`^\\s*(?:(?:self|cls)\\.)?${field}\\s*:\\s*["']?([\\w.]+)`);
|
|
469
|
+
const methods = context.getNodesInFile(ref.filePath).filter(n => n.kind === 'method' &&
|
|
470
|
+
n.qualifiedName.startsWith(`${owner.qualifiedName}::`));
|
|
471
|
+
const types = new Set();
|
|
472
|
+
for (let i = owner.startLine; i < owner.endLine; i++) {
|
|
473
|
+
const method = methods.find(n => n.startLine <= i + 1 && n.endLine >= i + 1);
|
|
474
|
+
if (method && method.name !== '__init__' && method.id !== ref.fromNodeId)
|
|
475
|
+
continue;
|
|
476
|
+
if (method?.id === ref.fromNodeId && i + 1 > ref.line)
|
|
477
|
+
continue;
|
|
478
|
+
const line = lines[i] ?? '';
|
|
479
|
+
const declared = !method || /^\s*(?:self|cls)\./.test(line) ? line.match(annotation)?.[1] : undefined;
|
|
480
|
+
if (declared)
|
|
481
|
+
types.add(declared);
|
|
482
|
+
const assigned = line.match(assignment);
|
|
483
|
+
if (!assigned)
|
|
484
|
+
continue;
|
|
485
|
+
if (assigned[1]) {
|
|
486
|
+
types.add(assigned[1]);
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
const constructor = assigned[2].match(/^([A-Z][\w.]*)\s*\(/)?.[1];
|
|
490
|
+
if (constructor) {
|
|
491
|
+
types.add(constructor);
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const param = assigned[2].trim();
|
|
495
|
+
if (method && /^\w+$/.test(param)) {
|
|
496
|
+
const signature = method.signature ?? '';
|
|
497
|
+
const type = signature.match(new RegExp(`\\b${param}\\s*:\\s*["']?([\\w.]+)`))?.[1];
|
|
498
|
+
if (type)
|
|
499
|
+
types.add(type);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
types.add('<unknown>');
|
|
503
|
+
}
|
|
200
504
|
}
|
|
201
|
-
|
|
505
|
+
// Conflicting assignments are known-but-ambiguous, never a name-only fallback.
|
|
506
|
+
return types.size === 1 ? [...types][0] : types.size > 1 ? '<ambiguous>' : null;
|
|
202
507
|
}
|
|
203
508
|
/**
|
|
204
509
|
* Resolve a function-as-value reference (#756) — a function name used as a
|
|
205
510
|
* callback/function-pointer value (`register(handler)`, `o->cb = handler`,
|
|
206
511
|
* `{ .cb = handler }`, `signal(SIGINT, handler)`). The ONLY strategy allowed
|
|
207
512
|
* for `function_ref` refs: exact name, function/method targets only, same
|
|
208
|
-
* language family, same-file first, and cross-file
|
|
209
|
-
*
|
|
210
|
-
* edge is worse than none.
|
|
513
|
+
* language family, same-file first for bare names, and unique-only cross-file.
|
|
514
|
+
* Member values use receiver/type/import scope before a unique-name fallback.
|
|
515
|
+
* A wrong callback edge is worse than none.
|
|
211
516
|
*/
|
|
212
517
|
function matchFunctionRef(ref, context) {
|
|
213
518
|
// `this.<member>` refs are resolved ONLY by the class-scoped resolver in
|
|
214
519
|
// resolveOne (resolveThisMemberFnRef) — never by name matching here.
|
|
215
520
|
if (ref.referenceName.startsWith('this.'))
|
|
216
521
|
return null;
|
|
522
|
+
if ((ref.language === 'python' || ref.language === 'go') && ref.referenceName.includes('.')) {
|
|
523
|
+
return matchMemberFunctionRef(ref, context);
|
|
524
|
+
}
|
|
217
525
|
// In JS/TS/Python a bare identifier can never be a method value (methods
|
|
218
526
|
// are only reachable through a receiver — `this.m` / `self.m` /
|
|
219
527
|
// `Cls.m`), so bare fn-refs match FUNCTIONS only. This also sidesteps the
|
|
@@ -231,6 +539,15 @@ function matchFunctionRef(ref, context) {
|
|
|
231
539
|
ref.language === 'arkts' ||
|
|
232
540
|
ref.language === 'cpp' || ref.language === 'python' ||
|
|
233
541
|
ref.language === 'php';
|
|
542
|
+
// Python additionally accepts CLASS targets for bare identifiers (#1478):
|
|
543
|
+
// class-as-value is a core Python idiom (`return SomeSerializer`,
|
|
544
|
+
// `Meta.model = Org`, registry dicts, `admin.site.register(Model, Admin)`)
|
|
545
|
+
// and, unlike TS, Python has no type-annotation recovery path. The
|
|
546
|
+
// false-positive mechanism behind the function-only rule was lowercase
|
|
547
|
+
// locals colliding with same-named METHODS (docopt.py) — a candidate must
|
|
548
|
+
// be an exact-name CLASS node here, and the extraction gate (same-file
|
|
549
|
+
// class ∪ imports) plus unique-or-drop still apply. Methods stay excluded.
|
|
550
|
+
const bareClassOk = ref.language === 'python';
|
|
234
551
|
// Qualified member-pointer (`&Widget::on_click` → "Widget::on_click"):
|
|
235
552
|
// resolve the member ON THAT SCOPE — exempt from bareFnOnly (the `&Cls::m`
|
|
236
553
|
// shape is an explicit member reference). Unique-or-drop like everything else.
|
|
@@ -259,7 +576,9 @@ function matchFunctionRef(ref, context) {
|
|
|
259
576
|
}
|
|
260
577
|
let candidates = context
|
|
261
578
|
.getNodesByName(ref.referenceName)
|
|
262
|
-
.filter((n) => (n.kind === 'function' ||
|
|
579
|
+
.filter((n) => (n.kind === 'function' ||
|
|
580
|
+
(!bareFnOnly && n.kind === 'method') ||
|
|
581
|
+
(bareClassOk && n.kind === 'class')) &&
|
|
263
582
|
sameLanguageFamily(n.language, ref.language) &&
|
|
264
583
|
n.id !== ref.fromNodeId // a function registering itself is not a dependency edge
|
|
265
584
|
);
|
|
@@ -332,6 +651,8 @@ function matchFunctionRef(ref, context) {
|
|
|
332
651
|
}
|
|
333
652
|
return null;
|
|
334
653
|
}
|
|
654
|
+
/** Languages with no nested named functions: nesting in the graph is never a scope. */
|
|
655
|
+
const NO_NESTED_FUNCTIONS = new Set(['c', 'cpp']);
|
|
335
656
|
/**
|
|
336
657
|
* A function nested inside another FUNCTION is only callable from within its
|
|
337
658
|
* container — Python, JS/TS, and every closure language scope it lexically.
|
|
@@ -346,6 +667,15 @@ function matchFunctionRef(ref, context) {
|
|
|
346
667
|
function isLexicallyReachable(candidate, ref, context) {
|
|
347
668
|
if (candidate.kind !== 'function')
|
|
348
669
|
return true;
|
|
670
|
+
// C and C++ have no nested named functions, so a function the graph shows
|
|
671
|
+
// inside another is an extraction artifact, not a scope: tree-sitter-c
|
|
672
|
+
// cannot parse a macro call whose arguments are designated initializers
|
|
673
|
+
// (betaflight's `RESET_CONFIG(pidProfile_t, pidProfile, .pid = {…})`), and
|
|
674
|
+
// its error recovery runs the enclosing function_definition to the end of
|
|
675
|
+
// the file, nesting every function after it. Trusting that nesting rejected
|
|
676
|
+
// 117 real calls into pid.c on that tree; the functions are reachable.
|
|
677
|
+
if (NO_NESTED_FUNCTIONS.has(candidate.language))
|
|
678
|
+
return true;
|
|
349
679
|
const qn = candidate.qualifiedName;
|
|
350
680
|
if (!qn || !qn.includes('::'))
|
|
351
681
|
return true;
|
|
@@ -361,6 +691,469 @@ function isLexicallyReachable(candidate, ref, context) {
|
|
|
361
691
|
return (ref.filePath === candidate.filePath &&
|
|
362
692
|
containers.some((p) => ref.line >= p.startLine && ref.line <= p.endLine));
|
|
363
693
|
}
|
|
694
|
+
/** Languages whose module boundary is `import`/`export` (or CommonJS). */
|
|
695
|
+
const ESM_FAMILY = new Set(['typescript', 'tsx', 'javascript', 'jsx', 'arkts']);
|
|
696
|
+
/**
|
|
697
|
+
* A line-initial `import` statement — the marker that a JS/TS file is a MODULE
|
|
698
|
+
* rather than a classic script. Line-anchored and followed by a name, brace,
|
|
699
|
+
* star or quote, so a dynamic `import(` and the word inside a comment or string
|
|
700
|
+
* do not match.
|
|
701
|
+
*/
|
|
702
|
+
const HAS_IMPORT_STATEMENT = /^[ \t]*import[\s{*'"]/m;
|
|
703
|
+
/**
|
|
704
|
+
* Anything the file could offer another file, in every form the extractor's own
|
|
705
|
+
* `isExported` flag misses. `^export` covers the declaration and later forms
|
|
706
|
+
* (`export const`, `export { x }`, `export default x`, `export *`); the
|
|
707
|
+
* CommonJS shapes cover files that never use ESM syntax at all, in both the dot
|
|
708
|
+
* and the bracket form; and `declare global` contributes names to every file
|
|
709
|
+
* whether or not the module exports anything of its own. Kept as a source test
|
|
710
|
+
* rather than a node scan precisely because `isExported` is set only from an
|
|
711
|
+
* `export_statement` ancestor, so `const x = …; export { x }` and
|
|
712
|
+
* `module.exports = { x }` both read as unexported on the node.
|
|
713
|
+
*/
|
|
714
|
+
const HAS_ESM_EXPORT = /^[ \t]*export[\s{*]|^[ \t]*declare\s+global\b/m;
|
|
715
|
+
const HAS_CJS_EXPORT = /\bmodule\.exports\b|\bexports\s*[.[]/;
|
|
716
|
+
/**
|
|
717
|
+
* Per-context memo of "this file is a module that exports nothing", asked once
|
|
718
|
+
* per candidate FILE rather than once per reference. Derived from file source,
|
|
719
|
+
* so it drops with the context's file caches — clearNameMatcherMemos deletes it
|
|
720
|
+
* alongside INFER_SCAN_STATES.
|
|
721
|
+
*/
|
|
722
|
+
const SEALED_MODULES = new WeakMap();
|
|
723
|
+
/**
|
|
724
|
+
* Whether `filePath` is a JS/TS module that exports NOTHING — an import
|
|
725
|
+
* statement present, no export of any form. No reference from another file can
|
|
726
|
+
* reach any binding in such a file, so every one of its symbols is a false
|
|
727
|
+
* candidate for a cross-file name match.
|
|
728
|
+
*
|
|
729
|
+
* This is the general case behind a package name capturing a same-named local:
|
|
730
|
+
* on `vitejs/vite`, 157 cross-file `imports` refs — every `import { defineConfig
|
|
731
|
+
* } from 'vite'` in the playground and the create-vite templates — resolved onto
|
|
732
|
+
* `playground/ssr-html/test-stacktrace.js::vite`, which is `const vite = await
|
|
733
|
+
* createServer(…)` at module scope in a file with zero exports. The existing
|
|
734
|
+
* guards cannot see it: `isLexicallyReachable` returns early for any candidate
|
|
735
|
+
* that is not a `function`, and the bare-import guard correctly declines because
|
|
736
|
+
* `vite` IS a workspace member, so the specifier really is project-local. What
|
|
737
|
+
* is wrong is only which node the name lands on.
|
|
738
|
+
*
|
|
739
|
+
* Deliberately narrow on three axes, because each is a class this would
|
|
740
|
+
* otherwise resolve wrongly in the opposite direction:
|
|
741
|
+
*
|
|
742
|
+
* - **A classic script is exempt.** Requiring an `import` statement means a
|
|
743
|
+
* non-module `.js` file — concatenated globals, a browser `<script>` — keeps
|
|
744
|
+
* its cross-file matches, where a top-level binding genuinely is reachable.
|
|
745
|
+
* - **CommonJS is exempt.** `module.exports` and `exports.x` are matched as
|
|
746
|
+
* exports, so a CJS file is never sealed.
|
|
747
|
+
* - **Other languages are exempt.** Go, Python, Java and the rest have no
|
|
748
|
+
* equivalent boundary, and several extractors hardcode `isExported`.
|
|
749
|
+
*/
|
|
750
|
+
function isSealedModule(filePath, context) {
|
|
751
|
+
let memo = SEALED_MODULES.get(context);
|
|
752
|
+
if (!memo) {
|
|
753
|
+
memo = new Map();
|
|
754
|
+
SEALED_MODULES.set(context, memo);
|
|
755
|
+
}
|
|
756
|
+
const hit = memo.get(filePath);
|
|
757
|
+
if (hit !== undefined)
|
|
758
|
+
return hit;
|
|
759
|
+
// CommonJS assignments can execute inside template interpolations, which the
|
|
760
|
+
// masker blanks. Keep the conservative raw-source exemption for those forms.
|
|
761
|
+
// Cheapest disqualifiers first: nearly every module exports a node (asked
|
|
762
|
+
// without reading or decoding the file), and masking the source is only
|
|
763
|
+
// needed to rule out the ones that don't. (The masker only blanks text, so
|
|
764
|
+
// no `import` in the source means none in code.)
|
|
765
|
+
const exportsNode = context.fileHasExportedNode
|
|
766
|
+
? context.fileHasExportedNode(filePath)
|
|
767
|
+
: context.getNodesInFile(filePath).some((n) => n.isExported);
|
|
768
|
+
const source = exportsNode ? null : context.readFile(filePath);
|
|
769
|
+
const sealed = !exportsNode && source !== null && source.includes('import') &&
|
|
770
|
+
!HAS_CJS_EXPORT.test(source) &&
|
|
771
|
+
(() => {
|
|
772
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(source, 'typescript'));
|
|
773
|
+
return HAS_IMPORT_STATEMENT.test(code) && !HAS_ESM_EXPORT.test(code);
|
|
774
|
+
})();
|
|
775
|
+
memo.set(filePath, sealed);
|
|
776
|
+
return sealed;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Whether `candidate` can be named by a reference in `ref`'s file at all.
|
|
780
|
+
* Both name-based strategies validate their chosen candidate. Removing an
|
|
781
|
+
* unreachable candidate before ranking can promote an unrelated runner-up;
|
|
782
|
+
* rejecting the chosen target must leave the reference unresolved instead.
|
|
783
|
+
*/
|
|
784
|
+
function isCrossFileReachable(candidate, ref, context) {
|
|
785
|
+
if (ref.language !== 'markdown' && candidate.language === 'markdown')
|
|
786
|
+
return false;
|
|
787
|
+
if (ref.referenceKind === 'calls' && ESM_FAMILY.has(candidate.language) &&
|
|
788
|
+
(candidate.kind === 'constant' || candidate.kind === 'variable') &&
|
|
789
|
+
/^=\s*require\s*\(\s*(['"])[^'"]+\.json\1\s*\)\s*;?\s*$/.test(candidate.signature ?? ''))
|
|
790
|
+
return false;
|
|
791
|
+
return (candidate.filePath === ref.filePath ||
|
|
792
|
+
!ESM_FAMILY.has(candidate.language) ||
|
|
793
|
+
!isSealedModule(candidate.filePath, context));
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Languages in which `visibility: 'private'` on a definition means no other
|
|
797
|
+
* FILE can name it: a Kotlin `private fun` is file- or class-local, and the
|
|
798
|
+
* same holds for Java, C#, Swift, Scala, Dart and PHP members.
|
|
799
|
+
*/
|
|
800
|
+
const PRIVATE_IS_FILE_LOCAL = new Set(['kotlin', 'java', 'csharp', 'swift', 'scala', 'dart', 'php']);
|
|
801
|
+
/** Per-context memo: node id → "this C/C++ function is declared `static`". */
|
|
802
|
+
const C_STATIC_MEMO = new WeakMap();
|
|
803
|
+
/**
|
|
804
|
+
* A C/C++ file that IS a translation unit. A `static` defined here is local
|
|
805
|
+
* to it. A `static` (typically `static inline`) in a header is a different
|
|
806
|
+
* thing: the header is textually included, so the function exists in every
|
|
807
|
+
* unit that includes it and is callable from each — MAVLink's generated
|
|
808
|
+
* `mavlink_msg_*.h` are nothing but such functions, 4,306 real calls on one
|
|
809
|
+
* betaflight tree.
|
|
810
|
+
*/
|
|
811
|
+
const C_SOURCE_EXT = /\.(c|cc|cpp|cxx|c\+\+|m|mm)$/i;
|
|
812
|
+
/**
|
|
813
|
+
* Whether a C/C++ function definition carries the `static` storage class —
|
|
814
|
+
* read from its first source line(s), since the extractor records no storage
|
|
815
|
+
* class and the kernel arm would need the same field. `static` on the line
|
|
816
|
+
* above the name (`static void\nfoo(void)`) is the common alternative layout.
|
|
817
|
+
*/
|
|
818
|
+
function isStaticCFunction(candidate, context) {
|
|
819
|
+
let memo = C_STATIC_MEMO.get(context);
|
|
820
|
+
if (!memo) {
|
|
821
|
+
memo = new Map();
|
|
822
|
+
C_STATIC_MEMO.set(context, memo);
|
|
823
|
+
}
|
|
824
|
+
const hit = memo.get(candidate.id);
|
|
825
|
+
if (hit !== undefined)
|
|
826
|
+
return hit;
|
|
827
|
+
const lines = context.getFileLines?.(candidate.filePath) ?? context.readFile(candidate.filePath)?.split('\n') ?? [];
|
|
828
|
+
const head = [lines[candidate.startLine - 2] ?? '', lines[candidate.startLine - 1] ?? ''].join('\n');
|
|
829
|
+
const isStatic = /(^|[\s;}])static\s/.test(head);
|
|
830
|
+
memo.set(candidate.id, isStatic);
|
|
831
|
+
return isStatic;
|
|
832
|
+
}
|
|
833
|
+
/** Per-context memo: node id → "this Rust method implements a trait". */
|
|
834
|
+
const RUST_TRAIT_IMPL_MEMO = new WeakMap();
|
|
835
|
+
/**
|
|
836
|
+
* Whether a Rust method sits in an `impl Trait for Type` block. Such a method
|
|
837
|
+
* carries no `pub` — the trait decides its visibility — so the extractor
|
|
838
|
+
* records it as private; it is reachable wherever the trait is. Read from the
|
|
839
|
+
* nearest enclosing `impl` header above the method, memoised per node.
|
|
840
|
+
*/
|
|
841
|
+
function isRustTraitImplMethod(candidate, context) {
|
|
842
|
+
if (candidate.kind !== 'method')
|
|
843
|
+
return false;
|
|
844
|
+
let memo = RUST_TRAIT_IMPL_MEMO.get(context);
|
|
845
|
+
if (!memo) {
|
|
846
|
+
memo = new Map();
|
|
847
|
+
RUST_TRAIT_IMPL_MEMO.set(context, memo);
|
|
848
|
+
}
|
|
849
|
+
const hit = memo.get(candidate.id);
|
|
850
|
+
if (hit !== undefined)
|
|
851
|
+
return hit;
|
|
852
|
+
const lines = context.getFileLines?.(candidate.filePath) ?? context.readFile(candidate.filePath)?.split('\n') ?? [];
|
|
853
|
+
let isTrait = false;
|
|
854
|
+
for (let i = candidate.startLine - 2; i >= 0; i--) {
|
|
855
|
+
const line = lines[i] ?? '';
|
|
856
|
+
if (/^\s*(pub(\([^)]*\))?\s+)?(unsafe\s+)?impl\b/.test(line)) {
|
|
857
|
+
isTrait = /\sfor\s/.test(line.replace(/\/\/.*$/, ''));
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
// A top-level item above the method means it was not inside an impl.
|
|
861
|
+
if (/^(pub(\([^)]*\))?\s+)?(fn|struct|enum|mod|trait|const|static|type)\b/.test(line))
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
memo.set(candidate.id, isTrait);
|
|
865
|
+
return isTrait;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* The directory a Rust file's private items are visible from: the file's own
|
|
869
|
+
* module subtree. `src/net.rs` and `src/net/mod.rs` own `src/net/`; a crate
|
|
870
|
+
* root (`lib.rs` / `main.rs`) owns its directory. A child module reaches its
|
|
871
|
+
* ancestors' private items (`super::`), a sibling or another crate never does.
|
|
872
|
+
*/
|
|
873
|
+
function rustModuleDir(filePath) {
|
|
874
|
+
const base = path.posix.basename(filePath);
|
|
875
|
+
const dir = path.posix.dirname(filePath);
|
|
876
|
+
if (base === 'mod.rs' || base === 'lib.rs' || base === 'main.rs')
|
|
877
|
+
return dir;
|
|
878
|
+
return path.posix.join(dir, base.replace(/\.rs$/, ''));
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Whether `candidate` can be NAMED from a reference in `ref`'s file at all,
|
|
882
|
+
* given what its language says about the definition's visibility. A
|
|
883
|
+
* definition the language makes file-local is not a candidate for a
|
|
884
|
+
* cross-file name match, however well the names agree:
|
|
885
|
+
*
|
|
886
|
+
* - **C / C++**: a `static` function defined in a SOURCE file is local to
|
|
887
|
+
* that translation unit; one in a header is part of every unit that
|
|
888
|
+
* includes it and stays visible. On a 2,109-file betaflight tree 145
|
|
889
|
+
* cross-file calls resolved onto a `static` in another `.c` (#1730) —
|
|
890
|
+
* `usbd_get_descriptor` onto the `static get_device_descriptor` of
|
|
891
|
+
* whichever USB class file ranked first.
|
|
892
|
+
* - **Kotlin, Java, C#, Swift, Scala, Dart, PHP**: `private` is class- or
|
|
893
|
+
* file-local. An Android `editor.apply()` resolved onto an unrelated class's
|
|
894
|
+
* `private fun apply`.
|
|
895
|
+
* - **Go**: an unexported (lowercase) identifier is package-local, and a
|
|
896
|
+
* package is a directory. Judged by the name's case: the extractor's
|
|
897
|
+
* `isExported` is unset for every Go method.
|
|
898
|
+
* - **Rust**: a non-`pub` item is visible to its module and that module's
|
|
899
|
+
* descendants, never to a sibling module or another crate — `.count()` on
|
|
900
|
+
* an iterator resolved onto a `fn count` in a different crate. A method in
|
|
901
|
+
* an `impl Trait for Type` block has the trait's visibility, not `private`.
|
|
902
|
+
* - **JS / TS / ArkTS**: a binding in a module that exports nothing (an
|
|
903
|
+
* `import` present, no `export` / CommonJS / `declare global`) is sealed —
|
|
904
|
+
* the vite playground's `const vite = await createServer(…)` took 157
|
|
905
|
+
* `import { defineConfig } from 'vite'` edges (#1719). Classic scripts,
|
|
906
|
+
* CommonJS, later `export { … }`, and ambient globals stay visible.
|
|
907
|
+
*
|
|
908
|
+
* Same-file candidates are always visible. Applied by ReferenceResolver to
|
|
909
|
+
* the target the whole name-matching pipeline settled on, so a rejection ends
|
|
910
|
+
* the reference unresolved: declining inside matchByExactName instead let the
|
|
911
|
+
* ref fall through to matchFuzzy, which then committed to a same-language
|
|
912
|
+
* namesake the ranking had passed over — eight such edges on one tree, all
|
|
913
|
+
* onto a local `const fail = …` arrow the graph does not hold. matchFuzzy
|
|
914
|
+
* checks its own survivor as well, since nothing runs after it.
|
|
915
|
+
*/
|
|
916
|
+
function isVisibleAcrossFiles(candidate, ref, context) {
|
|
917
|
+
if (candidate.filePath === ref.filePath)
|
|
918
|
+
return true;
|
|
919
|
+
const lang = candidate.language;
|
|
920
|
+
if (lang === 'c' || lang === 'cpp') {
|
|
921
|
+
return (candidate.kind !== 'function' ||
|
|
922
|
+
!C_SOURCE_EXT.test(candidate.filePath) ||
|
|
923
|
+
!isStaticCFunction(candidate, context));
|
|
924
|
+
}
|
|
925
|
+
if (lang === 'go') {
|
|
926
|
+
// By the name's first letter, not the extractor's flag: the flag is unset
|
|
927
|
+
// for every Go method, exported or not.
|
|
928
|
+
return /^[A-Z]/.test(candidate.name) || path.posix.dirname(candidate.filePath) === path.posix.dirname(ref.filePath);
|
|
929
|
+
}
|
|
930
|
+
if (lang === 'rust') {
|
|
931
|
+
if (candidate.visibility !== 'private')
|
|
932
|
+
return true;
|
|
933
|
+
if (isRustTraitImplMethod(candidate, context))
|
|
934
|
+
return true;
|
|
935
|
+
const owner = rustModuleDir(candidate.filePath);
|
|
936
|
+
return ref.filePath.startsWith(owner + '/');
|
|
937
|
+
}
|
|
938
|
+
if (PRIVATE_IS_FILE_LOCAL.has(lang))
|
|
939
|
+
return candidate.visibility !== 'private';
|
|
940
|
+
// JS/TS/ArkTS sealed modules + markdown/JSON call-target guards (#1719).
|
|
941
|
+
// Same predicate matchByExactName / matchFuzzy apply to their survivors so a
|
|
942
|
+
// rejection here cannot fall through to a promoted runner-up.
|
|
943
|
+
return isCrossFileReachable(candidate, ref, context);
|
|
944
|
+
}
|
|
945
|
+
const JS_FAMILY = new Set(['typescript', 'tsx', 'javascript', 'jsx']);
|
|
946
|
+
/**
|
|
947
|
+
* Whether a JS/TS `calls` ref is a RECEIVER-LESS call — `serialize(x)`, not
|
|
948
|
+
* `this.serialize(x)` / `obj.serialize(x)`. The extractor emits `this.m()`
|
|
949
|
+
* and `super.m()` under the bare method name, so the receiver is read back
|
|
950
|
+
* from the call site's own line: the text at the ref's column is the call
|
|
951
|
+
* expression, and it starts with the name itself only when nothing precedes
|
|
952
|
+
* it. In JS/TS a bare call can never bind to a class method (methods need a
|
|
953
|
+
* receiver), so a `method` node is not a candidate for it (#1714) — the
|
|
954
|
+
* enclosing method itself least of all, which the same-file proximity term
|
|
955
|
+
* used to pick over the module-scope function the call actually means.
|
|
956
|
+
*/
|
|
957
|
+
function isBareJsCall(ref, context) {
|
|
958
|
+
return JS_FAMILY.has(ref.language) && isReceiverLessCall(ref, context);
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Whether a Go `calls` ref is receiver-less — `relogin(ctx)`, not
|
|
962
|
+
* `l.relogin(ctx)`. A Go method is only reachable through a value or a method
|
|
963
|
+
* expression, so a bare call (a func parameter, a local func value, a
|
|
964
|
+
* package-level function) is never a method, in its own package or in one the
|
|
965
|
+
* file does not import (#1857). Read from the source line like the JS/TS
|
|
966
|
+
* check, because `pkg.Factory().Method()` reaches the resolver as a bare
|
|
967
|
+
* `Method` ref too.
|
|
968
|
+
*/
|
|
969
|
+
function isBareGoCall(ref, context) {
|
|
970
|
+
return ref.language === 'go' && isReceiverLessCall(ref, context);
|
|
971
|
+
}
|
|
972
|
+
function isReceiverLessCall(ref, context) {
|
|
973
|
+
if (ref.referenceKind !== 'calls')
|
|
974
|
+
return false;
|
|
975
|
+
if (ref.referenceName.includes('.'))
|
|
976
|
+
return false;
|
|
977
|
+
const line = context.getFileLines?.(ref.filePath)?.[ref.line - 1]
|
|
978
|
+
?? context.readFile(ref.filePath)?.split('\n')[ref.line - 1];
|
|
979
|
+
if (line === undefined)
|
|
980
|
+
return false;
|
|
981
|
+
// `^<name>\s*[(<]` at the call's column, without compiling a pattern per call.
|
|
982
|
+
if (!line.startsWith(ref.referenceName, ref.column))
|
|
983
|
+
return false;
|
|
984
|
+
CALL_OPENER.lastIndex = ref.column + ref.referenceName.length;
|
|
985
|
+
if (!CALL_OPENER.test(line))
|
|
986
|
+
return false;
|
|
987
|
+
// Nothing but whitespace, an operator or an opener may precede a bare call:
|
|
988
|
+
// read the text before the column backwards, past trailing whitespace,
|
|
989
|
+
// instead of end-anchoring a pattern that scans the prefix from its start.
|
|
990
|
+
let end = Math.min(ref.column, line.length);
|
|
991
|
+
while (end > 0 && WHITESPACE.test(line[end - 1]))
|
|
992
|
+
end--;
|
|
993
|
+
if (end === 0 || !RECEIVER_TAIL_CHAR.test(line[end - 1]))
|
|
994
|
+
return true;
|
|
995
|
+
let start = end;
|
|
996
|
+
while (start > 0 && WORD_CHAR.test(line[start - 1]))
|
|
997
|
+
start--;
|
|
998
|
+
return BARE_CALL_KEYWORDS.has(line.slice(start, end));
|
|
999
|
+
}
|
|
1000
|
+
/** `\s*[(<]` from a given index (sticky). */
|
|
1001
|
+
const CALL_OPENER = /\s*[(<]/y;
|
|
1002
|
+
const WHITESPACE = /\s/;
|
|
1003
|
+
const WORD_CHAR = /\w/;
|
|
1004
|
+
/** A character that ends a receiver: `.`, a word character, `$`, `]` or `)`. */
|
|
1005
|
+
const RECEIVER_TAIL_CHAR = /[.\w$\])]/;
|
|
1006
|
+
/** Keywords after which a name starts an expression, so the call has no receiver. */
|
|
1007
|
+
const BARE_CALL_KEYWORDS = new Set([
|
|
1008
|
+
'return', 'await', 'yield', 'typeof', 'void', 'new', 'else', 'case', 'throw', 'in', 'of', 'instanceof', 'go', 'defer',
|
|
1009
|
+
]);
|
|
1010
|
+
/** Per-context memo: `file\0name` → "the file binds this name locally". */
|
|
1011
|
+
const LOCAL_BINDING_MEMO = new WeakMap();
|
|
1012
|
+
const LOCAL_BINDING_SITES = new WeakMap();
|
|
1013
|
+
const LOCAL_BINDING_SITES_KEEP = 16;
|
|
1014
|
+
const VAR_DECL_SITE = /\b(?:const|let|var)\s/g;
|
|
1015
|
+
const FN_DECL_SITE = /\b(?:function|class)\s/g;
|
|
1016
|
+
function localBindingSites(filePath, source, context) {
|
|
1017
|
+
let cache = LOCAL_BINDING_SITES.get(context);
|
|
1018
|
+
if (!cache) {
|
|
1019
|
+
cache = new Map();
|
|
1020
|
+
LOCAL_BINDING_SITES.set(context, cache);
|
|
1021
|
+
}
|
|
1022
|
+
let sites = cache.get(filePath);
|
|
1023
|
+
if (!sites) {
|
|
1024
|
+
const offsets = (re) => Array.from(source.matchAll(re), (m) => m.index);
|
|
1025
|
+
const arrows = [];
|
|
1026
|
+
for (let a = source.indexOf('=>'); a !== -1; a = source.indexOf('=>', a + 2))
|
|
1027
|
+
arrows.push(a);
|
|
1028
|
+
sites = { varDecls: offsets(VAR_DECL_SITE), fnDecls: offsets(FN_DECL_SITE), arrows };
|
|
1029
|
+
if (cache.size >= LOCAL_BINDING_SITES_KEEP)
|
|
1030
|
+
cache.delete(cache.keys().next().value);
|
|
1031
|
+
cache.set(filePath, sites);
|
|
1032
|
+
}
|
|
1033
|
+
return sites;
|
|
1034
|
+
}
|
|
1035
|
+
/** Sticky binding patterns by name — the same names recur file after file. */
|
|
1036
|
+
const LOCAL_BINDING_PATTERNS = new Map();
|
|
1037
|
+
const LOCAL_BINDING_PATTERNS_CAP = 4096;
|
|
1038
|
+
const JS_BINDING_NAME = /^[\w$]+$/;
|
|
1039
|
+
const ARROW_HEAD_CHAR = /[\w$.]/;
|
|
1040
|
+
const IMPORT_BINDING_VALUE = /^\s*(?:await\s+)?(?:require|import)\s*\(/;
|
|
1041
|
+
function localBindingPatterns(name, flags) {
|
|
1042
|
+
const n = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1043
|
+
return {
|
|
1044
|
+
// `const { name } = require('./m')` / `= await import('./m')` binds an IMPORT,
|
|
1045
|
+
// not a shadow: the symbol lives in the other file and the call means it.
|
|
1046
|
+
decl: new RegExp('\\b(?:const|let|var)\\s+(?:' + n + '\\b|[{\\[][^;=]*?\\b' + n + '\\b[^;=]*?[}\\]])\\s*(?:=\\s*([^;\\n]*))?', flags),
|
|
1047
|
+
fn: new RegExp('\\b(?:function|class)\\s+' + n + '\\b', flags),
|
|
1048
|
+
// a parameter: every token before the name in the list is itself a
|
|
1049
|
+
// parameter (identifier, optional type, optional default) — so a string
|
|
1050
|
+
// argument containing the word cannot match.
|
|
1051
|
+
// Each earlier parameter has exactly one parse: its first non-space
|
|
1052
|
+
// character after the identifier picks the type (`?`/`:`), default (`=`)
|
|
1053
|
+
// or bare alternative. Written as `(type)?(default)?\s*`, the same
|
|
1054
|
+
// strings split several ways per parameter, and a failing search
|
|
1055
|
+
// backtracked through every combination — 30-40s per name on a vscode
|
|
1056
|
+
// test file whose helper takes nine `name: T = value` parameters.
|
|
1057
|
+
param: new RegExp('\\(\\s*(?:(?:\\.\\.\\.)?[\\w$]+(?:\\s*(?:\\?\\s*)?:[^,()]+|\\s*=[^,()]+|\\s*),\\s*)*' +
|
|
1058
|
+
n + '\\b(?:\\s*\\??\\s*:[^,()]*)?(?:\\s*=[^,()]*)?(?:\\s*,\\s*[^()]*)?\\)\\s*(?::[^=;{]*)?(?:=>|\\{)', flags),
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Whether a JS/TS file binds `name` itself — as a `const`/`let`/`var`/
|
|
1063
|
+
* `function`/`class` declaration (destructuring included) or as a parameter
|
|
1064
|
+
* of a function or arrow. Such a binding shadows every same-named symbol in
|
|
1065
|
+
* other files, so a bare call to it has no cross-file candidate: the
|
|
1066
|
+
* `resolve` of `new Promise((resolve, reject) => …)`, a spec's
|
|
1067
|
+
* `const transform = await makeTransform()`, a factory's `const now =
|
|
1068
|
+
* options.now || (() => new Date())`. None of these is a node the graph
|
|
1069
|
+
* holds (a parameter, a const bound to a call result), so without this the
|
|
1070
|
+
* matcher hands the call to whichever other file defines the name — and
|
|
1071
|
+
* once methods stop being candidates for a bare call (#1714), the function
|
|
1072
|
+
* that was out-ranked steps in. Read from source, memoised per file+name.
|
|
1073
|
+
*/
|
|
1074
|
+
function isLocallyBoundJsName(name, filePath, context) {
|
|
1075
|
+
let memo = LOCAL_BINDING_MEMO.get(context);
|
|
1076
|
+
if (!memo) {
|
|
1077
|
+
memo = new Map();
|
|
1078
|
+
LOCAL_BINDING_MEMO.set(context, memo);
|
|
1079
|
+
}
|
|
1080
|
+
const key = filePath + '\0' + name;
|
|
1081
|
+
const hit = memo.get(key);
|
|
1082
|
+
if (hit !== undefined)
|
|
1083
|
+
return hit;
|
|
1084
|
+
const source = context.readFile(filePath) ?? '';
|
|
1085
|
+
const bound = JS_BINDING_NAME.test(name)
|
|
1086
|
+
? bindsAtSites(source, name, localBindingSites(filePath, source, context))
|
|
1087
|
+
: bindsAnywhere(source, name);
|
|
1088
|
+
memo.set(key, bound);
|
|
1089
|
+
return bound;
|
|
1090
|
+
}
|
|
1091
|
+
/** isLocallyBoundJsName's patterns, searched through the whole source. */
|
|
1092
|
+
function bindsAnywhere(source, name) {
|
|
1093
|
+
const { decl, fn, param } = localBindingPatterns(name, 'g');
|
|
1094
|
+
for (const m of source.matchAll(decl)) {
|
|
1095
|
+
if (!IMPORT_BINDING_VALUE.test(m[1] ?? ''))
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
const n = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1099
|
+
return fn.test(source) || param.test(source) || new RegExp('(?:^|[^\\w$.])' + n + '\\s*=>').test(source);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* bindsAnywhere for a plain identifier, tried only where a match can start:
|
|
1103
|
+
* a declaration at its keyword (in order, resuming past each match exactly as
|
|
1104
|
+
* the global search does), a parameter at the `(` its list opens with — the
|
|
1105
|
+
* last `(` before an occurrence of the name, with no `)` between, since no
|
|
1106
|
+
* earlier parameter can hold a parenthesis — and `name =>` at each arrow.
|
|
1107
|
+
*/
|
|
1108
|
+
function bindsAtSites(source, name, sites) {
|
|
1109
|
+
let patterns = LOCAL_BINDING_PATTERNS.get(name);
|
|
1110
|
+
if (!patterns) {
|
|
1111
|
+
patterns = localBindingPatterns(name, 'y');
|
|
1112
|
+
if (LOCAL_BINDING_PATTERNS.size >= LOCAL_BINDING_PATTERNS_CAP) {
|
|
1113
|
+
LOCAL_BINDING_PATTERNS.delete(LOCAL_BINDING_PATTERNS.keys().next().value);
|
|
1114
|
+
}
|
|
1115
|
+
LOCAL_BINDING_PATTERNS.set(name, patterns);
|
|
1116
|
+
}
|
|
1117
|
+
const { decl, fn, param } = patterns;
|
|
1118
|
+
let from = 0;
|
|
1119
|
+
for (const at of sites.varDecls) {
|
|
1120
|
+
if (at < from)
|
|
1121
|
+
continue;
|
|
1122
|
+
decl.lastIndex = at;
|
|
1123
|
+
const m = decl.exec(source);
|
|
1124
|
+
if (!m)
|
|
1125
|
+
continue;
|
|
1126
|
+
from = at + m[0].length;
|
|
1127
|
+
if (!IMPORT_BINDING_VALUE.test(m[1] ?? ''))
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
for (const at of sites.fnDecls) {
|
|
1131
|
+
fn.lastIndex = at;
|
|
1132
|
+
if (fn.test(source))
|
|
1133
|
+
return true;
|
|
1134
|
+
}
|
|
1135
|
+
let tried = -1;
|
|
1136
|
+
for (let at = source.indexOf(name); at !== -1; at = source.indexOf(name, at + 1)) {
|
|
1137
|
+
const open = at > 0 ? source.lastIndexOf('(', at - 1) : -1;
|
|
1138
|
+
if (open < 0 || open === tried || source.lastIndexOf(')', at - 1) > open)
|
|
1139
|
+
continue;
|
|
1140
|
+
tried = open;
|
|
1141
|
+
param.lastIndex = open;
|
|
1142
|
+
if (param.test(source))
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1145
|
+
// `name =>`: the name ends where the whitespace before the arrow starts.
|
|
1146
|
+
for (const arrow of sites.arrows) {
|
|
1147
|
+
let end = arrow;
|
|
1148
|
+
while (end > 0 && WHITESPACE.test(source[end - 1]))
|
|
1149
|
+
end--;
|
|
1150
|
+
const start = end - name.length;
|
|
1151
|
+
if (start >= 0 && source.startsWith(name, start) && (start === 0 || !ARROW_HEAD_CHAR.test(source[start - 1]))) {
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
return false;
|
|
1156
|
+
}
|
|
364
1157
|
/**
|
|
365
1158
|
* Try to resolve a reference by exact name match
|
|
366
1159
|
*/
|
|
@@ -374,15 +1167,62 @@ function matchByExactName(ref, context) {
|
|
|
374
1167
|
// unresolved import refs each scored K same-named import candidates through
|
|
375
1168
|
// findBestMatch — O(K²) per package, the dominant cost of "Resolving refs" on
|
|
376
1169
|
// large import-heavy (front-end + back-end) repos (#915).
|
|
377
|
-
const
|
|
378
|
-
|
|
1170
|
+
const bareJs = isBareJsCall(ref, context);
|
|
1171
|
+
const bareGo = isBareGoCall(ref, context);
|
|
1172
|
+
if (bareJs) {
|
|
1173
|
+
const storeAction = matchJsStoreBindingCall(ref, context);
|
|
1174
|
+
if (storeAction)
|
|
1175
|
+
return storeAction;
|
|
1176
|
+
}
|
|
1177
|
+
// Every rule below judges one candidate on its own, so they run as ONE pass,
|
|
1178
|
+
// the kind/language checks before the ones that read source: a common name
|
|
1179
|
+
// has thousands of same-named nodes, and a chain of filters copied that
|
|
1180
|
+
// list once per rule for every reference.
|
|
1181
|
+
const valueRef = ref.referenceKind === 'references' || ref.referenceKind === 'function_ref';
|
|
1182
|
+
const importRef = ref.referenceKind === 'imports';
|
|
1183
|
+
const inheritanceRef = (0, types_1.isInheritanceRef)(ref);
|
|
1184
|
+
const sameName = context.getNodesByName(ref.referenceName);
|
|
1185
|
+
// `NAME(...)` where NAME is a function-like macro somewhere in the project is
|
|
1186
|
+
// an expansion or a call to a same-named function — never the macro itself
|
|
1187
|
+
// (#1839), and never a type that happens to share the name (#2070: expat's
|
|
1188
|
+
// `PREFIX(scanRef)(…)` bound to an unrelated `struct PREFIX`). Keep
|
|
1189
|
+
// upstream's language gate on the chosen result.
|
|
1190
|
+
const cMacroCall = ref.referenceKind === 'calls' && (ref.language === 'c' || ref.language === 'cpp') &&
|
|
1191
|
+
sameName.some((n) => n.kind === 'constant' && types_1.CPP_DEFINE_SIGNATURE.test(n.signature ?? ''));
|
|
1192
|
+
const candidates = sameName.filter((n) => !(cMacroCall && n.kind !== 'function' && n.kind !== 'method') &&
|
|
1193
|
+
// Type/value references retain same-family eligibility: a native namesake
|
|
1194
|
+
// must not hide the actual web type. Calls still gate only the winner.
|
|
1195
|
+
(!valueRef || sameLanguageFamily(n.language, ref.language)) &&
|
|
1196
|
+
n.kind !== 'import' &&
|
|
1197
|
+
// A receiver-less JS/TS or Go call cannot reach a method (#1714, #1857).
|
|
1198
|
+
!((bareJs || bareGo) && n.kind === 'method') &&
|
|
1199
|
+
// An `extends`/`implements` ref names a supertype, so anything that can't
|
|
1200
|
+
// BE one is not a candidate at all. This is eligibility, not
|
|
1201
|
+
// ranking: kind is only a scoring bonus below (and none is awarded for
|
|
1202
|
+
// inheritance refs), so without this a same-named `enum_member` outranked
|
|
1203
|
+
// the real `trait`, and as the sole candidate was adopted outright by the
|
|
1204
|
+
// single-match shortcut. Restricting the pool BEFORE ranking lets the
|
|
1205
|
+
// legitimate supertype win instead of merely dropping the false edge.
|
|
1206
|
+
(!inheritanceRef || (0, types_1.isSupertypeTarget)(n)) &&
|
|
1207
|
+
// Likewise for `imports`: a member that only exists inside a type is not
|
|
1208
|
+
// importable, so it is not a candidate. Without this a `path`/`id`/`url`
|
|
1209
|
+
// import resolved to some interface's same-named property.
|
|
1210
|
+
(!importRef || (0, types_1.isImportableKind)(n.kind)) &&
|
|
379
1211
|
// Nested locals are only reachable from inside their container (#1230).
|
|
380
|
-
|
|
1212
|
+
isLexicallyReachable(n, ref, context) &&
|
|
1213
|
+
// Preserve import ranking; calls reject the winner without promoting another.
|
|
1214
|
+
(!importRef || n.filePath === ref.filePath ||
|
|
1215
|
+
!ESM_FAMILY.has(n.language) || !isSealedModule(n.filePath, context)) &&
|
|
1216
|
+
// A name the file binds itself (a parameter, a const) shadows every other
|
|
1217
|
+
// file's symbol of that name, so a bare call has no cross-file candidate.
|
|
1218
|
+
!(bareJs && n.filePath !== ref.filePath && isLocallyBoundJsName(ref.referenceName, ref.filePath, context)));
|
|
381
1219
|
if (candidates.length === 0) {
|
|
382
1220
|
return null;
|
|
383
1221
|
}
|
|
384
1222
|
// If only one match, use it — but penalize cross-language matches
|
|
385
1223
|
if (candidates.length === 1) {
|
|
1224
|
+
if (!isCrossFileReachable(candidates[0], ref, context))
|
|
1225
|
+
return null;
|
|
386
1226
|
const isCrossLanguage = candidates[0].language !== ref.language;
|
|
387
1227
|
return {
|
|
388
1228
|
original: ref,
|
|
@@ -401,7 +1241,7 @@ function matchByExactName(ref, context) {
|
|
|
401
1241
|
}
|
|
402
1242
|
// Multiple matches - try to narrow down
|
|
403
1243
|
const bestMatch = findBestMatch(ref, candidates, context);
|
|
404
|
-
if (bestMatch) {
|
|
1244
|
+
if (bestMatch && isCrossFileReachable(bestMatch, ref, context)) {
|
|
405
1245
|
// Lower confidence when the match is from a distant/unrelated module
|
|
406
1246
|
const proximity = computePathProximity(ref.filePath, bestMatch.filePath);
|
|
407
1247
|
const confidence = proximity >= 30 ? 0.7 : 0.4;
|
|
@@ -456,6 +1296,32 @@ function matchByQualifiedName(ref, context) {
|
|
|
456
1296
|
};
|
|
457
1297
|
}
|
|
458
1298
|
}
|
|
1299
|
+
// Erlang qualified refs (#1610): every erlang function's qualifiedName
|
|
1300
|
+
// carries its arity (`mod::f/2`), and refs carry the call-site arity when it
|
|
1301
|
+
// is statically known.
|
|
1302
|
+
if (ref.language === 'erlang' && ref.referenceName.includes('::')) {
|
|
1303
|
+
// A ref WITH arity that missed the exact lookup names an arity that isn't
|
|
1304
|
+
// defined (or a module out of repo). Never fall through to the partial
|
|
1305
|
+
// match — its "last segment" would be the arity digits — and never settle
|
|
1306
|
+
// for a sibling arity: silent beats wrong.
|
|
1307
|
+
if (/\/\d{1,3}$/.test(ref.referenceName))
|
|
1308
|
+
return null;
|
|
1309
|
+
// An arity-LESS qualified ref (dynamic MFA whose args list wasn't a
|
|
1310
|
+
// static literal): resolve only when the module defines exactly ONE arity
|
|
1311
|
+
// of that function; several arities with no signal is a guess.
|
|
1312
|
+
const base = ref.referenceName.slice(ref.referenceName.lastIndexOf('::') + 2);
|
|
1313
|
+
const prefix = `${ref.referenceName}/`;
|
|
1314
|
+
const arityCands = keepForRef(context.getNodesByName(base)).filter((n) => n.qualifiedName.startsWith(prefix) && /^\d{1,3}$/.test(n.qualifiedName.slice(prefix.length)));
|
|
1315
|
+
if (arityCands.length === 1) {
|
|
1316
|
+
return {
|
|
1317
|
+
original: ref,
|
|
1318
|
+
targetNodeId: arityCands[0].id,
|
|
1319
|
+
confidence: 0.85,
|
|
1320
|
+
resolvedBy: 'qualified-name',
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
459
1325
|
// Try partial qualified name match — again preferring the call site's own
|
|
460
1326
|
// file when more than one symbol's qualifiedName ends with the reference.
|
|
461
1327
|
const parts = ref.referenceName.split(/[:.]/);
|
|
@@ -475,6 +1341,11 @@ function matchByQualifiedName(ref, context) {
|
|
|
475
1341
|
}
|
|
476
1342
|
return null;
|
|
477
1343
|
}
|
|
1344
|
+
/** A node a `Receiver.method()` call can name as the method's owning type. */
|
|
1345
|
+
function isMethodOwnerKind(n) {
|
|
1346
|
+
return n.kind === 'class' || n.kind === 'struct' || n.kind === 'union' || n.kind === 'interface' ||
|
|
1347
|
+
(n.language === 'scala' && n.kind === 'module');
|
|
1348
|
+
}
|
|
478
1349
|
/**
|
|
479
1350
|
* When a symbol name is ambiguous across files, prefer the candidate(s) declared
|
|
480
1351
|
* in the call site's own file, keeping the rest in their original order (#1079).
|
|
@@ -496,6 +1367,223 @@ function preferCallSiteFile(nodes, callSiteFile) {
|
|
|
496
1367
|
}
|
|
497
1368
|
return same.length ? [...same, ...other] : nodes;
|
|
498
1369
|
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Languages whose object literals declare callable members — `export const
|
|
1372
|
+
* api = { call() {…}, get: () => {…} }` used as a namespace (#1573).
|
|
1373
|
+
*/
|
|
1374
|
+
const OBJECT_LITERAL_LANGUAGES = new Set(['typescript', 'tsx', 'javascript', 'jsx', 'arkts']);
|
|
1375
|
+
/** True when `inner`'s source range lies within `outer`'s (lines, then columns on a shared line). */
|
|
1376
|
+
function rangeWithin(inner, outer) {
|
|
1377
|
+
const innerEnd = inner.endLine ?? inner.startLine;
|
|
1378
|
+
const outerEnd = outer.endLine ?? outer.startLine;
|
|
1379
|
+
if (inner.startLine < outer.startLine || innerEnd > outerEnd)
|
|
1380
|
+
return false;
|
|
1381
|
+
if (inner.startLine === outer.startLine && inner.startColumn < outer.startColumn)
|
|
1382
|
+
return false;
|
|
1383
|
+
if (innerEnd === outerEnd && inner.endColumn > outer.endColumn)
|
|
1384
|
+
return false;
|
|
1385
|
+
return true;
|
|
1386
|
+
}
|
|
1387
|
+
function sameRange(a, b) {
|
|
1388
|
+
return (a.startLine === b.startLine &&
|
|
1389
|
+
a.startColumn === b.startColumn &&
|
|
1390
|
+
(a.endLine ?? a.startLine) === (b.endLine ?? b.startLine) &&
|
|
1391
|
+
a.endColumn === b.endColumn);
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Resolve `container.member` where `container` is a VALUE holding an object
|
|
1395
|
+
* literal — `export const api = { call() {…}, get: () => {…} }` used as the
|
|
1396
|
+
* module's namespace (#1573). The members are extracted as plain functions
|
|
1397
|
+
* with BARE qualified names inside the constant's source extent (there is no
|
|
1398
|
+
* `api::call`), so neither the `Container::member` lookup the class-shaped
|
|
1399
|
+
* kinds use (#825) nor the declared-type inference for singleton instances
|
|
1400
|
+
* (#1292) can reach them, and every such call resolved to nothing — or, via
|
|
1401
|
+
* an import, to the constant itself. This looks the member up by CONTAINMENT:
|
|
1402
|
+
* a node named `member` whose range lies inside the container's, in the
|
|
1403
|
+
* container's own file. A helper declared inside a member's body is not a
|
|
1404
|
+
* member and is skipped; nothing else in the file can donate a match. Calls
|
|
1405
|
+
* take callable kinds only; other references accept value members too.
|
|
1406
|
+
*/
|
|
1407
|
+
function resolveObjectLiteralMember(container, member, ref, context, confidence, resolvedBy) {
|
|
1408
|
+
if (container.kind !== 'constant' && container.kind !== 'variable')
|
|
1409
|
+
return null;
|
|
1410
|
+
if (!OBJECT_LITERAL_LANGUAGES.has(container.language))
|
|
1411
|
+
return null;
|
|
1412
|
+
if (!sameLanguageFamily(container.language, ref.language))
|
|
1413
|
+
return null;
|
|
1414
|
+
const inFile = context.getNodesInFile(container.filePath);
|
|
1415
|
+
const callable = (n) => n.kind === 'function' || n.kind === 'method';
|
|
1416
|
+
const valueMember = (n) => callable(n) || n.kind === 'property' || n.kind === 'variable' || n.kind === 'constant';
|
|
1417
|
+
const accepts = ref.referenceKind === 'calls' ? callable : valueMember;
|
|
1418
|
+
const inside = inFile.filter((n) => n.id !== container.id && rangeWithin(n, container));
|
|
1419
|
+
const property = objectLiteralProperty(container, member, context);
|
|
1420
|
+
if (property === null || property?.binding)
|
|
1421
|
+
return null;
|
|
1422
|
+
let candidates = inside.filter((n) => n.name === member && accepts(n) && (!property || property.contains(n)));
|
|
1423
|
+
if (candidates.length === 0)
|
|
1424
|
+
return null;
|
|
1425
|
+
// Drop a candidate nested inside ANOTHER callable's body within the literal
|
|
1426
|
+
// (`{ run() { const call = () => {}; } }` — `call` is `run`'s local, not a
|
|
1427
|
+
// member). Strict containment: an identically-ranged sibling node for the
|
|
1428
|
+
// same member (a property node over an arrow function) is not a body.
|
|
1429
|
+
const bodies = inside.filter(callable);
|
|
1430
|
+
candidates = candidates.filter((c) => !bodies.some((b) => b.id !== c.id && !sameRange(b, c) && rangeWithin(c, b)));
|
|
1431
|
+
if (candidates.length === 0)
|
|
1432
|
+
return null;
|
|
1433
|
+
// Several survivors (a property AND a function for one arrow member, say):
|
|
1434
|
+
// a callable first, then the earliest in source order.
|
|
1435
|
+
candidates.sort((a, b) => {
|
|
1436
|
+
const ca = callable(a) ? 0 : 1;
|
|
1437
|
+
const cb = callable(b) ? 0 : 1;
|
|
1438
|
+
if (ca !== cb)
|
|
1439
|
+
return ca - cb;
|
|
1440
|
+
return a.startLine - b.startLine || a.startColumn - b.startColumn;
|
|
1441
|
+
});
|
|
1442
|
+
return {
|
|
1443
|
+
original: ref,
|
|
1444
|
+
targetNodeId: candidates[0].id,
|
|
1445
|
+
confidence,
|
|
1446
|
+
resolvedBy,
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* The binding an object-literal member names when it is a shorthand property
|
|
1451
|
+
* (`{ getUser }`) or a pair whose value is a bare identifier (`{ getUser:
|
|
1452
|
+
* fetchUser }`) — the usual way an API module assembles its namespace from
|
|
1453
|
+
* standalone functions (#1932). Only the literal's own members count: a member
|
|
1454
|
+
* of a nested object, a word inside a member's body, a comment or a string
|
|
1455
|
+
* never donates one. Null when the member is absent, or when its value is not
|
|
1456
|
+
* a bare identifier (`{ fn: 1 }` names nothing).
|
|
1457
|
+
*/
|
|
1458
|
+
function objectLiteralMemberBinding(container, member, context) {
|
|
1459
|
+
return objectLiteralProperty(container, member, context)?.binding ?? null;
|
|
1460
|
+
}
|
|
1461
|
+
/** The last own property wins; an unknown spread/computed key invalidates earlier evidence. */
|
|
1462
|
+
function objectLiteralProperty(container, member, context) {
|
|
1463
|
+
const lines = context.getFileLines?.(container.filePath) ?? context.readFile(container.filePath)?.split('\n');
|
|
1464
|
+
if (!lines)
|
|
1465
|
+
return undefined;
|
|
1466
|
+
const extentLines = lines.slice(container.startLine - 1, container.endLine);
|
|
1467
|
+
if (!extentLines.length)
|
|
1468
|
+
return undefined;
|
|
1469
|
+
extentLines[extentLines.length - 1] = extentLines[extentLines.length - 1].slice(0, container.endColumn);
|
|
1470
|
+
extentLines[0] = extentLines[0].slice(container.startColumn);
|
|
1471
|
+
const extent = (0, strip_comments_1.stripCommentsForRegex)(extentLines.join('\n'), 'typescript');
|
|
1472
|
+
const code = (0, strip_comments_1.blankStringContents)(extent);
|
|
1473
|
+
// Start at THIS declarator, including its columns, never a sibling on the same line.
|
|
1474
|
+
const open = /^[^=]*=\s*(?:(?:Object\.(?:freeze|seal)\s*)?\(\s*)*\{/.exec(code);
|
|
1475
|
+
if (!open)
|
|
1476
|
+
return undefined;
|
|
1477
|
+
const members = [];
|
|
1478
|
+
let depth = 0;
|
|
1479
|
+
let start = open[0].length;
|
|
1480
|
+
for (let i = start; i < code.length; i++) {
|
|
1481
|
+
const ch = code[i];
|
|
1482
|
+
if (ch === '{' || ch === '(' || ch === '[')
|
|
1483
|
+
depth++;
|
|
1484
|
+
else if (ch === ')' || ch === ']')
|
|
1485
|
+
depth--;
|
|
1486
|
+
else if (ch === '}') {
|
|
1487
|
+
if (depth === 0) {
|
|
1488
|
+
members.push({ start, end: i });
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
depth--;
|
|
1492
|
+
}
|
|
1493
|
+
else if (ch === ',' && depth === 0) {
|
|
1494
|
+
members.push({ start, end: i });
|
|
1495
|
+
start = i + 1;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
let selected = null;
|
|
1499
|
+
for (const part of members) {
|
|
1500
|
+
const text = extent.slice(part.start, part.end).trim();
|
|
1501
|
+
if (/^(?:\.\.\.|\[)/.test(text)) {
|
|
1502
|
+
selected = null;
|
|
1503
|
+
continue;
|
|
1504
|
+
}
|
|
1505
|
+
const key = /^(?:(?:async|get|set)\s+)?\*?\s*(?:([A-Za-z_$][\w$]*)|['"]([^'"\\]*)['"])(?=\s*(?:[:(<,=]|$))/.exec(text);
|
|
1506
|
+
if ((key?.[1] ?? key?.[2]) !== member)
|
|
1507
|
+
continue;
|
|
1508
|
+
const value = text.slice(key[0].length).trim();
|
|
1509
|
+
const binding = value === '' ? member : /^:\s*([A-Za-z_$][\w$]*)$/.exec(value)?.[1] ?? null;
|
|
1510
|
+
selected = { ...part, binding };
|
|
1511
|
+
}
|
|
1512
|
+
if (!selected)
|
|
1513
|
+
return null;
|
|
1514
|
+
const offset = (node) => {
|
|
1515
|
+
let result = node.startColumn - container.startColumn;
|
|
1516
|
+
for (let line = container.startLine; line < node.startLine; line++)
|
|
1517
|
+
result += lines[line - 1].length + 1;
|
|
1518
|
+
return result;
|
|
1519
|
+
};
|
|
1520
|
+
const property = selected;
|
|
1521
|
+
return { binding: property.binding, contains: (node) => offset(node) >= property.start && offset(node) < property.end };
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Shared lexical lookup for namespace-object aliases (#1932): `api.getUser()` where
|
|
1525
|
+
* `api` is `const api = { getUser }` (or `{ getUser: fetchUser }`) in the
|
|
1526
|
+
* object's own file. The member's function is declared OUTSIDE the literal, so
|
|
1527
|
+
* containment (`resolveObjectLiteralMember`) finds nothing. Follow the binding
|
|
1528
|
+
* the member names — a symbol of this file, else one of its imports — unless a
|
|
1529
|
+
* parameter or nearer declaration shadows that name where the literal is
|
|
1530
|
+
* written (the edge would then name the wrong function).
|
|
1531
|
+
*/
|
|
1532
|
+
function resolveObjectLiteralBinding(container, member, ref, context) {
|
|
1533
|
+
const binding = objectLiteralMemberBinding(container, member, context);
|
|
1534
|
+
if (!binding)
|
|
1535
|
+
return null;
|
|
1536
|
+
const at = { ...ref, filePath: container.filePath, language: container.language,
|
|
1537
|
+
fromNodeId: container.id, line: container.startLine, column: container.startColumn };
|
|
1538
|
+
const inFile = context.getNodesInFile(container.filePath);
|
|
1539
|
+
if (inFile.some((n) => (n.kind === 'function' || n.kind === 'method') &&
|
|
1540
|
+
rangeWithin(container, n) && n.signature &&
|
|
1541
|
+
hasParameterBinding(`${n.signature} {`, binding.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))))
|
|
1542
|
+
return null;
|
|
1543
|
+
const lines = context.getFileLines?.(container.filePath) ?? context.readFile(container.filePath)?.split('\n');
|
|
1544
|
+
if (!lines)
|
|
1545
|
+
return null;
|
|
1546
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(lines.join('\n'), 'typescript'));
|
|
1547
|
+
const offsets = [0];
|
|
1548
|
+
for (let i = 0; i < code.length; i++)
|
|
1549
|
+
if (code[i] === '\n')
|
|
1550
|
+
offsets.push(i + 1);
|
|
1551
|
+
const scopeAt = (node) => {
|
|
1552
|
+
const end = (offsets[node.startLine - 1] ?? code.length) + node.startColumn;
|
|
1553
|
+
const scope = [];
|
|
1554
|
+
for (let i = 0; i < end; i++) {
|
|
1555
|
+
if (code[i] === '{')
|
|
1556
|
+
scope.push(i);
|
|
1557
|
+
else if (code[i] === '}')
|
|
1558
|
+
scope.pop();
|
|
1559
|
+
}
|
|
1560
|
+
return scope;
|
|
1561
|
+
};
|
|
1562
|
+
const scope = scopeAt(container);
|
|
1563
|
+
const callable = (n) => n.kind === 'function' || n.kind === 'method' || n.kind === 'class';
|
|
1564
|
+
const accepts = ref.referenceKind === 'calls'
|
|
1565
|
+
? callable
|
|
1566
|
+
: (n) => callable(n) || n.kind === 'constant' || n.kind === 'variable' || n.kind === 'component';
|
|
1567
|
+
const locals = inFile
|
|
1568
|
+
.filter((n) => n.name === binding && n.id !== container.id &&
|
|
1569
|
+
['function', 'class', 'constant', 'variable', 'component'].includes(n.kind))
|
|
1570
|
+
.map((node) => ({ node, scope: scopeAt(node) }))
|
|
1571
|
+
.filter((entry) => entry.scope.every((position, i) => scope[i] === position))
|
|
1572
|
+
.sort((a, b) => b.scope.length - a.scope.length);
|
|
1573
|
+
// Select the lexical binding BEFORE checking callability: a nearer value
|
|
1574
|
+
// shadows an outer function even if that value cannot be called.
|
|
1575
|
+
const local = locals[0]?.node;
|
|
1576
|
+
if (local)
|
|
1577
|
+
return accepts(local)
|
|
1578
|
+
? { original: ref, targetNodeId: local.id, confidence: 0.85, resolvedBy: 'instance-method' }
|
|
1579
|
+
: null;
|
|
1580
|
+
const imported = context.resolveImport?.({ ...at, referenceName: binding });
|
|
1581
|
+
const target = imported ? context.getNodeById?.(imported.targetNodeId) : null;
|
|
1582
|
+
if (target && accepts(target)) {
|
|
1583
|
+
return { original: ref, targetNodeId: target.id, confidence: 0.85, resolvedBy: 'instance-method' };
|
|
1584
|
+
}
|
|
1585
|
+
return null;
|
|
1586
|
+
}
|
|
499
1587
|
// Exported for the precedence unit tests (#1079): they assert the
|
|
500
1588
|
// preferredFqn → same-file → matches[0] ordering directly.
|
|
501
1589
|
function resolveMethodOnType(typeName, methodName, ref, context, confidence, resolvedBy,
|
|
@@ -531,7 +1619,7 @@ depth = 0) {
|
|
|
531
1619
|
for (const m of methodCandidates) {
|
|
532
1620
|
if (m.kind !== 'method')
|
|
533
1621
|
continue;
|
|
534
|
-
if (m.language
|
|
1622
|
+
if (!sameLanguageFamily(m.language, ref.language))
|
|
535
1623
|
continue;
|
|
536
1624
|
const qn = m.qualifiedName;
|
|
537
1625
|
if (qn === want || qn.endsWith(`::${want}`)) {
|
|
@@ -586,6 +1674,8 @@ depth = 0) {
|
|
|
586
1674
|
// block, so Java/Kotlin import disambiguation — whose target is intentionally
|
|
587
1675
|
// in ANOTHER file (#314) — is unaffected: that block returns early whenever
|
|
588
1676
|
// an import FQN pins the class.
|
|
1677
|
+
if (ref.referenceKind === 'function_ref' && matches.length !== 1)
|
|
1678
|
+
return null;
|
|
589
1679
|
const ordered = preferCallSiteFile(matches, ref.filePath);
|
|
590
1680
|
return {
|
|
591
1681
|
original: ref,
|
|
@@ -725,12 +1815,12 @@ function lookupCalleeReturnType(callee, ref, context) {
|
|
|
725
1815
|
}
|
|
726
1816
|
return candidates.find((n) => n.kind === 'function')?.returnType ?? null;
|
|
727
1817
|
}
|
|
728
|
-
/** Does the graph contain
|
|
1818
|
+
/** Does the graph contain an aggregate type named `name`'s last segment? */
|
|
729
1819
|
function cppClassExists(name, ref, context) {
|
|
730
1820
|
const last = cppLastSegment(name);
|
|
731
1821
|
return context
|
|
732
1822
|
.getNodesByName(last)
|
|
733
|
-
.some((n) => (n.kind === 'class' || n.kind === 'struct') && n.language === ref.language);
|
|
1823
|
+
.some((n) => (n.kind === 'class' || n.kind === 'struct' || n.kind === 'union') && n.language === ref.language);
|
|
734
1824
|
}
|
|
735
1825
|
/**
|
|
736
1826
|
* Infer the class produced by a C++ call/construction expression, using return
|
|
@@ -1054,6 +2144,8 @@ function normalizeInferredTypeName(raw) {
|
|
|
1054
2144
|
const PATTERN_MEMO = new Map();
|
|
1055
2145
|
const PATTERN_MEMO_CAP = 8192;
|
|
1056
2146
|
const INFER_SCAN_STATES = new WeakMap();
|
|
2147
|
+
const AWAITED_TYPE_MEMO = new WeakMap();
|
|
2148
|
+
const AWAITED_FILES = new WeakMap();
|
|
1057
2149
|
function getInferScanStates(context) {
|
|
1058
2150
|
let m = INFER_SCAN_STATES.get(context);
|
|
1059
2151
|
if (!m) {
|
|
@@ -1065,6 +2157,19 @@ function getInferScanStates(context) {
|
|
|
1065
2157
|
/** Drop the per-context scan states (see ReferenceResolver.clearCaches). */
|
|
1066
2158
|
function clearNameMatcherMemos(context) {
|
|
1067
2159
|
INFER_SCAN_STATES.delete(context);
|
|
2160
|
+
PYTHON_MEMBER_LINES.delete(context);
|
|
2161
|
+
AWAITED_TYPE_MEMO.delete(context);
|
|
2162
|
+
AWAITED_FILES.delete(context);
|
|
2163
|
+
C_STATIC_MEMO.delete(context);
|
|
2164
|
+
RUST_TRAIT_IMPL_MEMO.delete(context);
|
|
2165
|
+
SEALED_MODULES.delete(context);
|
|
2166
|
+
LOCAL_BINDING_MEMO.delete(context);
|
|
2167
|
+
LOCAL_BINDING_SITES.delete(context);
|
|
2168
|
+
SELECTOR_NAMES.delete(context);
|
|
2169
|
+
GET_STATE_FILES.delete(context);
|
|
2170
|
+
TS_FIELD_DECL_MEMO.delete(context);
|
|
2171
|
+
TS_CLASS_LINES.delete(context);
|
|
2172
|
+
TARGET_LANGUAGE.delete(context);
|
|
1068
2173
|
}
|
|
1069
2174
|
function memoPatterns(key, build) {
|
|
1070
2175
|
const hit = PATTERN_MEMO.get(key);
|
|
@@ -1103,6 +2208,12 @@ function buildLocalReceiverTypePatterns(language, r) {
|
|
|
1103
2208
|
case 'python':
|
|
1104
2209
|
return [
|
|
1105
2210
|
new RegExp(`\\b${r}\\b\\s*=\\s*([A-Z][\\w.]*)\\s*\\(`), // lg = Logger(...)
|
|
2211
|
+
// A quoted forward reference (`lg: "Logger"`, `lg: 'pkg.Logger'`) is the
|
|
2212
|
+
// same annotation — and what every file under `from __future__ import
|
|
2213
|
+
// annotations` or with a not-yet-defined class writes. The unquoted
|
|
2214
|
+
// pattern below stopped at the quote and read no type at all, so the
|
|
2215
|
+
// call produced no edge (#1684). Tried first: it is the stricter shape.
|
|
2216
|
+
new RegExp(`\\b${r}\\b\\s*:\\s*["']([A-Z][\\w.]*)["']`), // lg: "Logger"
|
|
1106
2217
|
new RegExp(`\\b${r}\\b\\s*:\\s*([A-Z][\\w.]*)`), // lg: Logger (PEP 526)
|
|
1107
2218
|
];
|
|
1108
2219
|
case 'java':
|
|
@@ -1399,6 +2510,191 @@ function inferLocalReceiverType(receiverName, ref, context) {
|
|
|
1399
2510
|
}
|
|
1400
2511
|
return null;
|
|
1401
2512
|
}
|
|
2513
|
+
/** Infer only a visible awaited binding and its actual local/imported callee.
|
|
2514
|
+
* The signature already carries the return annotation in both extractors, so
|
|
2515
|
+
* multiline declarations and neighboring declarations cannot donate a type.
|
|
2516
|
+
* `null` means no awaited evidence; a null NAME means an awaited receiver whose
|
|
2517
|
+
* type is unknown, which must not fall back to an unrelated method name. */
|
|
2518
|
+
function inferEsmAwaitedCallType(receiverName, ref, context) {
|
|
2519
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(receiverName))
|
|
2520
|
+
return null;
|
|
2521
|
+
let files = AWAITED_FILES.get(context);
|
|
2522
|
+
if (!files) {
|
|
2523
|
+
files = new Map();
|
|
2524
|
+
AWAITED_FILES.set(context, files);
|
|
2525
|
+
}
|
|
2526
|
+
let file = files.get(ref.filePath);
|
|
2527
|
+
if (file === undefined) {
|
|
2528
|
+
const source = context.readFile(ref.filePath) ?? '';
|
|
2529
|
+
file = null;
|
|
2530
|
+
// Raw eligibility is cheap; sanitize and index scopes only when a ref
|
|
2531
|
+
// actually uses one of these names. Comments cannot donate a binding:
|
|
2532
|
+
// the names are checked again after sanitizing on the first real lookup.
|
|
2533
|
+
const names = new Set([...source.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*await\s+[\w$]+\s*\(/g)].map(m => m[1]));
|
|
2534
|
+
if (names.size)
|
|
2535
|
+
file = { code: source, ready: false, names, offsets: [], scopes: [], declarations: new Map() };
|
|
2536
|
+
if (files.size >= 256)
|
|
2537
|
+
files.delete(files.keys().next().value);
|
|
2538
|
+
files.set(ref.filePath, file);
|
|
2539
|
+
}
|
|
2540
|
+
if (!file?.names.has(receiverName))
|
|
2541
|
+
return null;
|
|
2542
|
+
if (!file.ready) {
|
|
2543
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(file.code, 'typescript'));
|
|
2544
|
+
const names = new Set([...code.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*await\s+[\w$]+\s*\(/g)].map(m => m[1]));
|
|
2545
|
+
const offsets = [0];
|
|
2546
|
+
const scopes = [{ start: -1, end: code.length, parent: -1 }];
|
|
2547
|
+
const stack = [0];
|
|
2548
|
+
for (let i = 0; i < code.length; i++) {
|
|
2549
|
+
if (code[i] === '\n')
|
|
2550
|
+
offsets.push(i + 1);
|
|
2551
|
+
if (code[i] === '{') {
|
|
2552
|
+
scopes.push({ start: i, end: code.length, parent: stack[stack.length - 1] });
|
|
2553
|
+
stack.push(scopes.length - 1);
|
|
2554
|
+
}
|
|
2555
|
+
else if (code[i] === '}' && stack.length > 1)
|
|
2556
|
+
scopes[stack.pop()].end = i;
|
|
2557
|
+
}
|
|
2558
|
+
const declarations = new Map();
|
|
2559
|
+
for (const m of code.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*/g)) {
|
|
2560
|
+
if (!names.has(m[1]))
|
|
2561
|
+
continue;
|
|
2562
|
+
const entries = declarations.get(m[1]) ?? [];
|
|
2563
|
+
entries.push({ index: m.index, length: m[0].length });
|
|
2564
|
+
declarations.set(m[1], entries);
|
|
2565
|
+
}
|
|
2566
|
+
Object.assign(file, { code, ready: true, names, offsets, scopes, declarations });
|
|
2567
|
+
if (!names.has(receiverName))
|
|
2568
|
+
return null;
|
|
2569
|
+
}
|
|
2570
|
+
let memo = AWAITED_TYPE_MEMO.get(context);
|
|
2571
|
+
if (!memo) {
|
|
2572
|
+
memo = new Map();
|
|
2573
|
+
AWAITED_TYPE_MEMO.set(context, memo);
|
|
2574
|
+
}
|
|
2575
|
+
const key = `${ref.filePath}|${ref.line}|${ref.column}|${receiverName}`;
|
|
2576
|
+
if (memo.has(key))
|
|
2577
|
+
return memo.get(key);
|
|
2578
|
+
const result = resolveAwaitedCallType(receiverName, file, ref, context);
|
|
2579
|
+
if (memo.size >= PATTERN_MEMO_CAP)
|
|
2580
|
+
memo.delete(memo.keys().next().value);
|
|
2581
|
+
memo.set(key, result);
|
|
2582
|
+
return result;
|
|
2583
|
+
}
|
|
2584
|
+
function resolveAwaitedCallType(receiverName, file, ref, context) {
|
|
2585
|
+
const unknown = { name: null, filePath: ref.filePath };
|
|
2586
|
+
const end = (file.offsets[ref.line - 1] ?? file.code.length) + ref.column;
|
|
2587
|
+
const code = file.code.slice(0, end);
|
|
2588
|
+
const escaped = receiverName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2589
|
+
// Locate scopes in the precomputed brace tree. Rescanning the entire file
|
|
2590
|
+
// for every candidate binding made large test files quadratic in refs.
|
|
2591
|
+
const scopeAt = (offset) => {
|
|
2592
|
+
let lo = 0, hi = file.scopes.length;
|
|
2593
|
+
while (lo + 1 < hi) {
|
|
2594
|
+
const mid = (lo + hi) >>> 1;
|
|
2595
|
+
if (file.scopes[mid].start < offset)
|
|
2596
|
+
lo = mid;
|
|
2597
|
+
else
|
|
2598
|
+
hi = mid;
|
|
2599
|
+
}
|
|
2600
|
+
while (lo > 0 && file.scopes[lo].end < offset)
|
|
2601
|
+
lo = file.scopes[lo].parent;
|
|
2602
|
+
return lo;
|
|
2603
|
+
};
|
|
2604
|
+
const visibleAt = (declaration, use) => {
|
|
2605
|
+
const ancestor = scopeAt(declaration);
|
|
2606
|
+
for (let scope = scopeAt(use); scope >= 0; scope = file.scopes[scope].parent)
|
|
2607
|
+
if (scope === ancestor)
|
|
2608
|
+
return true;
|
|
2609
|
+
return false;
|
|
2610
|
+
};
|
|
2611
|
+
const binding = [...(file.declarations.get(receiverName) ?? [])].reverse()
|
|
2612
|
+
.find(m => m.index < end && visibleAt(m.index, end));
|
|
2613
|
+
if (!binding)
|
|
2614
|
+
return null;
|
|
2615
|
+
const init = code.slice(binding.index + binding.length);
|
|
2616
|
+
if (!/^await\b/.test(init))
|
|
2617
|
+
return null;
|
|
2618
|
+
// Only a bare call result, not a following member/index/conditional expression.
|
|
2619
|
+
const call = /^await\s+([A-Za-z_$][\w$]*)\s*\(/.exec(init);
|
|
2620
|
+
if (!call)
|
|
2621
|
+
return null;
|
|
2622
|
+
let depth = 1, callEnd = call[0].length;
|
|
2623
|
+
for (; callEnd < init.length && depth; callEnd++) {
|
|
2624
|
+
if (init[callEnd] === '(')
|
|
2625
|
+
depth++;
|
|
2626
|
+
else if (init[callEnd] === ')')
|
|
2627
|
+
depth--;
|
|
2628
|
+
}
|
|
2629
|
+
if (depth)
|
|
2630
|
+
return unknown;
|
|
2631
|
+
const tail = init.slice(callEnd);
|
|
2632
|
+
// A following property/index/call is not the callee's annotated value.
|
|
2633
|
+
if (!/^[ \t]*(?:;|\r?\n(?![ \t]*[.(\[?]))/.test(tail))
|
|
2634
|
+
return unknown;
|
|
2635
|
+
const rest = tail;
|
|
2636
|
+
if (new RegExp(`\\b(?:const|let|var|function|class)\\s+(?:${escaped}\\b|\\{[^}]*\\b${escaped}\\b)`).test(rest) ||
|
|
2637
|
+
new RegExp(`\\b${escaped}\\s*=(?!=)`).test(rest) || hasParameterBinding(rest, escaped))
|
|
2638
|
+
return unknown;
|
|
2639
|
+
const bindingLine = file.code.slice(0, binding.index).split('\n').length;
|
|
2640
|
+
const bindingRef = { ...ref, line: bindingLine, column: binding.index - file.offsets[bindingLine - 1] };
|
|
2641
|
+
const callee = call[1];
|
|
2642
|
+
const calleeEscaped = callee.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2643
|
+
if (context.getNodesInFile(ref.filePath).some(n => (n.kind === 'function' || n.kind === 'method') && n.startLine <= bindingLine && n.endLine >= bindingLine &&
|
|
2644
|
+
n.signature && hasParameterBinding(`${n.signature} {`, calleeEscaped)))
|
|
2645
|
+
return unknown;
|
|
2646
|
+
const imported = context.getImportMappings(ref.filePath, ref.language).some(m => m.localName === callee);
|
|
2647
|
+
let declaring;
|
|
2648
|
+
if (imported) {
|
|
2649
|
+
if (importShadowedAt(callee, bindingRef, context))
|
|
2650
|
+
return unknown;
|
|
2651
|
+
const resolved = context.resolveImport?.({ ...bindingRef, referenceName: callee, referenceKind: 'calls' });
|
|
2652
|
+
declaring = resolved ? context.getNodeById?.(resolved.targetNodeId) ?? undefined : undefined;
|
|
2653
|
+
}
|
|
2654
|
+
else {
|
|
2655
|
+
const local = context.getNodesByName(callee).filter(n => n.kind === 'function' &&
|
|
2656
|
+
n.filePath === ref.filePath && ESM_FAMILY.has(n.language) && isLexicallyReachable(n, bindingRef, context));
|
|
2657
|
+
if (local.length === 1)
|
|
2658
|
+
declaring = local[0];
|
|
2659
|
+
}
|
|
2660
|
+
if (!declaring || declaring.kind !== 'function' || !declaring.signature)
|
|
2661
|
+
return unknown;
|
|
2662
|
+
if (!imported) {
|
|
2663
|
+
const beforeBinding = code.slice(0, binding.index);
|
|
2664
|
+
const shadows = new RegExp(`\\b(?:const|let|var)\\s+${calleeEscaped}\\b`, 'g');
|
|
2665
|
+
for (const shadow of beforeBinding.matchAll(shadows)) {
|
|
2666
|
+
if (!visibleAt(shadow.index, binding.index))
|
|
2667
|
+
continue;
|
|
2668
|
+
// A typed arrow function may itself be the declared local factory.
|
|
2669
|
+
const line = file.code.slice(0, shadow.index).split('\n').length;
|
|
2670
|
+
if (line !== declaring.startLine || shadow.index - file.offsets[line - 1] > declaring.startColumn)
|
|
2671
|
+
return unknown;
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
const signature = declaring.signature;
|
|
2675
|
+
const annotation = signature.slice(signature.lastIndexOf(')') + 1).match(/^\s*:\s*([\s\S]+)$/)?.[1]?.trim();
|
|
2676
|
+
if (!annotation)
|
|
2677
|
+
return unknown;
|
|
2678
|
+
// Do not turn unions, arrays, object/function types, or conditional types into
|
|
2679
|
+
// a project class. Await recursively unwraps promises, but this narrow path
|
|
2680
|
+
// accepts a single named Promise<T> layer only.
|
|
2681
|
+
const returned = annotation.match(/^Promise\s*<\s*([\w$]+)\s*>$/)?.[1] ?? annotation;
|
|
2682
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(returned))
|
|
2683
|
+
return unknown;
|
|
2684
|
+
if (js_builtins_1.TS_PRIMITIVE_TYPES.has(returned))
|
|
2685
|
+
return { name: returned, filePath: declaring.filePath };
|
|
2686
|
+
const typeRef = { ...bindingRef, fromNodeId: declaring.id, filePath: declaring.filePath,
|
|
2687
|
+
language: declaring.language, line: declaring.startLine, column: declaring.startColumn,
|
|
2688
|
+
referenceName: returned, referenceKind: 'references' };
|
|
2689
|
+
const typeImport = context.getImportMappings(declaring.filePath, declaring.language).some(m => m.localName === returned);
|
|
2690
|
+
const resolved = typeImport ? context.resolveImport?.(typeRef) : null;
|
|
2691
|
+
const typeNode = resolved ? context.getNodeById?.(resolved.targetNodeId) :
|
|
2692
|
+
context.getNodesByName(returned).find(n => n.filePath === declaring.filePath &&
|
|
2693
|
+
ESM_FAMILY.has(n.language) && (n.kind === 'class' || n.kind === 'interface'));
|
|
2694
|
+
if (!typeNode || (typeNode.kind !== 'class' && typeNode.kind !== 'interface'))
|
|
2695
|
+
return unknown;
|
|
2696
|
+
return { name: typeNode.name, filePath: typeNode.filePath };
|
|
2697
|
+
}
|
|
1402
2698
|
/**
|
|
1403
2699
|
* Patterns that recover a PHP class property's declared type for a
|
|
1404
2700
|
* `$this->prop` receiver. Deliberately NOT localReceiverTypePatterns: only
|
|
@@ -1536,6 +2832,15 @@ function matchMethodCall(ref, context) {
|
|
|
1536
2832
|
return null;
|
|
1537
2833
|
return resolveMethodOnType(inferredType, phpMethodName, ref, context, 0.9, 'instance-method', importedFqnOf(inferredType, ref, context));
|
|
1538
2834
|
}
|
|
2835
|
+
// A TS/JS call through an ES private field of the enclosing class —
|
|
2836
|
+
// `this.#items.add()`, emitted as `this.#items.add` (#1987) — resolves
|
|
2837
|
+
// exactly like `this.<field>` below (#1496). `#` is outside dotMatch's
|
|
2838
|
+
// receiver class, so the shape is matched here.
|
|
2839
|
+
if (ref.language === 'typescript' || ref.language === 'javascript' || ref.language === 'tsx' || ref.language === 'jsx') {
|
|
2840
|
+
const privateField = ref.referenceName.match(/^this\.(#[\w$]+)\.(\w+)$/);
|
|
2841
|
+
if (privateField)
|
|
2842
|
+
return matchTsThisFieldCall(privateField[1], privateField[2], ref, context);
|
|
2843
|
+
}
|
|
1539
2844
|
const match = dotMatch || colonMatch || luaColonMatch || rDollarMatch;
|
|
1540
2845
|
if (!match) {
|
|
1541
2846
|
return null;
|
|
@@ -1550,9 +2855,16 @@ function matchMethodCall(ref, context) {
|
|
|
1550
2855
|
// shared source-based inferrer. resolveMethodOnType validates the method
|
|
1551
2856
|
// exists on the inferred type, so a mis-inference produces no edge.
|
|
1552
2857
|
if (inferableReceiver) {
|
|
1553
|
-
|
|
2858
|
+
let inferredType = nmTimedT('mc-infer', ref, () => ref.language === 'cpp'
|
|
1554
2859
|
? inferCppReceiverType(objectOrClass, ref, context)
|
|
1555
2860
|
: inferLocalReceiverType(objectOrClass, ref, context));
|
|
2861
|
+
const awaited = !inferredType && ESM_FAMILY.has(ref.language)
|
|
2862
|
+
? inferEsmAwaitedCallType(objectOrClass, ref, context) : null;
|
|
2863
|
+
if (awaited) {
|
|
2864
|
+
if (!awaited.name || js_builtins_1.TS_PRIMITIVE_TYPES.has(awaited.name))
|
|
2865
|
+
return null;
|
|
2866
|
+
inferredType = awaited.name;
|
|
2867
|
+
}
|
|
1556
2868
|
if (inferredType) {
|
|
1557
2869
|
// Java/Kotlin: when two classes share the simple name, the file's import
|
|
1558
2870
|
// pins WHICH one (#314). Other languages disambiguate by call-site file.
|
|
@@ -1561,10 +2873,29 @@ function matchMethodCall(ref, context) {
|
|
|
1561
2873
|
.getImportMappings(ref.filePath, ref.language)
|
|
1562
2874
|
.find((i) => i.localName === inferredType)?.source
|
|
1563
2875
|
: undefined;
|
|
1564
|
-
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, ref, context, 0.9, 'instance-method', importedFqn));
|
|
2876
|
+
const typedMatch = nmTimedT('mc-rmot', ref, () => resolveMethodOnType(inferredType, methodName, awaited ? { ...ref, filePath: awaited.filePath } : ref, context, 0.9, 'instance-method', importedFqn));
|
|
1565
2877
|
if (typedMatch) {
|
|
2878
|
+
if (awaited) {
|
|
2879
|
+
const target = context.getNodeById?.(typedMatch.targetNodeId);
|
|
2880
|
+
if (!target || (target.qualifiedName.startsWith(`${inferredType}::`) && target.filePath !== awaited.filePath))
|
|
2881
|
+
return null;
|
|
2882
|
+
return { ...typedMatch, original: ref };
|
|
2883
|
+
}
|
|
1566
2884
|
return typedMatch;
|
|
1567
2885
|
}
|
|
2886
|
+
if (awaited)
|
|
2887
|
+
return null;
|
|
2888
|
+
// A known JS/TS builtin receiver is external when it has no project
|
|
2889
|
+
// method (#1566). Inference already strips generics (`Map<K, V>` →
|
|
2890
|
+
// `Map`); do not let Strategy 3 guess an unrelated `get`/`set`/`has`.
|
|
2891
|
+
// Keep the validated match above for a project type shadowing a builtin.
|
|
2892
|
+
// A primitive receiver joins the builtins here: `listed.split()` on a
|
|
2893
|
+
// `string` is the built-in method, and Strategy 3 would otherwise hand
|
|
2894
|
+
// it whichever project class happens to declare a lone `split` (#1840).
|
|
2895
|
+
if (ESM_FAMILY.has(ref.language) &&
|
|
2896
|
+
(js_builtins_1.JS_BUILT_INS.has(inferredType) || js_builtins_1.TS_PRIMITIVE_TYPES.has(inferredType))) {
|
|
2897
|
+
return null;
|
|
2898
|
+
}
|
|
1568
2899
|
}
|
|
1569
2900
|
}
|
|
1570
2901
|
// Go 2-hop field chain `base.field.Method` (#1276): the base's type comes
|
|
@@ -1581,6 +2912,39 @@ function matchMethodCall(ref, context) {
|
|
|
1581
2912
|
if (ref.language === 'go' && dotMatch && objectOrClass.includes('.')) {
|
|
1582
2913
|
return matchGoFieldChainCall(objectOrClass, methodName, ref, context);
|
|
1583
2914
|
}
|
|
2915
|
+
// Rust call through a field of the enclosing type — `self.inner.run()`,
|
|
2916
|
+
// emitted as `self.inner.run` (#1585). Same discipline as the Go branch
|
|
2917
|
+
// above, and EXCLUSIVE for the same reason: validated field-type inference
|
|
2918
|
+
// or nothing. Letting this shape reach the bare-name strategies below is
|
|
2919
|
+
// how `self.inner.run()` resolved to a same-named method on an unrelated
|
|
2920
|
+
// type — or to the calling method itself, a self-edge the source doesn't
|
|
2921
|
+
// contain — whenever the field's type was external or merely shared a
|
|
2922
|
+
// method name with something nearby.
|
|
2923
|
+
if (ref.language === 'rust' && dotMatch && objectOrClass.startsWith('self.')) {
|
|
2924
|
+
return matchRustSelfFieldCall(objectOrClass.slice('self.'.length), methodName, ref, context);
|
|
2925
|
+
}
|
|
2926
|
+
// Rust call on the enclosing type itself — `self.reset()`, emitted as
|
|
2927
|
+
// `self.reset` (#1861). Same discipline as the field branch above, and
|
|
2928
|
+
// EXCLUSIVE for the same reason: the owner is written on the `impl` line and
|
|
2929
|
+
// carried in the calling method's qualified name, so it is not a guess.
|
|
2930
|
+
// Letting this shape reach the bare-name strategies below is how
|
|
2931
|
+
// `self.reset()` resolved to a same-named method on an unrelated type
|
|
2932
|
+
// whenever that type's method happened to sit nearer the call site.
|
|
2933
|
+
if (ref.language === 'rust' && dotMatch && objectOrClass === 'self') {
|
|
2934
|
+
return matchRustSelfCall(methodName, ref, context);
|
|
2935
|
+
}
|
|
2936
|
+
// TS/JS call through a field of the enclosing class — `this.mailer.send()`,
|
|
2937
|
+
// emitted as `this.mailer.send` (#1496). Same discipline as the Rust branch
|
|
2938
|
+
// above, and EXCLUSIVE for the same reason: the field's declared type off
|
|
2939
|
+
// the class's own declaration, validated by resolveMethodOnType, or nothing.
|
|
2940
|
+
// Letting the bare name through is how `this.mailer.send()` inside
|
|
2941
|
+
// `Notifier.send()` resolved to the calling method itself — a self-edge the
|
|
2942
|
+
// source does not contain — whenever the two shared a name.
|
|
2943
|
+
if ((ref.language === 'typescript' || ref.language === 'javascript' || ref.language === 'tsx' || ref.language === 'jsx') &&
|
|
2944
|
+
dotMatch &&
|
|
2945
|
+
objectOrClass.startsWith('this.')) {
|
|
2946
|
+
return matchTsThisFieldCall(objectOrClass.slice('this.'.length), methodName, ref, context);
|
|
2947
|
+
}
|
|
1584
2948
|
// Java/Kotlin: receiver may be a field whose name doesn't match the type by
|
|
1585
2949
|
// Java naming convention (`userbo` → class `UserBO`, abbreviated). Look up
|
|
1586
2950
|
// the field in the enclosing class to get its declared type, then resolve
|
|
@@ -1600,59 +2964,85 @@ function matchMethodCall(ref, context) {
|
|
|
1600
2964
|
}
|
|
1601
2965
|
}
|
|
1602
2966
|
}
|
|
2967
|
+
// Object-literal namespace receiver (#1573): `api.call()` where `api` is a
|
|
2968
|
+
// same-file `const api = { call() {…}, get: () => {…} }`. Its members are
|
|
2969
|
+
// plain functions with bare names inside the constant's extent — no
|
|
2970
|
+
// `Container::member` qualified name — so none of the class-shaped
|
|
2971
|
+
// strategies below can see them (Strategy 3 only considers `method`
|
|
2972
|
+
// kinds) and the call resolved to nothing at all. Same file only: a
|
|
2973
|
+
// cross-file use reaches the same helper through the import path.
|
|
2974
|
+
if (dotMatch && !objectOrClass.includes('.') && OBJECT_LITERAL_LANGUAGES.has(ref.language)) {
|
|
2975
|
+
const literalMatch = nmTimedT('mc-literal', ref, () => {
|
|
2976
|
+
// Same-file holders only, so the call-site-first ordering is moot.
|
|
2977
|
+
const holders = context.getNodesByName(objectOrClass).filter((n) => (n.kind === 'constant' || n.kind === 'variable') && n.filePath === ref.filePath);
|
|
2978
|
+
for (const holder of holders) {
|
|
2979
|
+
const hit = resolveObjectLiteralMember(holder, methodName, ref, context, 0.85, 'instance-method') ??
|
|
2980
|
+
resolveObjectLiteralBinding(holder, methodName, ref, context);
|
|
2981
|
+
if (hit)
|
|
2982
|
+
return hit;
|
|
2983
|
+
}
|
|
2984
|
+
return null;
|
|
2985
|
+
});
|
|
2986
|
+
if (literalMatch)
|
|
2987
|
+
return literalMatch;
|
|
2988
|
+
}
|
|
1603
2989
|
// Strategy 1: Direct class name match (existing logic). When the receiver
|
|
1604
2990
|
// names a class that exists in several files (`Logger.log()` / `Logger::log()`
|
|
1605
2991
|
// with a `Logger` in both `a/` and `b/`), try the class in the call site's
|
|
1606
2992
|
// own file first — otherwise the first-indexed class wins and a call in `b/`
|
|
1607
2993
|
// resolves to `a/`'s method (#1079).
|
|
1608
2994
|
const strat1 = nmTimedT('mc-class', ref, () => {
|
|
1609
|
-
const classCandidates = preferCallSiteFile(context.getNodesByName(objectOrClass), ref.filePath);
|
|
2995
|
+
const classCandidates = preferCallSiteFile(context.getNodesByName(objectOrClass).filter(isMethodOwnerKind), ref.filePath);
|
|
1610
2996
|
for (const classNode of classCandidates) {
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
2997
|
+
// Skip cross-language class matches
|
|
2998
|
+
if (classNode.language !== ref.language)
|
|
2999
|
+
continue;
|
|
3000
|
+
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
3001
|
+
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
3002
|
+
n.name === methodName &&
|
|
3003
|
+
n.qualifiedName.includes(classNode.name));
|
|
3004
|
+
if (methodNode) {
|
|
3005
|
+
return {
|
|
3006
|
+
original: ref,
|
|
3007
|
+
targetNodeId: methodNode.id,
|
|
3008
|
+
confidence: 0.85,
|
|
3009
|
+
resolvedBy: 'qualified-name',
|
|
3010
|
+
};
|
|
1627
3011
|
}
|
|
1628
3012
|
}
|
|
1629
3013
|
return null;
|
|
1630
3014
|
});
|
|
1631
3015
|
if (strat1)
|
|
1632
3016
|
return strat1;
|
|
3017
|
+
// Built-in method names need a validated receiver (#1987). Typed, imported,
|
|
3018
|
+
// object-literal and direct class receivers have had their chance above;
|
|
3019
|
+
// capitalization, word overlap or a unique method name are not evidence
|
|
3020
|
+
// that `list.map()` / `cache.get()` calls a project class.
|
|
3021
|
+
if (ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language) &&
|
|
3022
|
+
objectOrClass !== 'this' && objectOrClass !== 'super' &&
|
|
3023
|
+
js_builtins_1.JS_BUILTIN_METHODS.has(methodName))
|
|
3024
|
+
return null;
|
|
1633
3025
|
// Strategy 2: Instance variable receiver - try capitalized form to find class
|
|
1634
3026
|
// e.g., "permissionEngine" → look for classes containing "PermissionEngine"
|
|
1635
3027
|
const capitalizedReceiver = objectOrClass.charAt(0).toUpperCase() + objectOrClass.slice(1);
|
|
1636
3028
|
if (capitalizedReceiver !== objectOrClass) {
|
|
1637
3029
|
const strat2 = nmTimedT('mc-capital', ref, () => {
|
|
1638
|
-
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver), ref.filePath);
|
|
3030
|
+
const fuzzyClassCandidates = preferCallSiteFile(context.getNodesByName(capitalizedReceiver).filter(isMethodOwnerKind), ref.filePath);
|
|
1639
3031
|
for (const classNode of fuzzyClassCandidates) {
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
3032
|
+
// Skip cross-language class matches
|
|
3033
|
+
if (classNode.language !== ref.language)
|
|
3034
|
+
continue;
|
|
3035
|
+
const nodesInFile = context.getNodesInFile(classNode.filePath);
|
|
3036
|
+
const methodNode = nodesInFile.find((n) => n.kind === 'method' &&
|
|
3037
|
+
n.name === methodName &&
|
|
3038
|
+
n.qualifiedName.includes(classNode.name));
|
|
3039
|
+
if (methodNode) {
|
|
3040
|
+
return {
|
|
3041
|
+
original: ref,
|
|
3042
|
+
targetNodeId: methodNode.id,
|
|
3043
|
+
confidence: 0.8,
|
|
3044
|
+
resolvedBy: 'instance-method',
|
|
3045
|
+
};
|
|
1656
3046
|
}
|
|
1657
3047
|
}
|
|
1658
3048
|
return null;
|
|
@@ -1803,6 +3193,641 @@ function matchGoFieldChainCall(receiverChain, methodName, ref, context) {
|
|
|
1803
3193
|
}
|
|
1804
3194
|
return null;
|
|
1805
3195
|
}
|
|
3196
|
+
// Rust primitives and the prelude's own types: a field of one of these never
|
|
3197
|
+
// names a project type, so a `self.<field>.<method>()` on it stays unresolved.
|
|
3198
|
+
const RUST_NON_PROJECT_FIELD_TYPES = new Set([
|
|
3199
|
+
'bool', 'char', 'str', 'String',
|
|
3200
|
+
'i8', 'i16', 'i32', 'i64', 'i128', 'isize',
|
|
3201
|
+
'u8', 'u16', 'u32', 'u64', 'u128', 'usize',
|
|
3202
|
+
'f32', 'f64',
|
|
3203
|
+
'Self', 'self',
|
|
3204
|
+
]);
|
|
3205
|
+
/**
|
|
3206
|
+
* Reduce a Rust field's declared type text to the simple name of the type a
|
|
3207
|
+
* method call on that field auto-derefs to, or null when there is none we can
|
|
3208
|
+
* name. Only the layers Rust's method-call auto-deref looks through are
|
|
3209
|
+
* unwrapped: references (`&`, `&'a mut`) and the owning smart pointers
|
|
3210
|
+
* (`Box`, `Rc`, `Arc`) — `self.inner.run()` with `inner: Box<Inner>` calls
|
|
3211
|
+
* `Inner::run`. Containers that do NOT auto-deref to their parameter
|
|
3212
|
+
* (`Option<Inner>`, `Vec<Inner>`, `Mutex<Inner>`, `RefCell<Inner>`) keep their
|
|
3213
|
+
* own name and, having no project node, resolve to nothing — `self.items.push()`
|
|
3214
|
+
* must never become `Inner::push`. A trait object (`Box<dyn Source>`) yields
|
|
3215
|
+
* the trait, whose method node the interface-impl synthesizer fans out. A
|
|
3216
|
+
* generic parameter (`T`), a primitive, a tuple / array / raw pointer / fn
|
|
3217
|
+
* type, or a non-identifier yields null.
|
|
3218
|
+
*/
|
|
3219
|
+
function rustFieldTypeName(raw) {
|
|
3220
|
+
let t = raw.trim();
|
|
3221
|
+
for (;;) {
|
|
3222
|
+
const before = t;
|
|
3223
|
+
t = t.replace(/^&\s*(?:'\w+\s+)?(?:mut\s+)?/, '');
|
|
3224
|
+
t = t.replace(/^(?:Box|Rc|Arc)\s*<\s*/, '');
|
|
3225
|
+
t = t.replace(/^(?:dyn|impl)\s+/, '');
|
|
3226
|
+
if (t === before)
|
|
3227
|
+
break;
|
|
3228
|
+
}
|
|
3229
|
+
// Drop generic args, the closing `>`s of unwrapped pointers, and trait-object
|
|
3230
|
+
// bounds (`dyn Source + Send`); keep the last path segment.
|
|
3231
|
+
t = t.replace(/[<>+].*$/, '').trim();
|
|
3232
|
+
const seg = t.split('::').filter(Boolean).pop();
|
|
3233
|
+
if (!seg || !/^[A-Za-z_]\w*$/.test(seg))
|
|
3234
|
+
return null;
|
|
3235
|
+
if (RUST_NON_PROJECT_FIELD_TYPES.has(seg))
|
|
3236
|
+
return null;
|
|
3237
|
+
if (/^[A-Z]$/.test(seg))
|
|
3238
|
+
return null; // bare single-letter generic parameter
|
|
3239
|
+
return seg;
|
|
3240
|
+
}
|
|
3241
|
+
/**
|
|
3242
|
+
* `self.method()` in Rust — the method on the type the call sits inside.
|
|
3243
|
+
*
|
|
3244
|
+
* The owner is the calling method's qualified-name prefix (`Target::run` →
|
|
3245
|
+
* `Target`), which is where the `impl` block's type ends up. A free function
|
|
3246
|
+
* has no `self`, so a caller whose qualified name carries no owner declines.
|
|
3247
|
+
* Exactly one candidate must belong to that owner: a project with two `impl`
|
|
3248
|
+
* blocks for the same type is normal, two same-named methods on it is not, and
|
|
3249
|
+
* guessing between them is the failure this replaces.
|
|
3250
|
+
*/
|
|
3251
|
+
function matchRustSelfCall(methodName, ref, context) {
|
|
3252
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
3253
|
+
if (!caller?.qualifiedName)
|
|
3254
|
+
return null;
|
|
3255
|
+
const sep = caller.qualifiedName.lastIndexOf('::');
|
|
3256
|
+
if (sep <= 0)
|
|
3257
|
+
return null; // a free fn has no `self`
|
|
3258
|
+
const owner = caller.qualifiedName.slice(0, sep);
|
|
3259
|
+
let owned = context
|
|
3260
|
+
.getNodesByQualifiedName(`${owner}::${methodName}`)
|
|
3261
|
+
.filter((n) => n.kind === 'method' &&
|
|
3262
|
+
n.language === 'rust' &&
|
|
3263
|
+
n.qualifiedName === `${owner}::${methodName}`);
|
|
3264
|
+
// Rust's extracted qualified names omit module paths. Two modules can
|
|
3265
|
+
// each declare `Target`; matching just `Target::reset` does not establish
|
|
3266
|
+
// ownership. In that case require a single owner declaration in the
|
|
3267
|
+
// caller's file and a method in that file. Otherwise leave it unresolved.
|
|
3268
|
+
// A unique owner still permits ordinary impl blocks split across files.
|
|
3269
|
+
const owners = context.getNodesByQualifiedName(owner).filter((n) => n.language === 'rust' && ['struct', 'enum', 'union', 'trait', 'class'].includes(n.kind));
|
|
3270
|
+
if (owners.length > 1) {
|
|
3271
|
+
if (owners.filter((n) => n.filePath === caller.filePath).length !== 1)
|
|
3272
|
+
return null;
|
|
3273
|
+
owned = owned.filter((n) => n.filePath === caller.filePath);
|
|
3274
|
+
}
|
|
3275
|
+
if (owned.length !== 1)
|
|
3276
|
+
return null;
|
|
3277
|
+
return {
|
|
3278
|
+
original: ref,
|
|
3279
|
+
targetNodeId: owned[0].id,
|
|
3280
|
+
confidence: 0.9,
|
|
3281
|
+
resolvedBy: 'qualified-name',
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Resolve a Rust call through a field of the enclosing type —
|
|
3286
|
+
* `self.inner.run()`, emitted by the extractor as `self.inner.run` (#1585).
|
|
3287
|
+
* Mirrors the Go 2-hop precedent above (#1276): the owner type is the calling
|
|
3288
|
+
* method's qualified-name prefix (`Outer::run` → `Outer`), the field's declared
|
|
3289
|
+
* type comes from the owner struct's OWN declaration lines, and the method is
|
|
3290
|
+
* resolved AND VALIDATED on that type by resolveMethodOnType. The caller
|
|
3291
|
+
* treats this branch as exclusive for `self.<field>` receivers: a field whose
|
|
3292
|
+
* type is external (`std::vec::IntoIter`, `regex::Regex`), a generic
|
|
3293
|
+
* parameter, or not declared where we can see it yields null and the ref stays
|
|
3294
|
+
* unresolved. Rust struct fields are not graph nodes, so the declaration text
|
|
3295
|
+
* is the only place the type lives.
|
|
3296
|
+
*/
|
|
3297
|
+
function matchRustSelfFieldCall(field, methodName, ref, context) {
|
|
3298
|
+
// The extractor only ever emits a single field hop; anything else is not ours.
|
|
3299
|
+
if (!field || field.includes('.'))
|
|
3300
|
+
return null;
|
|
3301
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
3302
|
+
if (!caller)
|
|
3303
|
+
return null;
|
|
3304
|
+
const sep = caller.qualifiedName.lastIndexOf('::');
|
|
3305
|
+
if (sep <= 0)
|
|
3306
|
+
return null; // a free fn has no `self`
|
|
3307
|
+
const owner = caller.qualifiedName.slice(0, sep).split('::').pop();
|
|
3308
|
+
if (!owner)
|
|
3309
|
+
return null;
|
|
3310
|
+
const owners = preferCallSiteFile(context.getNodesByName(owner), ref.filePath).filter((n) => (n.kind === 'struct' || n.kind === 'union' || n.kind === 'class') &&
|
|
3311
|
+
n.language === 'rust');
|
|
3312
|
+
const fieldEsc = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3313
|
+
// `pub inner: Inner,` / `inner: Box<dyn Source>,` / `pub(crate) inner: T }` —
|
|
3314
|
+
// the type text runs to the field separator. A comma inside generic args
|
|
3315
|
+
// (`HashMap<K, V>`) truncates the capture, which rustFieldTypeName then
|
|
3316
|
+
// reduces to the container's own name — exactly the non-deref case it
|
|
3317
|
+
// refuses anyway.
|
|
3318
|
+
const fieldRe = new RegExp(`\\b${fieldEsc}\\s*:\\s*([^,{}]+)`);
|
|
3319
|
+
for (const s of owners) {
|
|
3320
|
+
const source = context.readFile(s.filePath);
|
|
3321
|
+
if (!source)
|
|
3322
|
+
continue;
|
|
3323
|
+
// Only the struct's own declaration lines, comment-stripped line by line —
|
|
3324
|
+
// same discipline as the Go helper: prose or a same-named identifier
|
|
3325
|
+
// elsewhere in the file can never donate a type.
|
|
3326
|
+
const declLines = source.split('\n').slice(Math.max(0, s.startLine - 1), s.endLine);
|
|
3327
|
+
for (const rawLine of declLines) {
|
|
3328
|
+
const line = rawLine.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '');
|
|
3329
|
+
const m = line.match(fieldRe);
|
|
3330
|
+
if (!m || !m[1])
|
|
3331
|
+
continue;
|
|
3332
|
+
const fieldType = rustFieldTypeName(m[1]);
|
|
3333
|
+
// The field is declared here; whether or not its type names a project
|
|
3334
|
+
// symbol, this owner is the answer — no other same-named struct applies.
|
|
3335
|
+
if (!fieldType)
|
|
3336
|
+
return null;
|
|
3337
|
+
return resolveMethodOnType(fieldType, methodName, ref, context, 0.85, 'instance-method');
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
return null;
|
|
3341
|
+
}
|
|
3342
|
+
/**
|
|
3343
|
+
* Per-context memo for matchTsThisFieldCall's declaration scan: `classId\0field`
|
|
3344
|
+
* → the first line of the class that declares the field (as `: typeof X`,
|
|
3345
|
+
* `: X`, or `= new X`, tried in that order per line) with its captured type,
|
|
3346
|
+
* or null. The scan depends only on the class and the field, but ran for every
|
|
3347
|
+
* `this.<field>.<method>()` call — re-splitting the file and compiling three
|
|
3348
|
+
* patterns each time, a third of all method-call matching on vscode. Derived
|
|
3349
|
+
* from file source: drops with clearNameMatcherMemos.
|
|
3350
|
+
*/
|
|
3351
|
+
const TS_FIELD_DECL_MEMO = new WeakMap();
|
|
3352
|
+
/** The last few classes' declarations — calls arrive file by file. */
|
|
3353
|
+
const TS_CLASS_LINES = new WeakMap();
|
|
3354
|
+
const TS_CLASS_LINES_KEEP = 32;
|
|
3355
|
+
function tsClassDecl(cls, context) {
|
|
3356
|
+
let cache = TS_CLASS_LINES.get(context);
|
|
3357
|
+
if (!cache) {
|
|
3358
|
+
cache = new Map();
|
|
3359
|
+
TS_CLASS_LINES.set(context, cache);
|
|
3360
|
+
}
|
|
3361
|
+
const hit = cache.get(cls.id);
|
|
3362
|
+
if (hit !== undefined)
|
|
3363
|
+
return hit;
|
|
3364
|
+
const source = context.readFile(cls.filePath);
|
|
3365
|
+
const decl = source
|
|
3366
|
+
? {
|
|
3367
|
+
lines: source
|
|
3368
|
+
.split('\n')
|
|
3369
|
+
.slice(Math.max(0, cls.startLine - 1), cls.endLine)
|
|
3370
|
+
.map((rawLine) => rawLine.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '')),
|
|
3371
|
+
lookups: 0,
|
|
3372
|
+
linesByToken: null,
|
|
3373
|
+
}
|
|
3374
|
+
: null;
|
|
3375
|
+
if (cache.size >= TS_CLASS_LINES_KEEP)
|
|
3376
|
+
cache.delete(cache.keys().next().value);
|
|
3377
|
+
cache.set(cls.id, decl);
|
|
3378
|
+
return decl;
|
|
3379
|
+
}
|
|
3380
|
+
const TS_FIELD_TOKEN = /^[\w$#]+$/;
|
|
3381
|
+
const TS_LINE_TOKEN = /[\w$#]+/g;
|
|
3382
|
+
const TS_TOKEN_CHAR = /[\w$#]/;
|
|
3383
|
+
/**
|
|
3384
|
+
* tsFieldPatterns with the field spelled `[\w$#]+`, tried sticky at a whole-
|
|
3385
|
+
* token occurrence of the field. There the run consumes exactly the field (a
|
|
3386
|
+
* shorter prefix cannot continue: every pattern needs `\s`, `?`, `!`, `:` or
|
|
3387
|
+
* `=` next), so each matches exactly where the field's own pattern would —
|
|
3388
|
+
* without compiling three patterns for every field of every class.
|
|
3389
|
+
*/
|
|
3390
|
+
const TS_FIELD_PATTERNS_AT = [
|
|
3391
|
+
{ re: /(?<![\w$#])[\w$#]+\b\s*[?!]?\s*:\s*(?:readonly\s+)?typeof\s+([A-Za-z_$][\w.$]*)/y, valueType: true },
|
|
3392
|
+
{ re: /(?<![\w$#])[\w$#]+\b\s*[?!]?\s*:\s*(?:readonly\s+)?([A-Za-z_$][\w.$]*)/y, valueType: false },
|
|
3393
|
+
{ re: /(?<![\w$#])[\w$#]+\b\s*=\s*new\s+([A-Za-z_$][\w.$]*)/y, valueType: false },
|
|
3394
|
+
];
|
|
3395
|
+
/** The first declaration of `field` on one line, as `line.match` of its patterns in order would find it. */
|
|
3396
|
+
function tsFieldOnLine(line, field) {
|
|
3397
|
+
let at = null;
|
|
3398
|
+
for (let i = line.indexOf(field); i !== -1; i = line.indexOf(field, i + 1)) {
|
|
3399
|
+
const end = i + field.length;
|
|
3400
|
+
if ((i > 0 && TS_TOKEN_CHAR.test(line[i - 1])) || (end < line.length && TS_TOKEN_CHAR.test(line[end])))
|
|
3401
|
+
continue;
|
|
3402
|
+
(at ??= []).push(i);
|
|
3403
|
+
}
|
|
3404
|
+
if (!at)
|
|
3405
|
+
return null;
|
|
3406
|
+
for (const { re, valueType } of TS_FIELD_PATTERNS_AT) {
|
|
3407
|
+
for (const i of at) {
|
|
3408
|
+
re.lastIndex = i;
|
|
3409
|
+
const m = re.exec(line);
|
|
3410
|
+
if (m && m[1])
|
|
3411
|
+
return { valueType, type: m[1] };
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
return null;
|
|
3415
|
+
}
|
|
3416
|
+
/** Indices of the class lines holding `token` as a whole `[\w$#]` run, ascending. */
|
|
3417
|
+
function tsClassLinesWithToken(decl, token) {
|
|
3418
|
+
if (!decl.linesByToken) {
|
|
3419
|
+
const index = new Map();
|
|
3420
|
+
for (let i = 0; i < decl.lines.length; i++) {
|
|
3421
|
+
for (const m of decl.lines[i].matchAll(TS_LINE_TOKEN)) {
|
|
3422
|
+
const rows = index.get(m[0]);
|
|
3423
|
+
if (!rows)
|
|
3424
|
+
index.set(m[0], [i]);
|
|
3425
|
+
else if (rows[rows.length - 1] !== i)
|
|
3426
|
+
rows.push(i);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
decl.linesByToken = index;
|
|
3430
|
+
}
|
|
3431
|
+
return decl.linesByToken.get(token) ?? [];
|
|
3432
|
+
}
|
|
3433
|
+
/** Compiled declaration patterns by field name — fields recur across classes. */
|
|
3434
|
+
const TS_FIELD_PATTERNS = new Map();
|
|
3435
|
+
const TS_FIELD_PATTERNS_CAP = 4096;
|
|
3436
|
+
function tsFieldPatterns(field) {
|
|
3437
|
+
const hit = TS_FIELD_PATTERNS.get(field);
|
|
3438
|
+
if (hit)
|
|
3439
|
+
return hit;
|
|
3440
|
+
const fieldEsc = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3441
|
+
// A word boundary cannot open a private name; it also lets a public
|
|
3442
|
+
// `items` match `#items`. Keep the two field namespaces distinct (#1987).
|
|
3443
|
+
const fieldStart = '(?<![\\w$#])';
|
|
3444
|
+
const patterns = [
|
|
3445
|
+
// `storage: typeof DraftHubStorage` — the type OF a value: an object
|
|
3446
|
+
// literal used as a namespace. Its members are bare-named functions inside
|
|
3447
|
+
// the constant's extent (#1573), so they are found by containment, not by
|
|
3448
|
+
// `Type::method`. Tried first: the declared-type pattern below would
|
|
3449
|
+
// otherwise capture the word `typeof`.
|
|
3450
|
+
{
|
|
3451
|
+
re: new RegExp(`${fieldStart}${fieldEsc}\\b\\s*[?!]?\\s*:\\s*(?:readonly\\s+)?typeof\\s+([A-Za-z_$][\\w.$]*)`),
|
|
3452
|
+
valueType: true,
|
|
3453
|
+
},
|
|
3454
|
+
// `private readonly mailer?: Mailer` — a class field or a constructor
|
|
3455
|
+
// parameter property; the capture stops at `<`, `[` or `|`, so a generic
|
|
3456
|
+
// or union type yields its head and resolveMethodOnType decides.
|
|
3457
|
+
{
|
|
3458
|
+
re: new RegExp(`${fieldStart}${fieldEsc}\\b\\s*[?!]?\\s*:\\s*(?:readonly\\s+)?([A-Za-z_$][\\w.$]*)`),
|
|
3459
|
+
valueType: false,
|
|
3460
|
+
},
|
|
3461
|
+
// `mailer = new Mailer()` / `this.mailer = new Mailer()`
|
|
3462
|
+
{ re: new RegExp(`${fieldStart}${fieldEsc}\\b\\s*=\\s*new\\s+([A-Za-z_$][\\w.$]*)`), valueType: false },
|
|
3463
|
+
];
|
|
3464
|
+
if (TS_FIELD_PATTERNS.size >= TS_FIELD_PATTERNS_CAP)
|
|
3465
|
+
TS_FIELD_PATTERNS.delete(TS_FIELD_PATTERNS.keys().next().value);
|
|
3466
|
+
TS_FIELD_PATTERNS.set(field, patterns);
|
|
3467
|
+
return patterns;
|
|
3468
|
+
}
|
|
3469
|
+
function tsFieldDeclaration(cls, field, context) {
|
|
3470
|
+
let memo = TS_FIELD_DECL_MEMO.get(context);
|
|
3471
|
+
if (!memo) {
|
|
3472
|
+
memo = new Map();
|
|
3473
|
+
TS_FIELD_DECL_MEMO.set(context, memo);
|
|
3474
|
+
}
|
|
3475
|
+
const key = cls.id + '\0' + field;
|
|
3476
|
+
const hit = memo.get(key);
|
|
3477
|
+
if (hit !== undefined)
|
|
3478
|
+
return hit;
|
|
3479
|
+
let found = null;
|
|
3480
|
+
const decl = tsClassDecl(cls, context);
|
|
3481
|
+
if (decl && TS_FIELD_TOKEN.test(field)) {
|
|
3482
|
+
// Every pattern needs the field as a whole `[\w$#]` run — the lookbehind
|
|
3483
|
+
// bars one before it, and nothing after it but `\s`, `?`, `!`, `:` or `=`
|
|
3484
|
+
// can continue a match — so only lines holding that token can match. A
|
|
3485
|
+
// class asked about several fields is indexed by token once.
|
|
3486
|
+
const rows = ++decl.lookups > 1 ? tsClassLinesWithToken(decl, field) : null;
|
|
3487
|
+
const count = rows ? rows.length : decl.lines.length;
|
|
3488
|
+
for (let k = 0; k < count && !found; k++) {
|
|
3489
|
+
const line = decl.lines[rows ? rows[k] : k];
|
|
3490
|
+
// Every pattern spells the field literally, so only a line that contains
|
|
3491
|
+
// it can match — and most of a class's lines never mention a given field.
|
|
3492
|
+
if (line.includes(field))
|
|
3493
|
+
found = tsFieldOnLine(line, field);
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
else if (decl) {
|
|
3497
|
+
const patterns = tsFieldPatterns(field);
|
|
3498
|
+
scan: for (const line of decl.lines) {
|
|
3499
|
+
if (!line.includes(field))
|
|
3500
|
+
continue;
|
|
3501
|
+
for (const { re, valueType } of patterns) {
|
|
3502
|
+
const m = line.match(re);
|
|
3503
|
+
if (!m || !m[1])
|
|
3504
|
+
continue;
|
|
3505
|
+
found = { valueType, type: m[1] };
|
|
3506
|
+
break scan;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
memo.set(key, found);
|
|
3511
|
+
return found;
|
|
3512
|
+
}
|
|
3513
|
+
/**
|
|
3514
|
+
* Resolve a TS/JS `this.<field>.<method>()` call (#1496) through the field's
|
|
3515
|
+
* declared type, read off the ENCLOSING class's own declaration lines:
|
|
3516
|
+
* a field or constructor-parameter property (`private mailer: Mailer`,
|
|
3517
|
+
* `mailer?: Mailer`, `readonly mailer: Mailer`) or an initializer
|
|
3518
|
+
* (`mailer = new Mailer()`, `this.mailer = new Mailer()`). The method is then
|
|
3519
|
+
* VALIDATED on that type by resolveMethodOnType. Null — never a bare-name
|
|
3520
|
+
* fallback — when the field is not declared there or its type is external,
|
|
3521
|
+
* a builtin (`this.items.push()`) or not spelled out.
|
|
3522
|
+
*/
|
|
3523
|
+
function matchTsThisFieldCall(field, methodName, ref, context) {
|
|
3524
|
+
if (!field || field.includes('.'))
|
|
3525
|
+
return null;
|
|
3526
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
3527
|
+
if (!caller)
|
|
3528
|
+
return null;
|
|
3529
|
+
const sep = caller.qualifiedName.lastIndexOf('::');
|
|
3530
|
+
if (sep <= 0)
|
|
3531
|
+
return null; // not inside a class
|
|
3532
|
+
const owner = caller.qualifiedName.slice(0, sep).split('::').pop();
|
|
3533
|
+
if (!owner)
|
|
3534
|
+
return null;
|
|
3535
|
+
const owners = preferCallSiteFile(context.getNodesByName(owner), ref.filePath).filter((n) => (n.kind === 'class' || n.kind === 'component') && sameLanguageFamily(n.language, ref.language));
|
|
3536
|
+
for (const cls of owners) {
|
|
3537
|
+
const decl = tsFieldDeclaration(cls, field, context);
|
|
3538
|
+
if (!decl)
|
|
3539
|
+
continue;
|
|
3540
|
+
if (decl.valueType) {
|
|
3541
|
+
// The value's declaration may live in another file (it is imported);
|
|
3542
|
+
// the call site's file is preferred when several share the name.
|
|
3543
|
+
const holderName = decl.type.split('.').pop();
|
|
3544
|
+
const holders = preferCallSiteFile(context.getNodesByName(holderName), ref.filePath).filter((n) => (n.kind === 'constant' || n.kind === 'variable') && sameLanguageFamily(n.language, ref.language));
|
|
3545
|
+
for (const holder of holders) {
|
|
3546
|
+
const hit = resolveObjectLiteralMember(holder, methodName, ref, context, 0.85, 'instance-method');
|
|
3547
|
+
if (hit)
|
|
3548
|
+
return hit;
|
|
3549
|
+
}
|
|
3550
|
+
return null;
|
|
3551
|
+
}
|
|
3552
|
+
// `ns.Mailer` → `Mailer`; a primitive or builtin names no project type.
|
|
3553
|
+
const typeName = decl.type.split('.').pop();
|
|
3554
|
+
if (!/^[A-Z]/.test(typeName))
|
|
3555
|
+
return null;
|
|
3556
|
+
// Two apps in one repo may each declare a `UserService`. The bare-name
|
|
3557
|
+
// path this replaces broke that tie by directory proximity, so keep the
|
|
3558
|
+
// same signal: among the type's declarations of the method, prefer the
|
|
3559
|
+
// one closest to the call site's directory (its own app), never index
|
|
3560
|
+
// order. resolveMethodOnType still answers the single-declaration and
|
|
3561
|
+
// supertype cases.
|
|
3562
|
+
const declared = context
|
|
3563
|
+
.getNodesByName(methodName)
|
|
3564
|
+
.filter((n) => n.kind === 'method' &&
|
|
3565
|
+
sameLanguageFamily(n.language, ref.language) &&
|
|
3566
|
+
(n.qualifiedName === `${typeName}::${methodName}` || n.qualifiedName.endsWith(`::${typeName}::${methodName}`)));
|
|
3567
|
+
if (declared.length > 1) {
|
|
3568
|
+
const callDirs = ref.filePath.split('/').slice(0, -1);
|
|
3569
|
+
const shared = (fp) => {
|
|
3570
|
+
const dirs = fp.split('/').slice(0, -1);
|
|
3571
|
+
let i = 0;
|
|
3572
|
+
while (i < dirs.length && i < callDirs.length && dirs[i] === callDirs[i])
|
|
3573
|
+
i++;
|
|
3574
|
+
return i;
|
|
3575
|
+
};
|
|
3576
|
+
const nearest = [...declared].sort((a, b) => shared(b.filePath) - shared(a.filePath) || a.filePath.localeCompare(b.filePath))[0];
|
|
3577
|
+
return { original: ref, targetNodeId: nearest.id, confidence: 0.85, resolvedBy: 'instance-method' };
|
|
3578
|
+
}
|
|
3579
|
+
return resolveMethodOnType(typeName, methodName, ref, context, 0.85, 'instance-method');
|
|
3580
|
+
}
|
|
3581
|
+
return null;
|
|
3582
|
+
}
|
|
3583
|
+
/**
|
|
3584
|
+
* The one fallback a TS/JS/Python call-receiver chain keeps (#1683): a STORE
|
|
3585
|
+
* ACCESSOR. Zustand's `get()` inside the store factory and
|
|
3586
|
+
* `useStore.getState()` outside it hand back the store whose actions are
|
|
3587
|
+
* indexed as functions (#1573). JS/TS resolves the member within that store;
|
|
3588
|
+
* the existing Python fallback still requires a unique callable. Nothing else
|
|
3589
|
+
* qualifies: a chain rooted in a project value still says nothing about what
|
|
3590
|
+
* the inner call RETURNS — `db.prepare(sql).all()` would bind to any project
|
|
3591
|
+
* function named `all` — so it resolves to nothing, exactly like a chain
|
|
3592
|
+
* rooted in a parameter (`d.setdefault(k, []).append(v)`).
|
|
3593
|
+
*/
|
|
3594
|
+
function matchStoreAccessorChain(ref, context) {
|
|
3595
|
+
const m = ref.referenceName.match(/^([\w$.]+)\(\)\.(\w+)$/);
|
|
3596
|
+
if (!m || !m[1] || !m[2])
|
|
3597
|
+
return null;
|
|
3598
|
+
const inner = m[1];
|
|
3599
|
+
const method = m[2];
|
|
3600
|
+
if (!(inner === 'get' || inner === 'getState' || inner.endsWith('.getState')))
|
|
3601
|
+
return null;
|
|
3602
|
+
if (JS_FAMILY.has(ref.language)) {
|
|
3603
|
+
return resolveStoreAction(inner, method, ref, context);
|
|
3604
|
+
}
|
|
3605
|
+
const callables = context
|
|
3606
|
+
.getNodesByName(method)
|
|
3607
|
+
.filter((n) => (n.kind === 'function' || n.kind === 'method') && sameLanguageFamily(n.language, ref.language) && n.id !== ref.fromNodeId);
|
|
3608
|
+
if (callables.length !== 1)
|
|
3609
|
+
return null;
|
|
3610
|
+
return { original: ref, targetNodeId: callables[0].id, confidence: 0.6, resolvedBy: 'exact-match' };
|
|
3611
|
+
}
|
|
3612
|
+
/** Resolve the implementation inside the identified store, not a namesake or
|
|
3613
|
+
* an interface signature elsewhere in the project. Import resolution already
|
|
3614
|
+
* follows aliases/barrels; containment already excludes nested action locals. */
|
|
3615
|
+
function resolveStoreAction(inner, member, ref, context, selector = false) {
|
|
3616
|
+
let holders;
|
|
3617
|
+
if (inner === 'get' || inner === 'getState') {
|
|
3618
|
+
const caller = context.getNodeById?.(ref.fromNodeId);
|
|
3619
|
+
if (!caller)
|
|
3620
|
+
return null;
|
|
3621
|
+
holders = context.getNodesInFile(ref.filePath).filter((n) => {
|
|
3622
|
+
if ((n.kind !== 'constant' && n.kind !== 'variable') || !rangeWithin(caller, n))
|
|
3623
|
+
return false;
|
|
3624
|
+
const source = context.readFile(n.filePath)?.split('\n').slice(n.startLine - 1, caller.startLine).join('\n') ?? '';
|
|
3625
|
+
// The accessor must actually be a parameter of the enclosing factory.
|
|
3626
|
+
return new RegExp(`\\(\\s*[\\w$]+\\s*,\\s*${inner}\\s*(?:,\\s*[\\w$]+\\s*)?\\)\\s*=>`).test(source);
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
else {
|
|
3630
|
+
const name = inner.slice(0, -'.getState'.length);
|
|
3631
|
+
if (!/^[\w$]+$/.test(name))
|
|
3632
|
+
return null;
|
|
3633
|
+
const imported = context.resolveImport?.({ ...ref, referenceName: name, referenceKind: 'references' });
|
|
3634
|
+
const node = imported && context.getNodeById?.(imported.targetNodeId);
|
|
3635
|
+
if (node && importShadowedAt(name, ref, context))
|
|
3636
|
+
return null;
|
|
3637
|
+
holders = node ? [node] : context.getNodesByName(name).filter((n) => n.filePath === ref.filePath && isLexicallyReachable(n, ref, context));
|
|
3638
|
+
}
|
|
3639
|
+
if (holders.length !== 1)
|
|
3640
|
+
return null;
|
|
3641
|
+
const holder = holders[0];
|
|
3642
|
+
if (selector) {
|
|
3643
|
+
// Only a Zustand hook promises to return the selector's result. An
|
|
3644
|
+
// arbitrary function accepting that callback is not a store binding.
|
|
3645
|
+
const text = context.readFile(holder.filePath)?.split('\n').slice(holder.startLine - 1, holder.endLine).join('\n') ?? '';
|
|
3646
|
+
const escaped = holder.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3647
|
+
const factory = new RegExp(`\\b(?:const|let)\\s+${escaped}\\s*=\\s*([\\w$]+)\\s*[<(]`).exec(text)?.[1];
|
|
3648
|
+
if (!factory || !context.getImportMappings(holder.filePath, holder.language).some(m => m.localName === factory && m.source === 'zustand' && (m.exportedName === 'create' || m.isDefault)))
|
|
3649
|
+
return null;
|
|
3650
|
+
}
|
|
3651
|
+
return resolveObjectLiteralMember(holder, member, ref, context, 0.9, 'instance-method');
|
|
3652
|
+
}
|
|
3653
|
+
// Eligibility is a file property, not a call-site property. Cache both answers
|
|
3654
|
+
// within the same stable-source window as the resolver's file cache; sync drops
|
|
3655
|
+
// it via clearNameMatcherMemos. Keep only booleans, FIFO-capped like PATTERN_MEMO
|
|
3656
|
+
// to avoid per-hit LRU churn. Eviction merely repeats the source scan.
|
|
3657
|
+
const GET_STATE_FILES = new WeakMap();
|
|
3658
|
+
const GET_STATE_FILES_CAP = 8192;
|
|
3659
|
+
/** A const destructuring is a bound reference, so it is eligible even though
|
|
3660
|
+
* arbitrary locally-bound bare calls must never guess a cross-file target. */
|
|
3661
|
+
function matchDestructuredStoreCall(ref, context) {
|
|
3662
|
+
let files = GET_STATE_FILES.get(context);
|
|
3663
|
+
if (!files) {
|
|
3664
|
+
files = new Map();
|
|
3665
|
+
GET_STATE_FILES.set(context, files);
|
|
3666
|
+
}
|
|
3667
|
+
let eligible = files.get(ref.filePath);
|
|
3668
|
+
let source;
|
|
3669
|
+
if (eligible === undefined) {
|
|
3670
|
+
source = context.readFile(ref.filePath);
|
|
3671
|
+
eligible = source?.includes('.getState') ?? false;
|
|
3672
|
+
if (files.size >= GET_STATE_FILES_CAP) {
|
|
3673
|
+
const oldest = files.keys().next().value;
|
|
3674
|
+
if (oldest !== undefined)
|
|
3675
|
+
files.delete(oldest);
|
|
3676
|
+
}
|
|
3677
|
+
files.set(ref.filePath, eligible);
|
|
3678
|
+
}
|
|
3679
|
+
if (!eligible)
|
|
3680
|
+
return null;
|
|
3681
|
+
source ??= context.readFile(ref.filePath);
|
|
3682
|
+
if (!source)
|
|
3683
|
+
return null;
|
|
3684
|
+
const lines = source.split('\n');
|
|
3685
|
+
const start = enclosingScopeStartLine(ref, context) - 1;
|
|
3686
|
+
const before = lines.slice(start, ref.line - 1).concat(lines[ref.line - 1].slice(0, ref.column)).join('\n');
|
|
3687
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(before, 'typescript'));
|
|
3688
|
+
const name = ref.referenceName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3689
|
+
const binding = /\bconst\s*\{([^{}]*)\}\s*=\s*([\w$]+)\.getState\s*\(\s*\)/g;
|
|
3690
|
+
// Compare block identities, not just nesting depth: a binding in a sibling
|
|
3691
|
+
// or already-closed block is not in scope at this call.
|
|
3692
|
+
const stackAt = (end) => {
|
|
3693
|
+
const stack = [];
|
|
3694
|
+
for (let i = 0; i < end; i++) {
|
|
3695
|
+
if (code[i] === '{')
|
|
3696
|
+
stack.push(i);
|
|
3697
|
+
else if (code[i] === '}')
|
|
3698
|
+
stack.pop();
|
|
3699
|
+
}
|
|
3700
|
+
return stack;
|
|
3701
|
+
};
|
|
3702
|
+
const callScope = stackAt(code.length);
|
|
3703
|
+
for (const m of [...code.matchAll(binding)].reverse()) {
|
|
3704
|
+
// Plain named bindings only; defaults, rest and computed keys need their
|
|
3705
|
+
// own value tracing rather than a same-name guess.
|
|
3706
|
+
if (!m[1].split(',').some(part => part.trim() === ref.referenceName))
|
|
3707
|
+
continue;
|
|
3708
|
+
const scope = stackAt(m.index);
|
|
3709
|
+
if (!scope.every((pos, i) => callScope[i] === pos))
|
|
3710
|
+
continue;
|
|
3711
|
+
const rest = code.slice(m.index + m[0].length);
|
|
3712
|
+
// Keep the guard when another declaration shadows the captured const.
|
|
3713
|
+
if (new RegExp(`\\b(?:const|let|var|function|class)\\s+(?:${name}\\b|\\{[^}]*\\b${name}\\b)`).test(rest))
|
|
3714
|
+
return null;
|
|
3715
|
+
return resolveStoreAction(`${m[2]}.getState`, ref.referenceName, ref, context);
|
|
3716
|
+
}
|
|
3717
|
+
return null;
|
|
3718
|
+
}
|
|
3719
|
+
/** Bound action names need not have a same-named definition (selectors may
|
|
3720
|
+
* rename them). The resolver's symbol-existence prefilter must allow them. */
|
|
3721
|
+
function matchJsStoreBindingCall(ref, context) {
|
|
3722
|
+
if (!isBareJsCall(ref, context))
|
|
3723
|
+
return null;
|
|
3724
|
+
return matchDestructuredStoreCall(ref, context) ?? matchSelectedStoreCall(ref, context);
|
|
3725
|
+
}
|
|
3726
|
+
/** A qualified untyped chain is useful source evidence, not permission to
|
|
3727
|
+
* infer a property type. Framework resolution runs before this guard. */
|
|
3728
|
+
function isUnresolvedJsMemberCall(ref) {
|
|
3729
|
+
return ref.referenceKind === 'calls' && JS_FAMILY.has(ref.language) &&
|
|
3730
|
+
!/^(?:this|window)\./.test(ref.referenceName) &&
|
|
3731
|
+
/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*){2,}$/.test(ref.referenceName);
|
|
3732
|
+
}
|
|
3733
|
+
const SELECTOR_NAMES = new WeakMap();
|
|
3734
|
+
/** A selector returns the named action from one identified store. Keep the
|
|
3735
|
+
* lexical block identity so closures may capture it but sibling scopes and
|
|
3736
|
+
* shadowing parameters/declarations cannot donate a binding. */
|
|
3737
|
+
function matchSelectedStoreCall(ref, context) {
|
|
3738
|
+
const source = context.readFile(ref.filePath);
|
|
3739
|
+
if (!source?.includes('=>'))
|
|
3740
|
+
return null;
|
|
3741
|
+
let files = SELECTOR_NAMES.get(context);
|
|
3742
|
+
if (!files) {
|
|
3743
|
+
files = new Map();
|
|
3744
|
+
SELECTOR_NAMES.set(context, files);
|
|
3745
|
+
}
|
|
3746
|
+
let names = files.get(ref.filePath);
|
|
3747
|
+
if (!names) {
|
|
3748
|
+
names = new Set([...source.matchAll(/\bconst\s+([\w$]+)\s*=\s*[\w$]+\s*\(\s*(?:\(\s*[\w$]+\s*\)|[\w$]+)\s*=>/g)].map(m => m[1]));
|
|
3749
|
+
files.set(ref.filePath, names);
|
|
3750
|
+
}
|
|
3751
|
+
if (!names.has(ref.referenceName))
|
|
3752
|
+
return null;
|
|
3753
|
+
const name = ref.referenceName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3754
|
+
const lines = source.split('\n');
|
|
3755
|
+
const before = lines.slice(0, ref.line - 1).concat(lines[ref.line - 1].slice(0, ref.column)).join('\n');
|
|
3756
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(before, 'typescript'));
|
|
3757
|
+
const binding = new RegExp(`\\bconst\\s+${name}\\s*=\\s*([\\w$]+)\\s*\\(\\s*(?:\\(\\s*([\\w$]+)\\s*\\)|([\\w$]+))\\s*=>\\s*([\\w$]+)\\.([\\w$]+)\\s*\\)`, 'g');
|
|
3758
|
+
const stackAt = (end) => {
|
|
3759
|
+
const stack = [];
|
|
3760
|
+
for (let i = 0; i < end; i++) {
|
|
3761
|
+
if (code[i] === '{')
|
|
3762
|
+
stack.push(i);
|
|
3763
|
+
else if (code[i] === '}')
|
|
3764
|
+
stack.pop();
|
|
3765
|
+
}
|
|
3766
|
+
return stack;
|
|
3767
|
+
};
|
|
3768
|
+
const callScope = stackAt(code.length);
|
|
3769
|
+
for (const m of [...code.matchAll(binding)].reverse()) {
|
|
3770
|
+
if ((m[2] ?? m[3]) !== m[4])
|
|
3771
|
+
continue;
|
|
3772
|
+
if (!stackAt(m.index).every((pos, i) => callScope[i] === pos))
|
|
3773
|
+
continue;
|
|
3774
|
+
const rest = code.slice(m.index + m[0].length);
|
|
3775
|
+
if (new RegExp(`\\b(?:const|let|var|function|class)\\s+(?:${name}\\b|\\{[^}]*\\b${name}\\b)`).test(rest) ||
|
|
3776
|
+
hasParameterBinding(rest, name))
|
|
3777
|
+
return null;
|
|
3778
|
+
return resolveStoreAction(`${m[1]}.getState`, m[5], ref, context, true);
|
|
3779
|
+
}
|
|
3780
|
+
return null;
|
|
3781
|
+
}
|
|
3782
|
+
/** Import resolution names the module binding; a nearer parameter or block
|
|
3783
|
+
* declaration can shadow that binding at this particular call site. */
|
|
3784
|
+
function importShadowedAt(name, ref, context) {
|
|
3785
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3786
|
+
for (const fn of context.getNodesInFile(ref.filePath)) {
|
|
3787
|
+
if ((fn.kind === 'function' || fn.kind === 'method') && fn.startLine <= ref.line && fn.endLine >= ref.line &&
|
|
3788
|
+
fn.signature && hasParameterBinding(`${fn.signature} {`, escaped))
|
|
3789
|
+
return true;
|
|
3790
|
+
}
|
|
3791
|
+
const lines = (context.readFile(ref.filePath) ?? '').split('\n');
|
|
3792
|
+
const before = lines.slice(0, ref.line - 1).concat(lines[ref.line - 1]?.slice(0, ref.column) ?? '').join('\n');
|
|
3793
|
+
const code = (0, strip_comments_1.blankStringContents)((0, strip_comments_1.stripCommentsForRegex)(before, 'typescript'));
|
|
3794
|
+
const stackAt = (end) => {
|
|
3795
|
+
const stack = [];
|
|
3796
|
+
for (let i = 0; i < end; i++) {
|
|
3797
|
+
if (code[i] === '{')
|
|
3798
|
+
stack.push(i);
|
|
3799
|
+
else if (code[i] === '}')
|
|
3800
|
+
stack.pop();
|
|
3801
|
+
}
|
|
3802
|
+
return stack;
|
|
3803
|
+
};
|
|
3804
|
+
const scope = stackAt(code.length);
|
|
3805
|
+
const declarations = new RegExp(`\\b(?:const|let|var|function|class)\\s+(?:${escaped}\\b|\\{[^}]*\\b${escaped}\\b)`, 'g');
|
|
3806
|
+
return [...code.matchAll(declarations)].some(m => stackAt(m.index).every((p, i) => scope[i] === p));
|
|
3807
|
+
}
|
|
3808
|
+
/** Balanced parameter lists also cover function-typed parameters, whose own
|
|
3809
|
+
* parentheses must not make the outer shadow invisible. Conservative when a
|
|
3810
|
+
* parameter's type mentions the same name: leave that call unresolved. */
|
|
3811
|
+
function hasParameterBinding(code, escapedName) {
|
|
3812
|
+
const name = new RegExp(`\\b${escapedName}\\b`);
|
|
3813
|
+
if (new RegExp(`\\b${escapedName}\\s*=>`).test(code))
|
|
3814
|
+
return true;
|
|
3815
|
+
for (let i = 0; i < code.length; i++) {
|
|
3816
|
+
if (code[i] !== '(' || /\b(?:if|while|for|switch|with)\s*$/.test(code.slice(0, i)))
|
|
3817
|
+
continue;
|
|
3818
|
+
let depth = 1, j = i + 1;
|
|
3819
|
+
for (; j < code.length && depth; j++) {
|
|
3820
|
+
if (code[j] === '(')
|
|
3821
|
+
depth++;
|
|
3822
|
+
else if (code[j] === ')')
|
|
3823
|
+
depth--;
|
|
3824
|
+
}
|
|
3825
|
+
if (depth === 0 && name.test(code.slice(i + 1, j - 1)) &&
|
|
3826
|
+
/^\s*(?::[^=;{]*)?(?:=>|\{)/.test(code.slice(j)))
|
|
3827
|
+
return true;
|
|
3828
|
+
}
|
|
3829
|
+
return false;
|
|
3830
|
+
}
|
|
1806
3831
|
/**
|
|
1807
3832
|
* Split a camelCase or PascalCase string into words.
|
|
1808
3833
|
*/
|
|
@@ -1901,6 +3926,7 @@ function findBestMatch(ref, candidates, _context) {
|
|
|
1901
3926
|
if (ref.referenceKind === 'instantiates') {
|
|
1902
3927
|
if (candidate.kind === 'class' ||
|
|
1903
3928
|
candidate.kind === 'struct' ||
|
|
3929
|
+
candidate.kind === 'union' ||
|
|
1904
3930
|
candidate.kind === 'interface') {
|
|
1905
3931
|
score += 25;
|
|
1906
3932
|
}
|
|
@@ -1941,11 +3967,35 @@ function matchFuzzy(ref, context) {
|
|
|
1941
3967
|
const candidates = context.getNodesByLowerName(lowerName);
|
|
1942
3968
|
// Filter to callable kinds only (function, method, class)
|
|
1943
3969
|
const callableKinds = new Set(['function', 'method', 'class']);
|
|
1944
|
-
const callableCandidates =
|
|
3970
|
+
const callableCandidates = candidates.filter((n) => callableKinds.has(n.kind))
|
|
3971
|
+
.filter((n) => (ref.referenceKind !== 'references' && ref.referenceKind !== 'function_ref') ||
|
|
3972
|
+
sameLanguageFamily(n.language, ref.language));
|
|
1945
3973
|
// Prefer same-language matches
|
|
1946
3974
|
const sameLanguageCandidates = callableCandidates.filter(n => n.language === ref.language);
|
|
1947
3975
|
const finalCandidates = sameLanguageCandidates.length > 0 ? sameLanguageCandidates : callableCandidates;
|
|
1948
|
-
|
|
3976
|
+
// Both post-pipeline visibility guards (#1745 language-local + #1719 sealed
|
|
3977
|
+
// module). The sealed-module test rejects the survivor and never filters the
|
|
3978
|
+
// set that produced it: removing a sealed candidate from a crowd would leave
|
|
3979
|
+
// a lone one and manufacture a 0.5 guess out of an ambiguity fuzzy declines.
|
|
3980
|
+
// Also decline a bare JS/TS call whose only survivor is a method or a
|
|
3981
|
+
// cross-file name the file already binds locally (#1714).
|
|
3982
|
+
// A function nested inside another function is only callable from inside
|
|
3983
|
+
// its container (#1230), so a builtin method call (`res.text()`) whose only
|
|
3984
|
+
// same-named project symbol is some file's closure must decline (#1708).
|
|
3985
|
+
// The check sits on the ONE candidate this strategy would commit to, not on
|
|
3986
|
+
// the candidate set: filtering the unreachable ones out of a crowd would
|
|
3987
|
+
// leave a single survivor and hand it every call of that name — on vite,
|
|
3988
|
+
// `import { resolve } from 'node:path'` in a dozen playground configs onto
|
|
3989
|
+
// the one reachable `resolve` method (#1709). Reachability may reject a
|
|
3990
|
+
// unique guess; it must never manufacture one.
|
|
3991
|
+
if (finalCandidates.length === 1 &&
|
|
3992
|
+
isVisibleAcrossFiles(finalCandidates[0], ref, context) &&
|
|
3993
|
+
isCrossFileReachable(finalCandidates[0], ref, context) &&
|
|
3994
|
+
!(isBareJsCall(ref, context) &&
|
|
3995
|
+
(finalCandidates[0].kind === 'method' ||
|
|
3996
|
+
(finalCandidates[0].filePath !== ref.filePath && isLocallyBoundJsName(ref.referenceName, ref.filePath, context)))) &&
|
|
3997
|
+
!(finalCandidates[0].kind === 'method' && isBareGoCall(ref, context)) &&
|
|
3998
|
+
isLexicallyReachable(finalCandidates[0], ref, context)) {
|
|
1949
3999
|
const isCrossLanguage = finalCandidates[0].language !== ref.language;
|
|
1950
4000
|
return {
|
|
1951
4001
|
original: ref,
|
|
@@ -2001,6 +4051,9 @@ function dumpNameMatcherProfile(label) {
|
|
|
2001
4051
|
}
|
|
2002
4052
|
}
|
|
2003
4053
|
function matchReference(ref, context) {
|
|
4054
|
+
return gateLanguageMatch(matchReferenceInner(ref, context), ref, context);
|
|
4055
|
+
}
|
|
4056
|
+
function matchReferenceInner(ref, context) {
|
|
2004
4057
|
// Function-as-value refs (#756) resolve ONLY through the dedicated matcher —
|
|
2005
4058
|
// never the fuzzy/qualified fallthrough below (a wrong callback edge is
|
|
2006
4059
|
// worse than none).
|
|
@@ -2058,6 +4111,48 @@ function matchReference(ref, context) {
|
|
|
2058
4111
|
resolvedBy: 'exact-match',
|
|
2059
4112
|
};
|
|
2060
4113
|
}
|
|
4114
|
+
// Erlang call/fun refs carry the call-site arity (`f/1` — #1610) because
|
|
4115
|
+
// arity is part of the function's identity and every erlang function's
|
|
4116
|
+
// qualifiedName carries it (`mod::f/1`). Resolve ONLY to a definition of
|
|
4117
|
+
// that exact arity: the call site's own file first (a local call targets its
|
|
4118
|
+
// own module by language semantics; `-import`ed functions ride the
|
|
4119
|
+
// cross-file branch), and when no definition of that arity exists anywhere,
|
|
4120
|
+
// resolve to NOTHING rather than a sibling arity — the real target may be
|
|
4121
|
+
// macro-generated or out of repo, and a wrong-arity edge is worse than none.
|
|
4122
|
+
if (ref.language === 'erlang' &&
|
|
4123
|
+
!ref.referenceName.includes('::') &&
|
|
4124
|
+
(ref.referenceKind === 'calls' || ref.referenceKind === 'references')) {
|
|
4125
|
+
const am = /^(.+)\/(\d{1,3})$/.exec(ref.referenceName);
|
|
4126
|
+
if (am) {
|
|
4127
|
+
// endsWith is length-anchored, so `/1` cannot match `…/11`.
|
|
4128
|
+
const arityTail = `/${am[2]}`;
|
|
4129
|
+
const candidates = context
|
|
4130
|
+
.getNodesByName(am[1])
|
|
4131
|
+
.filter((n) => n.language === 'erlang' && n.kind === 'function' && n.qualifiedName.endsWith(arityTail));
|
|
4132
|
+
if (candidates.length > 0) {
|
|
4133
|
+
const sameFile = candidates.find((n) => n.filePath === ref.filePath);
|
|
4134
|
+
if (sameFile) {
|
|
4135
|
+
return { original: ref, targetNodeId: sameFile.id, confidence: 0.95, resolvedBy: 'exact-match' };
|
|
4136
|
+
}
|
|
4137
|
+
if (candidates.length === 1) {
|
|
4138
|
+
return { original: ref, targetNodeId: candidates[0].id, confidence: 0.8, resolvedBy: 'exact-match' };
|
|
4139
|
+
}
|
|
4140
|
+
const best = findBestMatch(ref, candidates, context);
|
|
4141
|
+
if (best) {
|
|
4142
|
+
const proximity = computePathProximity(ref.filePath, best.filePath);
|
|
4143
|
+
return {
|
|
4144
|
+
original: ref,
|
|
4145
|
+
targetNodeId: best.id,
|
|
4146
|
+
confidence: proximity >= 30 ? 0.7 : 0.4,
|
|
4147
|
+
resolvedBy: 'exact-match',
|
|
4148
|
+
};
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
return null;
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
if (isUnresolvedJsMemberCall(ref))
|
|
4155
|
+
return null;
|
|
2061
4156
|
// Try strategies in order of confidence
|
|
2062
4157
|
let result;
|
|
2063
4158
|
// 0. File path match (e.g., "snippets/drawer-menu.liquid" → file node)
|
|
@@ -2105,6 +4200,16 @@ function matchReference(ref, context) {
|
|
|
2105
4200
|
if (result)
|
|
2106
4201
|
return result;
|
|
2107
4202
|
}
|
|
4203
|
+
// A call-receiver chain the extractor encoded as `<inner>().<method>` for a
|
|
4204
|
+
// language with no chain resolver above (TS/JS, Python — #1683) is a
|
|
4205
|
+
// receiver whose type is unknown. Nothing below may guess for it: the
|
|
4206
|
+
// method-call pattern rejects the parens, exact name never matches, but the
|
|
4207
|
+
// fuzzy strategy splits on `.` and would hand `make().run` to any `run` —
|
|
4208
|
+
// the fabricated edge the encoding exists to prevent.
|
|
4209
|
+
if (ref.referenceName.includes('().') &&
|
|
4210
|
+
(ref.language === 'typescript' || ref.language === 'javascript' || ref.language === 'tsx' || ref.language === 'jsx' || ref.language === 'python')) {
|
|
4211
|
+
return nmTimed('storeAccessorChain', ref, () => matchStoreAccessorChain(ref, context));
|
|
4212
|
+
}
|
|
2108
4213
|
// 2. Method call pattern
|
|
2109
4214
|
result = nmTimed('methodCall', ref, () => matchMethodCall(ref, context));
|
|
2110
4215
|
if (result)
|