@colbymchenry/codegraph-win32-arm64 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph +1 -1
- package/bin/codegraph.cmd +1 -1
- package/lib/dist/.test-build-engine.json +1 -1
- package/lib/dist/.test-build-viewer.json +1 -1
- package/lib/dist/bin/codegraph.d.ts +3 -0
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +507 -702
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/command-supervision.js +1 -57
- package/lib/dist/bin/command-supervision.js.map +1 -1
- package/lib/dist/bin/fatal-handler.js +0 -46
- package/lib/dist/bin/fatal-handler.js.map +1 -1
- package/lib/dist/bin/node-version-check.js +0 -33
- package/lib/dist/bin/node-version-check.js.map +1 -1
- package/lib/dist/bin/uninstall.js +0 -19
- package/lib/dist/bin/uninstall.js.map +1 -1
- package/lib/dist/bin/viewer-gate.js +0 -14
- package/lib/dist/bin/viewer-gate.js.map +1 -1
- package/lib/dist/compile-cache.d.ts +2 -0
- package/lib/dist/compile-cache.d.ts.map +1 -0
- package/lib/dist/compile-cache.js +45 -0
- package/lib/dist/compile-cache.js.map +1 -0
- package/lib/dist/context/formatter.js +3 -66
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +44 -1
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +123 -430
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/context/markers.js +0 -17
- package/lib/dist/context/markers.js.map +1 -1
- package/lib/dist/db/index.d.ts +44 -1
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +123 -395
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +11 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +71 -79
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/name-substring-index.d.ts +63 -0
- package/lib/dist/db/name-substring-index.d.ts.map +1 -0
- package/lib/dist/db/name-substring-index.js +151 -0
- package/lib/dist/db/name-substring-index.js.map +1 -0
- package/lib/dist/db/node-sqlite.d.ts +19 -0
- package/lib/dist/db/node-sqlite.d.ts.map +1 -0
- package/lib/dist/db/node-sqlite.js +23 -0
- package/lib/dist/db/node-sqlite.js.map +1 -0
- package/lib/dist/db/open-error.d.ts +36 -0
- package/lib/dist/db/open-error.d.ts.map +1 -0
- package/lib/dist/db/open-error.js +63 -0
- package/lib/dist/db/open-error.js.map +1 -0
- package/lib/dist/db/parameter-flow-queries.d.ts +120 -0
- package/lib/dist/db/parameter-flow-queries.d.ts.map +1 -0
- package/lib/dist/db/parameter-flow-queries.js +168 -0
- package/lib/dist/db/parameter-flow-queries.js.map +1 -0
- package/lib/dist/db/queries.d.ts +654 -34
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +1466 -1470
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/reference-tail.d.ts +83 -0
- package/lib/dist/db/reference-tail.d.ts.map +1 -0
- package/lib/dist/db/reference-tail.js +68 -0
- package/lib/dist/db/reference-tail.js.map +1 -0
- package/lib/dist/db/schema.sql +18 -2
- package/lib/dist/db/sqlite-adapter.d.ts +18 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +12 -62
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/synthesis-stage.d.ts.map +1 -1
- package/lib/dist/db/synthesis-stage.js +2 -6
- package/lib/dist/db/synthesis-stage.js.map +1 -1
- package/lib/dist/db/wal-valve.js +1 -153
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/db/wsl-shared-index.js +0 -37
- package/lib/dist/db/wsl-shared-index.js.map +1 -1
- package/lib/dist/directory.d.ts +51 -0
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +76 -530
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/engine.d.ts +15 -0
- package/lib/dist/engine.d.ts.map +1 -0
- package/lib/dist/engine.js +35 -0
- package/lib/dist/engine.js.map +1 -0
- package/lib/dist/errors.d.ts +10 -0
- package/lib/dist/errors.d.ts.map +1 -1
- package/lib/dist/errors.js +8 -101
- package/lib/dist/errors.js.map +1 -1
- package/lib/dist/extraction/astro-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/astro-extractor.js +11 -101
- package/lib/dist/extraction/astro-extractor.js.map +1 -1
- package/lib/dist/extraction/cfml-extractor.d.ts +27 -1
- package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/cfml-extractor.js +70 -206
- package/lib/dist/extraction/cfml-extractor.js.map +1 -1
- package/lib/dist/extraction/commonjs-requires.js +0 -31
- package/lib/dist/extraction/commonjs-requires.js.map +1 -1
- package/lib/dist/extraction/dfm-extractor.js +0 -21
- 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 -24
- package/lib/dist/extraction/extraction-version.js.map +1 -1
- package/lib/dist/extraction/function-ref.d.ts +40 -0
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +157 -207
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.js +0 -165
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +73 -4
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +160 -431
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +208 -7
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +594 -1383
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.js +0 -16
- package/lib/dist/extraction/kernel/decode.js.map +1 -1
- package/lib/dist/extraction/kernel/index.d.ts +3 -1
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -1
- package/lib/dist/extraction/kernel/index.js +48 -135
- package/lib/dist/extraction/kernel/index.js.map +1 -1
- package/lib/dist/extraction/kernel/layout.js +42 -76
- package/lib/dist/extraction/kernel/layout.js.map +1 -1
- package/lib/dist/extraction/kernel/loader.d.ts +5 -1
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -1
- package/lib/dist/extraction/kernel/loader.js +0 -37
- package/lib/dist/extraction/kernel/loader.js.map +1 -1
- package/lib/dist/extraction/languages/arkts.js +0 -59
- package/lib/dist/extraction/languages/arkts.js.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.d.ts +125 -28
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +789 -856
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/cfquery.js +0 -9
- package/lib/dist/extraction/languages/cfquery.js.map +1 -1
- package/lib/dist/extraction/languages/cfscript.d.ts +20 -0
- package/lib/dist/extraction/languages/cfscript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/cfscript.js +80 -9
- package/lib/dist/extraction/languages/cfscript.js.map +1 -1
- package/lib/dist/extraction/languages/cobol.js +0 -114
- package/lib/dist/extraction/languages/cobol.js.map +1 -1
- package/lib/dist/extraction/languages/cpp-brace-scopes.d.ts +66 -0
- package/lib/dist/extraction/languages/cpp-brace-scopes.d.ts.map +1 -0
- package/lib/dist/extraction/languages/cpp-brace-scopes.js +343 -0
- package/lib/dist/extraction/languages/cpp-brace-scopes.js.map +1 -0
- package/lib/dist/extraction/languages/cpp-macro-methods.d.ts +41 -0
- package/lib/dist/extraction/languages/cpp-macro-methods.d.ts.map +1 -0
- package/lib/dist/extraction/languages/cpp-macro-methods.js +487 -0
- package/lib/dist/extraction/languages/cpp-macro-methods.js.map +1 -0
- package/lib/dist/extraction/languages/csharp.js +3 -55
- package/lib/dist/extraction/languages/csharp.js.map +1 -1
- package/lib/dist/extraction/languages/dart.d.ts +129 -0
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +517 -162
- 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 +15 -102
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/go.d.ts +48 -0
- package/lib/dist/extraction/languages/go.d.ts.map +1 -1
- package/lib/dist/extraction/languages/go.js +102 -31
- package/lib/dist/extraction/languages/go.js.map +1 -1
- package/lib/dist/extraction/languages/index.js +0 -6
- package/lib/dist/extraction/languages/index.js.map +1 -1
- package/lib/dist/extraction/languages/java.d.ts.map +1 -1
- package/lib/dist/extraction/languages/java.js +67 -78
- package/lib/dist/extraction/languages/java.js.map +1 -1
- package/lib/dist/extraction/languages/javascript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/javascript.js +2 -12
- package/lib/dist/extraction/languages/javascript.js.map +1 -1
- package/lib/dist/extraction/languages/kotlin.d.ts +11 -0
- package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/lib/dist/extraction/languages/kotlin.js +43 -197
- package/lib/dist/extraction/languages/kotlin.js.map +1 -1
- package/lib/dist/extraction/languages/lua.js +2 -39
- package/lib/dist/extraction/languages/lua.js.map +1 -1
- package/lib/dist/extraction/languages/luau.js +0 -14
- package/lib/dist/extraction/languages/luau.js.map +1 -1
- package/lib/dist/extraction/languages/nix.js +0 -16
- package/lib/dist/extraction/languages/nix.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +5 -16
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/pascal-preparse.d.ts +66 -0
- package/lib/dist/extraction/languages/pascal-preparse.d.ts.map +1 -0
- package/lib/dist/extraction/languages/pascal-preparse.js +958 -0
- package/lib/dist/extraction/languages/pascal-preparse.js.map +1 -0
- package/lib/dist/extraction/languages/pascal-system.d.ts +11 -0
- package/lib/dist/extraction/languages/pascal-system.d.ts.map +1 -0
- package/lib/dist/extraction/languages/pascal-system.js +23 -0
- package/lib/dist/extraction/languages/pascal-system.js.map +1 -0
- package/lib/dist/extraction/languages/pascal.d.ts.map +1 -1
- package/lib/dist/extraction/languages/pascal.js +3 -4
- package/lib/dist/extraction/languages/pascal.js.map +1 -1
- package/lib/dist/extraction/languages/php.d.ts +9 -0
- package/lib/dist/extraction/languages/php.d.ts.map +1 -1
- package/lib/dist/extraction/languages/php.js +207 -44
- package/lib/dist/extraction/languages/php.js.map +1 -1
- package/lib/dist/extraction/languages/python.js +2 -20
- package/lib/dist/extraction/languages/python.js.map +1 -1
- package/lib/dist/extraction/languages/r.js +8 -78
- package/lib/dist/extraction/languages/r.js.map +1 -1
- package/lib/dist/extraction/languages/ruby.d.ts.map +1 -1
- package/lib/dist/extraction/languages/ruby.js +17 -25
- package/lib/dist/extraction/languages/ruby.js.map +1 -1
- package/lib/dist/extraction/languages/rust-macro-calls.d.ts +32 -0
- package/lib/dist/extraction/languages/rust-macro-calls.d.ts.map +1 -0
- package/lib/dist/extraction/languages/rust-macro-calls.js +306 -0
- package/lib/dist/extraction/languages/rust-macro-calls.js.map +1 -0
- package/lib/dist/extraction/languages/rust.d.ts +10 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +15 -47
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/languages/scala.js +5 -41
- package/lib/dist/extraction/languages/scala.js.map +1 -1
- package/lib/dist/extraction/languages/solidity.js +1 -82
- package/lib/dist/extraction/languages/solidity.js.map +1 -1
- package/lib/dist/extraction/languages/swift.js +3 -47
- package/lib/dist/extraction/languages/swift.js.map +1 -1
- package/lib/dist/extraction/languages/terraform.js +6 -152
- package/lib/dist/extraction/languages/terraform.js.map +1 -1
- package/lib/dist/extraction/languages/typescript.d.ts +64 -0
- package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/typescript.js +73 -49
- package/lib/dist/extraction/languages/typescript.js.map +1 -1
- package/lib/dist/extraction/languages/vbnet.d.ts.map +1 -1
- package/lib/dist/extraction/languages/vbnet.js +9 -42
- package/lib/dist/extraction/languages/vbnet.js.map +1 -1
- package/lib/dist/extraction/lazy-frameworks.d.ts +15 -0
- package/lib/dist/extraction/lazy-frameworks.d.ts.map +1 -0
- package/lib/dist/extraction/lazy-frameworks.js +8 -0
- package/lib/dist/extraction/lazy-frameworks.js.map +1 -0
- package/lib/dist/extraction/liquid-extractor.d.ts +29 -3
- package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/liquid-extractor.js +89 -148
- package/lib/dist/extraction/liquid-extractor.js.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.js +0 -78
- package/lib/dist/extraction/mybatis-extractor.js.map +1 -1
- package/lib/dist/extraction/parse-budget.d.ts +42 -7
- package/lib/dist/extraction/parse-budget.d.ts.map +1 -1
- package/lib/dist/extraction/parse-budget.js +39 -15
- package/lib/dist/extraction/parse-budget.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +29 -17
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +49 -193
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.d.ts +1 -1
- package/lib/dist/extraction/parse-worker.d.ts.map +1 -1
- package/lib/dist/extraction/parse-worker.js +5 -58
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/razor-extractor.d.ts +9 -0
- package/lib/dist/extraction/razor-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/razor-extractor.js +45 -69
- package/lib/dist/extraction/razor-extractor.js.map +1 -1
- package/lib/dist/extraction/razor-script.d.ts +23 -0
- package/lib/dist/extraction/razor-script.d.ts.map +1 -0
- package/lib/dist/extraction/razor-script.js +244 -0
- package/lib/dist/extraction/razor-script.js.map +1 -0
- package/lib/dist/extraction/sfc-script.d.ts +42 -0
- package/lib/dist/extraction/sfc-script.d.ts.map +1 -1
- package/lib/dist/extraction/sfc-script.js +32 -31
- package/lib/dist/extraction/sfc-script.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +1 -1
- package/lib/dist/extraction/store-worker.d.ts.map +1 -1
- package/lib/dist/extraction/store-worker.js +1 -38
- package/lib/dist/extraction/store-worker.js.map +1 -1
- package/lib/dist/extraction/store-writer.js +2 -34
- package/lib/dist/extraction/store-writer.js.map +1 -1
- package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/svelte-extractor.js +11 -87
- package/lib/dist/extraction/svelte-extractor.js.map +1 -1
- package/lib/dist/extraction/syntax-tokens.d.ts +6 -5
- package/lib/dist/extraction/syntax-tokens.d.ts.map +1 -1
- package/lib/dist/extraction/syntax-tokens.js +4 -152
- package/lib/dist/extraction/syntax-tokens.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.d.ts +37 -1
- package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.js +76 -68
- package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts +102 -22
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.js +0 -7
- package/lib/dist/extraction/tree-sitter-types.js.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +518 -10
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +2118 -2554
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/vue-extractor.d.ts +13 -0
- package/lib/dist/extraction/vue-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/vue-extractor.js +52 -92
- package/lib/dist/extraction/vue-extractor.js.map +1 -1
- package/lib/dist/extraction/vue-options-api.js +0 -32
- package/lib/dist/extraction/vue-options-api.js.map +1 -1
- package/lib/dist/extraction/vue-template-calls.d.ts +37 -0
- package/lib/dist/extraction/vue-template-calls.d.ts.map +1 -0
- package/lib/dist/extraction/vue-template-calls.js +497 -0
- package/lib/dist/extraction/vue-template-calls.js.map +1 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +18 -89
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/file-limits.d.ts +8 -0
- package/lib/dist/file-limits.d.ts.map +1 -1
- package/lib/dist/file-limits.js +13 -28
- package/lib/dist/file-limits.js.map +1 -1
- package/lib/dist/graph/branch-guards.d.ts.map +1 -1
- package/lib/dist/graph/branch-guards.js +4 -251
- package/lib/dist/graph/branch-guards.js.map +1 -1
- package/lib/dist/graph/call-sites.d.ts +12 -0
- package/lib/dist/graph/call-sites.d.ts.map +1 -0
- package/lib/dist/graph/call-sites.js +17 -0
- package/lib/dist/graph/call-sites.js.map +1 -0
- package/lib/dist/graph/cobol-copybooks.d.ts +75 -0
- package/lib/dist/graph/cobol-copybooks.d.ts.map +1 -0
- package/lib/dist/graph/cobol-copybooks.js +45 -0
- package/lib/dist/graph/cobol-copybooks.js.map +1 -0
- package/lib/dist/graph/dead-code.d.ts +26 -4
- package/lib/dist/graph/dead-code.d.ts.map +1 -1
- package/lib/dist/graph/dead-code.js +157 -311
- package/lib/dist/graph/dead-code.js.map +1 -1
- package/lib/dist/graph/dynamic-boundary-report.js +1 -88
- package/lib/dist/graph/dynamic-boundary-report.js.map +1 -1
- package/lib/dist/graph/file-cycles.d.ts +20 -0
- package/lib/dist/graph/file-cycles.d.ts.map +1 -0
- package/lib/dist/graph/file-cycles.js +79 -0
- package/lib/dist/graph/file-cycles.js.map +1 -0
- package/lib/dist/graph/file-drift.d.ts +35 -0
- package/lib/dist/graph/file-drift.d.ts.map +1 -0
- package/lib/dist/graph/file-drift.js +46 -0
- package/lib/dist/graph/file-drift.js.map +1 -0
- package/lib/dist/graph/go-package.d.ts +27 -0
- package/lib/dist/graph/go-package.d.ts.map +1 -0
- package/lib/dist/graph/go-package.js +49 -0
- package/lib/dist/graph/go-package.js.map +1 -0
- package/lib/dist/graph/index.d.ts +2 -0
- package/lib/dist/graph/index.d.ts.map +1 -1
- package/lib/dist/graph/index.js +4 -6
- package/lib/dist/graph/index.js.map +1 -1
- package/lib/dist/graph/named-symbol-flow.d.ts +5 -1
- package/lib/dist/graph/named-symbol-flow.d.ts.map +1 -1
- package/lib/dist/graph/named-symbol-flow.js +82 -223
- package/lib/dist/graph/named-symbol-flow.js.map +1 -1
- package/lib/dist/graph/owning-package.d.ts +59 -0
- package/lib/dist/graph/owning-package.d.ts.map +1 -0
- package/lib/dist/graph/owning-package.js +120 -0
- package/lib/dist/graph/owning-package.js.map +1 -0
- package/lib/dist/graph/queries.d.ts +6 -3
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +4 -137
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/symbol-lookup.d.ts +15 -3
- package/lib/dist/graph/symbol-lookup.d.ts.map +1 -1
- package/lib/dist/graph/symbol-lookup.js +47 -89
- package/lib/dist/graph/symbol-lookup.js.map +1 -1
- package/lib/dist/graph/symbol-references.d.ts +86 -0
- package/lib/dist/graph/symbol-references.d.ts.map +1 -0
- package/lib/dist/graph/symbol-references.js +304 -0
- package/lib/dist/graph/symbol-references.js.map +1 -0
- package/lib/dist/graph/synthesized-hop.d.ts +37 -0
- package/lib/dist/graph/synthesized-hop.d.ts.map +1 -0
- package/lib/dist/graph/synthesized-hop.js +62 -0
- package/lib/dist/graph/synthesized-hop.js.map +1 -0
- package/lib/dist/graph/test-code.d.ts +33 -0
- package/lib/dist/graph/test-code.d.ts.map +1 -0
- package/lib/dist/graph/test-code.js +104 -0
- package/lib/dist/graph/test-code.js.map +1 -0
- package/lib/dist/graph/traversal.d.ts +31 -2
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +96 -226
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/graph/type-hierarchy.js +0 -138
- package/lib/dist/graph/type-hierarchy.js.map +1 -1
- package/lib/dist/index.d.ts +214 -26
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +736 -1112
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.js +0 -39
- package/lib/dist/installer/beta-signup.js.map +1 -1
- package/lib/dist/installer/config-writer.js +0 -24
- package/lib/dist/installer/config-writer.js.map +1 -1
- package/lib/dist/installer/index.d.ts +13 -6
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +27 -160
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/instructions-template.d.ts +16 -1
- package/lib/dist/installer/instructions-template.d.ts.map +1 -1
- package/lib/dist/installer/instructions-template.js +10 -38
- package/lib/dist/installer/instructions-template.js.map +1 -1
- package/lib/dist/installer/targets/antigravity.js +0 -113
- package/lib/dist/installer/targets/antigravity.js.map +1 -1
- package/lib/dist/installer/targets/bob.d.ts +20 -0
- package/lib/dist/installer/targets/bob.d.ts.map +1 -0
- package/lib/dist/installer/targets/bob.js +83 -0
- package/lib/dist/installer/targets/bob.js.map +1 -0
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +1 -185
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +17 -109
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.js +2 -54
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -1
- package/lib/dist/installer/targets/copilot-jetbrains.js +0 -57
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -1
- package/lib/dist/installer/targets/copilot-vscode.js +0 -58
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -1
- package/lib/dist/installer/targets/cursor.js +7 -88
- package/lib/dist/installer/targets/cursor.js.map +1 -1
- package/lib/dist/installer/targets/droid.d.ts +18 -0
- package/lib/dist/installer/targets/droid.d.ts.map +1 -0
- package/lib/dist/installer/targets/droid.js +92 -0
- package/lib/dist/installer/targets/droid.js.map +1 -0
- package/lib/dist/installer/targets/dsh.d.ts +35 -0
- package/lib/dist/installer/targets/dsh.d.ts.map +1 -0
- package/lib/dist/installer/targets/dsh.js +267 -0
- package/lib/dist/installer/targets/dsh.js.map +1 -0
- package/lib/dist/installer/targets/gemini.js +0 -37
- package/lib/dist/installer/targets/gemini.js.map +1 -1
- package/lib/dist/installer/targets/grok.d.ts +25 -0
- package/lib/dist/installer/targets/grok.d.ts.map +1 -0
- package/lib/dist/installer/targets/grok.js +96 -0
- package/lib/dist/installer/targets/grok.js.map +1 -0
- package/lib/dist/installer/targets/hermes.d.ts +19 -7
- package/lib/dist/installer/targets/hermes.d.ts.map +1 -1
- package/lib/dist/installer/targets/hermes.js +218 -214
- package/lib/dist/installer/targets/hermes.js.map +1 -1
- package/lib/dist/installer/targets/json-config.d.ts +45 -0
- package/lib/dist/installer/targets/json-config.d.ts.map +1 -0
- package/lib/dist/installer/targets/json-config.js +128 -0
- package/lib/dist/installer/targets/json-config.js.map +1 -0
- package/lib/dist/installer/targets/kimi.d.ts +21 -0
- package/lib/dist/installer/targets/kimi.d.ts.map +1 -0
- package/lib/dist/installer/targets/kimi.js +97 -0
- package/lib/dist/installer/targets/kimi.js.map +1 -0
- package/lib/dist/installer/targets/kiro.js +1 -41
- package/lib/dist/installer/targets/kiro.js.map +1 -1
- package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
- package/lib/dist/installer/targets/opencode.js +1 -103
- package/lib/dist/installer/targets/opencode.js.map +1 -1
- package/lib/dist/installer/targets/pi.d.ts +24 -0
- package/lib/dist/installer/targets/pi.d.ts.map +1 -0
- package/lib/dist/installer/targets/pi.js +100 -0
- package/lib/dist/installer/targets/pi.js.map +1 -0
- package/lib/dist/installer/targets/qoder.d.ts +23 -0
- package/lib/dist/installer/targets/qoder.d.ts.map +1 -0
- package/lib/dist/installer/targets/qoder.js +83 -0
- package/lib/dist/installer/targets/qoder.js.map +1 -0
- package/lib/dist/installer/targets/qwen.d.ts +21 -0
- package/lib/dist/installer/targets/qwen.d.ts.map +1 -0
- package/lib/dist/installer/targets/qwen.js +115 -0
- package/lib/dist/installer/targets/qwen.js.map +1 -0
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +18 -25
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/shared.d.ts +83 -13
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +201 -131
- package/lib/dist/installer/targets/shared.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +82 -6
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +318 -112
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +1 -1
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/installer/targets/types.js +0 -13
- package/lib/dist/installer/targets/types.js.map +1 -1
- package/lib/dist/installer/targets/windsurf.d.ts +22 -0
- package/lib/dist/installer/targets/windsurf.d.ts.map +1 -0
- package/lib/dist/installer/targets/windsurf.js +90 -0
- package/lib/dist/installer/targets/windsurf.js.map +1 -0
- package/lib/dist/lazy-engine.d.ts +22 -0
- package/lib/dist/lazy-engine.d.ts.map +1 -0
- package/lib/dist/lazy-engine.js +16 -0
- package/lib/dist/lazy-engine.js.map +1 -0
- package/lib/dist/mcp/answer-freshness.js +0 -6
- package/lib/dist/mcp/answer-freshness.js.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +2 -23
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +2 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +9 -85
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-proof.d.ts +19 -0
- package/lib/dist/mcp/daemon-proof.d.ts.map +1 -0
- package/lib/dist/mcp/daemon-proof.js +126 -0
- package/lib/dist/mcp/daemon-proof.js.map +1 -0
- package/lib/dist/mcp/daemon-registry.d.ts +47 -2
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +188 -139
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +69 -0
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +186 -376
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.js +4 -78
- package/lib/dist/mcp/dynamic-boundaries.js.map +1 -1
- package/lib/dist/mcp/early-ppid.js +0 -24
- package/lib/dist/mcp/early-ppid.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +24 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +47 -152
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.js +0 -108
- package/lib/dist/mcp/explore-dedup.js.map +1 -1
- package/lib/dist/mcp/explore-diagnostics.d.ts +6 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -1
- package/lib/dist/mcp/explore-diagnostics.js +8 -116
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -1
- package/lib/dist/mcp/explore-one-symbol.d.ts +77 -0
- package/lib/dist/mcp/explore-one-symbol.d.ts.map +1 -0
- package/lib/dist/mcp/explore-one-symbol.js +431 -0
- package/lib/dist/mcp/explore-one-symbol.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +0 -129
- package/lib/dist/mcp/explore-session-state.js.map +1 -1
- package/lib/dist/mcp/hook-client.d.ts +44 -0
- package/lib/dist/mcp/hook-client.d.ts.map +1 -0
- package/lib/dist/mcp/hook-client.js +202 -0
- package/lib/dist/mcp/hook-client.js.map +1 -0
- package/lib/dist/mcp/index-freshness-worker.js +1 -6
- package/lib/dist/mcp/index-freshness-worker.js.map +1 -1
- package/lib/dist/mcp/index-freshness.js +0 -15
- package/lib/dist/mcp/index-freshness.js.map +1 -1
- package/lib/dist/mcp/index-version-warning.d.ts +21 -0
- package/lib/dist/mcp/index-version-warning.d.ts.map +1 -0
- package/lib/dist/mcp/index-version-warning.js +38 -0
- package/lib/dist/mcp/index-version-warning.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +29 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +131 -300
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +13 -3
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +106 -121
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/opencode-tool-names.d.ts +32 -0
- package/lib/dist/mcp/opencode-tool-names.d.ts.map +1 -0
- package/lib/dist/mcp/opencode-tool-names.js +24 -0
- package/lib/dist/mcp/opencode-tool-names.js.map +1 -0
- package/lib/dist/mcp/ppid-watchdog.js +0 -24
- package/lib/dist/mcp/ppid-watchdog.js.map +1 -1
- package/lib/dist/mcp/process-identity.d.ts +42 -0
- package/lib/dist/mcp/process-identity.d.ts.map +1 -0
- package/lib/dist/mcp/process-identity.js +130 -0
- package/lib/dist/mcp/process-identity.js.map +1 -0
- package/lib/dist/mcp/project-lifecycle.d.ts +6 -0
- package/lib/dist/mcp/project-lifecycle.d.ts.map +1 -1
- package/lib/dist/mcp/project-lifecycle.js +70 -19
- package/lib/dist/mcp/project-lifecycle.js.map +1 -1
- package/lib/dist/mcp/prompt-explore.d.ts +19 -0
- package/lib/dist/mcp/prompt-explore.d.ts.map +1 -0
- package/lib/dist/mcp/prompt-explore.js +6 -0
- package/lib/dist/mcp/prompt-explore.js.map +1 -0
- package/lib/dist/mcp/proxy.d.ts +25 -7
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +145 -274
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +52 -3
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +114 -123
- package/lib/dist/mcp/query-pool.js.map +1 -1
- package/lib/dist/mcp/query-worker.js +24 -36
- package/lib/dist/mcp/query-worker.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +18 -0
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +12 -32
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +46 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +70 -132
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/startup-handshake.js +1 -48
- package/lib/dist/mcp/startup-handshake.js.map +1 -1
- package/lib/dist/mcp/stdin-teardown.js +0 -28
- package/lib/dist/mcp/stdin-teardown.js.map +1 -1
- package/lib/dist/mcp/stdout-teardown.d.ts +26 -0
- package/lib/dist/mcp/stdout-teardown.d.ts.map +1 -0
- package/lib/dist/mcp/stdout-teardown.js +20 -0
- package/lib/dist/mcp/stdout-teardown.js.map +1 -0
- package/lib/dist/mcp/tools.d.ts +157 -18
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +797 -3621
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/transport.d.ts.map +1 -1
- package/lib/dist/mcp/transport.js +4 -96
- package/lib/dist/mcp/transport.js.map +1 -1
- package/lib/dist/mcp/version.d.ts +13 -1
- package/lib/dist/mcp/version.d.ts.map +1 -1
- package/lib/dist/mcp/version.js +19 -21
- package/lib/dist/mcp/version.js.map +1 -1
- package/lib/dist/mcp/writer-lock.d.ts +11 -0
- package/lib/dist/mcp/writer-lock.d.ts.map +1 -1
- package/lib/dist/mcp/writer-lock.js +49 -46
- package/lib/dist/mcp/writer-lock.js.map +1 -1
- package/lib/dist/project-config.d.ts +20 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +31 -140
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/alias-binding.d.ts +7 -0
- package/lib/dist/resolution/alias-binding.d.ts.map +1 -1
- package/lib/dist/resolution/alias-binding.js +7 -56
- package/lib/dist/resolution/alias-binding.js.map +1 -1
- package/lib/dist/resolution/ambient-modules.d.ts +185 -0
- package/lib/dist/resolution/ambient-modules.d.ts.map +1 -0
- package/lib/dist/resolution/ambient-modules.js +732 -0
- package/lib/dist/resolution/ambient-modules.js.map +1 -0
- package/lib/dist/resolution/angular-template-synthesizer.d.ts +48 -1
- package/lib/dist/resolution/angular-template-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/angular-template-synthesizer.js +401 -65
- package/lib/dist/resolution/angular-template-synthesizer.js.map +1 -1
- package/lib/dist/resolution/c-feature-variants.d.ts +40 -0
- package/lib/dist/resolution/c-feature-variants.d.ts.map +1 -0
- package/lib/dist/resolution/c-feature-variants.js +249 -0
- package/lib/dist/resolution/c-feature-variants.js.map +1 -0
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +23 -391
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/c-macro-renames.d.ts +25 -0
- package/lib/dist/resolution/c-macro-renames.d.ts.map +1 -0
- package/lib/dist/resolution/c-macro-renames.js +95 -0
- package/lib/dist/resolution/c-macro-renames.js.map +1 -0
- package/lib/dist/resolution/callback-synthesizer.d.ts +19 -5
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +1395 -1343
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/const-alias-synthesizer.d.ts +48 -0
- package/lib/dist/resolution/const-alias-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/const-alias-synthesizer.js +234 -0
- package/lib/dist/resolution/const-alias-synthesizer.js.map +1 -0
- package/lib/dist/resolution/cooperative-yield.js +0 -27
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/cpp-constructor.d.ts.map +1 -1
- package/lib/dist/resolution/cpp-constructor.js +15 -17
- package/lib/dist/resolution/cpp-constructor.js.map +1 -1
- package/lib/dist/resolution/cpp-includers.d.ts +46 -0
- package/lib/dist/resolution/cpp-includers.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-includers.js +153 -0
- package/lib/dist/resolution/cpp-includers.js.map +1 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts +16 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts.map +1 -1
- package/lib/dist/resolution/cpp-macro-visibility.js +17 -68
- package/lib/dist/resolution/cpp-macro-visibility.js.map +1 -1
- package/lib/dist/resolution/cpp-namespaces.d.ts +54 -0
- package/lib/dist/resolution/cpp-namespaces.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-namespaces.js +151 -0
- package/lib/dist/resolution/cpp-namespaces.js.map +1 -0
- package/lib/dist/resolution/cpp-raw-strings.d.ts +33 -0
- package/lib/dist/resolution/cpp-raw-strings.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-raw-strings.js +167 -0
- package/lib/dist/resolution/cpp-raw-strings.js.map +1 -0
- package/lib/dist/resolution/cpp-supertypes.d.ts +118 -0
- package/lib/dist/resolution/cpp-supertypes.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-supertypes.js +322 -0
- package/lib/dist/resolution/cpp-supertypes.js.map +1 -0
- package/lib/dist/resolution/cpp-template-instantiations.d.ts +83 -0
- package/lib/dist/resolution/cpp-template-instantiations.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-template-instantiations.js +983 -0
- package/lib/dist/resolution/cpp-template-instantiations.js.map +1 -0
- package/lib/dist/resolution/cpp-type-aliases.d.ts +194 -0
- package/lib/dist/resolution/cpp-type-aliases.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-type-aliases.js +648 -0
- package/lib/dist/resolution/cpp-type-aliases.js.map +1 -0
- package/lib/dist/resolution/dart-libraries.d.ts +75 -0
- package/lib/dist/resolution/dart-libraries.d.ts.map +1 -0
- package/lib/dist/resolution/dart-libraries.js +721 -0
- package/lib/dist/resolution/dart-libraries.js.map +1 -0
- package/lib/dist/resolution/dart-local-scope.d.ts +41 -0
- package/lib/dist/resolution/dart-local-scope.d.ts.map +1 -0
- package/lib/dist/resolution/dart-local-scope.js +565 -0
- package/lib/dist/resolution/dart-local-scope.js.map +1 -0
- package/lib/dist/resolution/event-emitter-synthesizer.d.ts +39 -0
- package/lib/dist/resolution/event-emitter-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/event-emitter-synthesizer.js +656 -0
- package/lib/dist/resolution/event-emitter-synthesizer.js.map +1 -0
- package/lib/dist/resolution/expo-router-synthesizer.js +0 -52
- package/lib/dist/resolution/expo-router-synthesizer.js.map +1 -1
- package/lib/dist/resolution/frameworks/angular-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/angular-router.js +41 -208
- package/lib/dist/resolution/frameworks/angular-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/aspnet-routes.d.ts +62 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.js +382 -0
- package/lib/dist/resolution/frameworks/aspnet-routes.js.map +1 -0
- package/lib/dist/resolution/frameworks/astro.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/astro.js +4 -60
- package/lib/dist/resolution/frameworks/astro.js.map +1 -1
- package/lib/dist/resolution/frameworks/cargo-workspace.d.ts +18 -1
- package/lib/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/cargo-workspace.js +65 -15
- package/lib/dist/resolution/frameworks/cargo-workspace.js.map +1 -1
- package/lib/dist/resolution/frameworks/cics.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/cics.js +7 -33
- package/lib/dist/resolution/frameworks/cics.js.map +1 -1
- package/lib/dist/resolution/frameworks/codeigniter.d.ts +23 -0
- package/lib/dist/resolution/frameworks/codeigniter.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/codeigniter.js +271 -0
- package/lib/dist/resolution/frameworks/codeigniter.js.map +1 -0
- package/lib/dist/resolution/frameworks/component-folder.d.ts +17 -0
- package/lib/dist/resolution/frameworks/component-folder.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/component-folder.js +11 -0
- package/lib/dist/resolution/frameworks/component-folder.js.map +1 -0
- package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/csharp.js +85 -102
- package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
- package/lib/dist/resolution/frameworks/drupal.d.ts +17 -8
- package/lib/dist/resolution/frameworks/drupal.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/drupal.js +377 -142
- package/lib/dist/resolution/frameworks/drupal.js.map +1 -1
- package/lib/dist/resolution/frameworks/elysia.d.ts +38 -0
- package/lib/dist/resolution/frameworks/elysia.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/elysia.js +683 -0
- package/lib/dist/resolution/frameworks/elysia.js.map +1 -0
- package/lib/dist/resolution/frameworks/expo-modules.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/expo-modules.js +8 -88
- package/lib/dist/resolution/frameworks/expo-modules.js.map +1 -1
- package/lib/dist/resolution/frameworks/expo-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/expo-router.js +9 -190
- package/lib/dist/resolution/frameworks/expo-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/express.d.ts +48 -1
- package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +193 -199
- package/lib/dist/resolution/frameworks/express.js.map +1 -1
- package/lib/dist/resolution/frameworks/fabric.js +1 -104
- package/lib/dist/resolution/frameworks/fabric.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +14 -43
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/frameworks/goframe.js +1 -55
- package/lib/dist/resolution/frameworks/goframe.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +14 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +16 -50
- 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 +203 -129
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.js +71 -136
- package/lib/dist/resolution/frameworks/laravel.js.map +1 -1
- package/lib/dist/resolution/frameworks/name-heuristic.js +0 -12
- package/lib/dist/resolution/frameworks/name-heuristic.js.map +1 -1
- package/lib/dist/resolution/frameworks/nestjs.js +2 -199
- package/lib/dist/resolution/frameworks/nestjs.js.map +1 -1
- package/lib/dist/resolution/frameworks/next-proxy.d.ts +67 -0
- package/lib/dist/resolution/frameworks/next-proxy.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/next-proxy.js +239 -0
- package/lib/dist/resolution/frameworks/next-proxy.js.map +1 -0
- package/lib/dist/resolution/frameworks/nextjs.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/nextjs.js +10 -66
- package/lib/dist/resolution/frameworks/nextjs.js.map +1 -1
- package/lib/dist/resolution/frameworks/object-literal.js +0 -21
- package/lib/dist/resolution/frameworks/object-literal.js.map +1 -1
- package/lib/dist/resolution/frameworks/package-deps.d.ts +11 -7
- package/lib/dist/resolution/frameworks/package-deps.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/package-deps.js +35 -26
- package/lib/dist/resolution/frameworks/package-deps.js.map +1 -1
- package/lib/dist/resolution/frameworks/page-component.js +0 -14
- package/lib/dist/resolution/frameworks/page-component.js.map +1 -1
- package/lib/dist/resolution/frameworks/play.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/play.js +26 -34
- package/lib/dist/resolution/frameworks/play.js.map +1 -1
- package/lib/dist/resolution/frameworks/python.js +5 -102
- package/lib/dist/resolution/frameworks/python.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.js +1 -166
- package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-router.d.ts +13 -4
- package/lib/dist/resolution/frameworks/react-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react-router.js +10 -82
- package/lib/dist/resolution/frameworks/react-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/react.d.ts +57 -0
- package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react.js +1449 -191
- package/lib/dist/resolution/frameworks/react.js.map +1 -1
- package/lib/dist/resolution/frameworks/ruby.js +1 -61
- package/lib/dist/resolution/frameworks/ruby.js.map +1 -1
- package/lib/dist/resolution/frameworks/rust.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/rust.js +35 -56
- package/lib/dist/resolution/frameworks/rust.js.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.js +7 -75
- package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
- package/lib/dist/resolution/frameworks/sveltekit-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/sveltekit-router.js +8 -46
- package/lib/dist/resolution/frameworks/sveltekit-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift-objc.js +0 -97
- package/lib/dist/resolution/frameworks/swift-objc.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +0 -97
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/frameworks/tanstack-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/tanstack-router.js +9 -130
- package/lib/dist/resolution/frameworks/tanstack-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/terraform.js +1 -85
- package/lib/dist/resolution/frameworks/terraform.js.map +1 -1
- package/lib/dist/resolution/frameworks/vue-router.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/vue-router.js +11 -134
- package/lib/dist/resolution/frameworks/vue-router.js.map +1 -1
- package/lib/dist/resolution/frameworks/vue.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/vue.js +42 -114
- package/lib/dist/resolution/frameworks/vue.js.map +1 -1
- package/lib/dist/resolution/go-func-field-synthesizer.d.ts +58 -0
- package/lib/dist/resolution/go-func-field-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/go-func-field-synthesizer.js +696 -0
- package/lib/dist/resolution/go-func-field-synthesizer.js.map +1 -0
- package/lib/dist/resolution/go-module.d.ts +23 -7
- package/lib/dist/resolution/go-module.d.ts.map +1 -1
- package/lib/dist/resolution/go-module.js +21 -24
- package/lib/dist/resolution/go-module.js.map +1 -1
- package/lib/dist/resolution/go-stdlib-methods.d.ts +9 -0
- package/lib/dist/resolution/go-stdlib-methods.d.ts.map +1 -0
- package/lib/dist/resolution/go-stdlib-methods.js +224 -0
- package/lib/dist/resolution/go-stdlib-methods.js.map +1 -0
- package/lib/dist/resolution/goframe-synthesizer.js +2 -53
- package/lib/dist/resolution/goframe-synthesizer.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +278 -29
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +1825 -1396
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +517 -6
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +1604 -1042
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/js-builtins.d.ts +23 -0
- package/lib/dist/resolution/js-builtins.d.ts.map +1 -1
- package/lib/dist/resolution/js-builtins.js +34 -14
- package/lib/dist/resolution/js-builtins.js.map +1 -1
- package/lib/dist/resolution/js-class-expressions.d.ts +48 -0
- package/lib/dist/resolution/js-class-expressions.d.ts.map +1 -0
- package/lib/dist/resolution/js-class-expressions.js +25 -0
- package/lib/dist/resolution/js-class-expressions.js.map +1 -0
- package/lib/dist/resolution/js-super-calls.d.ts +18 -0
- package/lib/dist/resolution/js-super-calls.d.ts.map +1 -0
- package/lib/dist/resolution/js-super-calls.js +94 -0
- package/lib/dist/resolution/js-super-calls.js.map +1 -0
- package/lib/dist/resolution/jsx-code.d.ts +28 -0
- package/lib/dist/resolution/jsx-code.d.ts.map +1 -0
- package/lib/dist/resolution/jsx-code.js +459 -0
- package/lib/dist/resolution/jsx-code.js.map +1 -0
- package/lib/dist/resolution/lru-cache.d.ts +5 -13
- package/lib/dist/resolution/lru-cache.d.ts.map +1 -1
- package/lib/dist/resolution/lru-cache.js +43 -32
- package/lib/dist/resolution/lru-cache.js.map +1 -1
- package/lib/dist/resolution/memory-budget.js +0 -52
- package/lib/dist/resolution/memory-budget.js.map +1 -1
- package/lib/dist/resolution/module-importers.d.ts +210 -0
- package/lib/dist/resolution/module-importers.d.ts.map +1 -0
- package/lib/dist/resolution/module-importers.js +673 -0
- package/lib/dist/resolution/module-importers.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +986 -7
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +24176 -6745
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/next-router-synthesizer.d.ts +19 -0
- package/lib/dist/resolution/next-router-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/next-router-synthesizer.js +46 -28
- package/lib/dist/resolution/next-router-synthesizer.js.map +1 -1
- package/lib/dist/resolution/override-parameters.d.ts +40 -0
- package/lib/dist/resolution/override-parameters.d.ts.map +1 -0
- package/lib/dist/resolution/override-parameters.js +339 -0
- package/lib/dist/resolution/override-parameters.js.map +1 -0
- package/lib/dist/resolution/parameter-flow.d.ts +218 -0
- package/lib/dist/resolution/parameter-flow.d.ts.map +1 -0
- package/lib/dist/resolution/parameter-flow.js +474 -0
- package/lib/dist/resolution/parameter-flow.js.map +1 -0
- package/lib/dist/resolution/pascal-scope.d.ts +91 -0
- package/lib/dist/resolution/pascal-scope.d.ts.map +1 -0
- package/lib/dist/resolution/pascal-scope.js +961 -0
- package/lib/dist/resolution/pascal-scope.js.map +1 -0
- package/lib/dist/resolution/path-aliases.d.ts +32 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +43 -110
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/php-web-root.d.ts +39 -0
- package/lib/dist/resolution/php-web-root.d.ts.map +1 -0
- package/lib/dist/resolution/php-web-root.js +141 -0
- package/lib/dist/resolution/php-web-root.js.map +1 -0
- package/lib/dist/resolution/project-scans.d.ts +38 -0
- package/lib/dist/resolution/project-scans.d.ts.map +1 -0
- package/lib/dist/resolution/project-scans.js +30 -0
- package/lib/dist/resolution/project-scans.js.map +1 -0
- package/lib/dist/resolution/python-overloads.d.ts +10 -0
- package/lib/dist/resolution/python-overloads.d.ts.map +1 -0
- package/lib/dist/resolution/python-overloads.js +75 -0
- package/lib/dist/resolution/python-overloads.js.map +1 -0
- package/lib/dist/resolution/react-router-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/react-router-synthesizer.js +3 -55
- package/lib/dist/resolution/react-router-synthesizer.js.map +1 -1
- package/lib/dist/resolution/resolver-pool.d.ts +23 -2
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -1
- package/lib/dist/resolution/resolver-pool.js +43 -111
- package/lib/dist/resolution/resolver-pool.js.map +1 -1
- package/lib/dist/resolution/resolver-worker.d.ts +1 -1
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -1
- package/lib/dist/resolution/resolver-worker.js +8 -37
- package/lib/dist/resolution/resolver-worker.js.map +1 -1
- package/lib/dist/resolution/resurrect-ref.d.ts +25 -0
- package/lib/dist/resolution/resurrect-ref.d.ts.map +1 -0
- package/lib/dist/resolution/resurrect-ref.js +19 -0
- package/lib/dist/resolution/resurrect-ref.js.map +1 -0
- package/lib/dist/resolution/ruby-constant-paths.d.ts +56 -0
- package/lib/dist/resolution/ruby-constant-paths.d.ts.map +1 -0
- package/lib/dist/resolution/ruby-constant-paths.js +255 -0
- package/lib/dist/resolution/ruby-constant-paths.js.map +1 -0
- package/lib/dist/resolution/ruby-parameter-flow.d.ts +10 -0
- package/lib/dist/resolution/ruby-parameter-flow.d.ts.map +1 -0
- package/lib/dist/resolution/ruby-parameter-flow.js +801 -0
- package/lib/dist/resolution/ruby-parameter-flow.js.map +1 -0
- package/lib/dist/resolution/rust-scopes.d.ts +120 -0
- package/lib/dist/resolution/rust-scopes.d.ts.map +1 -0
- package/lib/dist/resolution/rust-scopes.js +730 -0
- package/lib/dist/resolution/rust-scopes.js.map +1 -0
- package/lib/dist/resolution/shopify-themes.d.ts +10 -0
- package/lib/dist/resolution/shopify-themes.d.ts.map +1 -0
- package/lib/dist/resolution/shopify-themes.js +19 -0
- package/lib/dist/resolution/shopify-themes.js.map +1 -0
- package/lib/dist/resolution/strip-comments.d.ts +20 -1
- package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
- package/lib/dist/resolution/strip-comments.js +164 -119
- package/lib/dist/resolution/strip-comments.js.map +1 -1
- package/lib/dist/resolution/sveltekit-synthesizer.js +0 -64
- package/lib/dist/resolution/sveltekit-synthesizer.js.map +1 -1
- package/lib/dist/resolution/swift-objc-bridge.js +0 -160
- package/lib/dist/resolution/swift-objc-bridge.js.map +1 -1
- package/lib/dist/resolution/swift-type-visibility.d.ts.map +1 -1
- package/lib/dist/resolution/swift-type-visibility.js +62 -104
- package/lib/dist/resolution/swift-type-visibility.js.map +1 -1
- package/lib/dist/resolution/synth-utils.js +1 -22
- package/lib/dist/resolution/synth-utils.js.map +1 -1
- package/lib/dist/resolution/tanstack-router-synthesizer.js +0 -32
- package/lib/dist/resolution/tanstack-router-synthesizer.js.map +1 -1
- package/lib/dist/resolution/tauri-synthesizer.d.ts +37 -0
- package/lib/dist/resolution/tauri-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/tauri-synthesizer.js +1038 -0
- package/lib/dist/resolution/tauri-synthesizer.js.map +1 -0
- package/lib/dist/resolution/tier-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/tier-synthesizer.js +35 -177
- package/lib/dist/resolution/tier-synthesizer.js.map +1 -1
- package/lib/dist/resolution/type-parameters.d.ts +23 -0
- package/lib/dist/resolution/type-parameters.d.ts.map +1 -1
- package/lib/dist/resolution/type-parameters.js +52 -54
- package/lib/dist/resolution/type-parameters.js.map +1 -1
- package/lib/dist/resolution/types.d.ts +192 -11
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/types.js +0 -47
- package/lib/dist/resolution/types.js.map +1 -1
- package/lib/dist/resolution/vbnet-receivers.d.ts +92 -0
- package/lib/dist/resolution/vbnet-receivers.d.ts.map +1 -0
- package/lib/dist/resolution/vbnet-receivers.js +1482 -0
- package/lib/dist/resolution/vbnet-receivers.js.map +1 -0
- package/lib/dist/resolution/vue-router-synthesizer.js +0 -31
- package/lib/dist/resolution/vue-router-synthesizer.js.map +1 -1
- package/lib/dist/resolution/workspace-packages.d.ts +206 -15
- package/lib/dist/resolution/workspace-packages.d.ts.map +1 -1
- package/lib/dist/resolution/workspace-packages.js +573 -152
- package/lib/dist/resolution/workspace-packages.js.map +1 -1
- package/lib/dist/search/identifier-segments.js +2 -93
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-parser.js +0 -54
- package/lib/dist/search/query-parser.js.map +1 -1
- package/lib/dist/search/query-paths.js +0 -167
- package/lib/dist/search/query-paths.js.map +1 -1
- package/lib/dist/search/query-utils.d.ts +44 -0
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +120 -198
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/git-hooks.d.ts +14 -5
- package/lib/dist/sync/git-hooks.d.ts.map +1 -1
- package/lib/dist/sync/git-hooks.js +118 -65
- package/lib/dist/sync/git-hooks.js.map +1 -1
- package/lib/dist/sync/index.js +0 -14
- package/lib/dist/sync/index.js.map +1 -1
- package/lib/dist/sync/watch-policy.js +0 -45
- package/lib/dist/sync/watch-policy.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +29 -11
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +83 -487
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/sync/worktree.d.ts +7 -2
- package/lib/dist/sync/worktree.d.ts.map +1 -1
- package/lib/dist/sync/worktree.js +24 -97
- package/lib/dist/sync/worktree.js.map +1 -1
- package/lib/dist/telemetry/index.d.ts.map +1 -1
- package/lib/dist/telemetry/index.js +15 -135
- package/lib/dist/telemetry/index.js.map +1 -1
- package/lib/dist/types.d.ts +46 -0
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +15 -44
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.js +0 -19
- package/lib/dist/ui/color.js.map +1 -1
- package/lib/dist/ui/glyphs.js +2 -45
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +0 -21
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +0 -22
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui-server/api/deadcode.d.ts.map +1 -1
- package/lib/dist/ui-server/api/deadcode.js +2 -31
- package/lib/dist/ui-server/api/deadcode.js.map +1 -1
- package/lib/dist/ui-server/api/effects.js +0 -111
- package/lib/dist/ui-server/api/effects.js.map +1 -1
- package/lib/dist/ui-server/api/entrypoints.js +0 -142
- package/lib/dist/ui-server/api/entrypoints.js.map +1 -1
- package/lib/dist/ui-server/api/events.js +0 -145
- package/lib/dist/ui-server/api/events.js.map +1 -1
- package/lib/dist/ui-server/api/file.js +0 -80
- package/lib/dist/ui-server/api/file.js.map +1 -1
- package/lib/dist/ui-server/api/filecode.js +0 -95
- package/lib/dist/ui-server/api/filecode.js.map +1 -1
- package/lib/dist/ui-server/api/flow.js +0 -149
- package/lib/dist/ui-server/api/flow.js.map +1 -1
- package/lib/dist/ui-server/api/hierarchy.js +0 -28
- package/lib/dist/ui-server/api/hierarchy.js.map +1 -1
- package/lib/dist/ui-server/api/index.js +0 -88
- package/lib/dist/ui-server/api/index.js.map +1 -1
- package/lib/dist/ui-server/api/map.d.ts.map +1 -1
- package/lib/dist/ui-server/api/map.js +4 -317
- package/lib/dist/ui-server/api/map.js.map +1 -1
- package/lib/dist/ui-server/api/node.js +0 -111
- package/lib/dist/ui-server/api/node.js.map +1 -1
- package/lib/dist/ui-server/api/nodes.js +0 -16
- package/lib/dist/ui-server/api/nodes.js.map +1 -1
- package/lib/dist/ui-server/api/program.js +0 -90
- package/lib/dist/ui-server/api/program.js.map +1 -1
- package/lib/dist/ui-server/api/respond.js +0 -60
- package/lib/dist/ui-server/api/respond.js.map +1 -1
- package/lib/dist/ui-server/api/route-roots.d.ts.map +1 -1
- package/lib/dist/ui-server/api/route-roots.js +2 -44
- package/lib/dist/ui-server/api/route-roots.js.map +1 -1
- package/lib/dist/ui-server/api/routes.d.ts.map +1 -1
- package/lib/dist/ui-server/api/routes.js +4 -60
- package/lib/dist/ui-server/api/routes.js.map +1 -1
- package/lib/dist/ui-server/api/screens.d.ts.map +1 -1
- package/lib/dist/ui-server/api/screens.js +4 -174
- package/lib/dist/ui-server/api/screens.js.map +1 -1
- package/lib/dist/ui-server/api/search.js +0 -62
- package/lib/dist/ui-server/api/search.js.map +1 -1
- package/lib/dist/ui-server/api/session.js +0 -58
- package/lib/dist/ui-server/api/session.js.map +1 -1
- package/lib/dist/ui-server/api/source.d.ts.map +1 -1
- package/lib/dist/ui-server/api/source.js +0 -161
- package/lib/dist/ui-server/api/source.js.map +1 -1
- package/lib/dist/ui-server/api/stats.js +0 -58
- package/lib/dist/ui-server/api/stats.js.map +1 -1
- package/lib/dist/ui-server/api/steps.d.ts.map +1 -1
- package/lib/dist/ui-server/api/steps.js +5 -381
- package/lib/dist/ui-server/api/steps.js.map +1 -1
- package/lib/dist/ui-server/api/trail-store.d.ts +3 -3
- package/lib/dist/ui-server/api/trail-store.d.ts.map +1 -1
- package/lib/dist/ui-server/api/trail-store.js +24 -106
- package/lib/dist/ui-server/api/trail-store.js.map +1 -1
- package/lib/dist/ui-server/api/trails.d.ts.map +1 -1
- package/lib/dist/ui-server/api/trails.js +19 -94
- package/lib/dist/ui-server/api/trails.js.map +1 -1
- package/lib/dist/ui-server/api/when.js +0 -36
- package/lib/dist/ui-server/api/when.js.map +1 -1
- package/lib/dist/ui-server/api/wire.js +0 -58
- package/lib/dist/ui-server/api/wire.js.map +1 -1
- package/lib/dist/ui-server/assets.js +0 -35
- package/lib/dist/ui-server/assets.js.map +1 -1
- package/lib/dist/ui-server/constants.js +0 -26
- package/lib/dist/ui-server/constants.js.map +1 -1
- package/lib/dist/ui-server/highlight/bounded-tokenize.js +0 -25
- package/lib/dist/ui-server/highlight/bounded-tokenize.js.map +1 -1
- package/lib/dist/ui-server/highlight/index.js +1 -132
- package/lib/dist/ui-server/highlight/index.js.map +1 -1
- package/lib/dist/ui-server/highlight/languages.d.ts +3 -3
- package/lib/dist/ui-server/highlight/languages.js +0 -31
- package/lib/dist/ui-server/highlight/languages.js.map +1 -1
- package/lib/dist/ui-server/highlight/tokenize-worker.js +0 -5
- package/lib/dist/ui-server/highlight/tokenize-worker.js.map +1 -1
- package/lib/dist/ui-server/index.d.ts +25 -0
- package/lib/dist/ui-server/index.d.ts.map +1 -1
- package/lib/dist/ui-server/index.js +35 -103
- package/lib/dist/ui-server/index.js.map +1 -1
- package/lib/dist/ui-server/open-browser.js +0 -34
- package/lib/dist/ui-server/open-browser.js.map +1 -1
- package/lib/dist/ui-server/security.d.ts +5 -0
- package/lib/dist/ui-server/security.d.ts.map +1 -1
- package/lib/dist/ui-server/security.js +11 -147
- package/lib/dist/ui-server/security.js.map +1 -1
- package/lib/dist/ui-server/static.js +0 -41
- package/lib/dist/ui-server/static.js.map +1 -1
- package/lib/dist/upgrade/index.d.ts +18 -5
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +73 -229
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/dist/upgrade/remove-binary.js +2 -67
- package/lib/dist/upgrade/remove-binary.js.map +1 -1
- package/lib/dist/upgrade/update-check.js +1 -81
- package/lib/dist/upgrade/update-check.js.map +1 -1
- package/lib/dist/utils.d.ts +69 -1
- package/lib/dist/utils.d.ts.map +1 -1
- package/lib/dist/utils.js +224 -266
- package/lib/dist/utils.js.map +1 -1
- package/lib/dist/worker-teardown.js +0 -47
- package/lib/dist/worker-teardown.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +2 -2
- package/lib/node_modules/.package-lock.json +4 -4
- package/lib/node_modules/ignore/README.md +138 -8
- package/lib/node_modules/ignore/index.d.ts +56 -20
- package/lib/node_modules/ignore/index.js +1033 -221
- package/lib/node_modules/ignore/legacy.js +871 -178
- package/lib/node_modules/ignore/package.json +10 -4
- package/lib/package.json +14 -8
- package/node.exe +2 -2
- package/package.json +1 -1
package/lib/dist/db/queries.js
CHANGED
|
@@ -1,95 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Database Queries
|
|
4
|
-
*
|
|
5
|
-
* Prepared statements for CRUD operations on the knowledge graph.
|
|
6
|
-
*/
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.QueryBuilder = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
|
|
3
|
+
exports.QueryBuilder = exports.DOMINANT_FILE_SQL = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
|
|
9
4
|
const utils_1 = require("../utils");
|
|
10
5
|
const query_utils_1 = require("../search/query-utils");
|
|
11
6
|
const query_parser_1 = require("../search/query-parser");
|
|
12
7
|
const generated_detection_1 = require("../extraction/generated-detection");
|
|
13
8
|
const identifier_segments_1 = require("../search/identifier-segments");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* mock outputs, …) often have huge in-file edge counts that dwarf the real
|
|
18
|
-
* source — etcd's `rpc.pb.go` has 4× the in-file edges of `server.go`.
|
|
19
|
-
*
|
|
20
|
-
* Path patterns plus, when the caller passes the indexed set, files whose
|
|
21
|
-
* HEADER declares them generated — a `payroll.go` full of generated CRUD has
|
|
22
|
-
* exactly the same edge-density problem as `rpc.pb.go` and nothing in its name
|
|
23
|
-
* to catch it (#1500).
|
|
24
|
-
*/
|
|
9
|
+
const reference_tail_1 = require("./reference-tail");
|
|
10
|
+
const parameter_flow_queries_1 = require("./parameter-flow-queries");
|
|
11
|
+
const name_substring_index_1 = require("./name-substring-index");
|
|
25
12
|
function isLowValueFile(filePath, generated) {
|
|
26
13
|
if (generated?.has(filePath))
|
|
27
14
|
return true;
|
|
28
|
-
|
|
29
|
-
return (/(?:^|\/)(tests?|__tests?__|spec)\//.test(lp) ||
|
|
30
|
-
/_test\.go$/.test(lp) ||
|
|
31
|
-
/(?:^|\/)test_[^/]+\.py$/.test(lp) ||
|
|
32
|
-
/_test\.py$/.test(lp) ||
|
|
33
|
-
/_spec\.rb$/.test(lp) ||
|
|
34
|
-
/_test\.rb$/.test(lp) ||
|
|
35
|
-
/\.(test|spec)\.[jt]sx?$/.test(lp) ||
|
|
36
|
-
/(test|spec|tests)\.(java|kt|scala)$/.test(lp) ||
|
|
37
|
-
/(tests?|spec)\.cs$/.test(lp) ||
|
|
38
|
-
/tests?\.swift$/.test(lp) ||
|
|
39
|
-
/_test\.dart$/.test(lp) ||
|
|
40
|
-
(0, generated_detection_1.isGeneratedFile)(filePath));
|
|
15
|
+
return (0, query_utils_1.isTestFile)(filePath) || /(?:^|\/)__test__\//i.test(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
41
16
|
}
|
|
42
17
|
const SQLITE_PARAM_CHUNK_SIZE = 500;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
* Seeks `idx_edges_target_kind`, so it costs a key lookup per row rather than a
|
|
54
|
-
* join over the whole edge table.
|
|
55
|
-
*/
|
|
18
|
+
const FOLDER_SPECIFIERS = (() => {
|
|
19
|
+
const names = ['.', './'];
|
|
20
|
+
for (let levels = 1; levels <= 12; levels++) {
|
|
21
|
+
const up = Array.from({ length: levels }, () => '..').join('/');
|
|
22
|
+
names.push(up, `${up}/`);
|
|
23
|
+
}
|
|
24
|
+
return names;
|
|
25
|
+
})();
|
|
26
|
+
const RECEIVER_NAME = /^[A-Za-z_$][\w$]*$/;
|
|
56
27
|
const IS_INTERFACE_MEMBER = (alias) => `EXISTS (
|
|
57
28
|
SELECT 1 FROM edges ce JOIN nodes owner ON owner.id = ce.source
|
|
58
29
|
WHERE ce.target = ${alias}.id AND ce.kind = 'contains' AND owner.kind = 'interface'
|
|
59
30
|
)`;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
* Derived rather than picked. `nameMatchBonus`'s prefix arm tops out below
|
|
66
|
-
* `10 + 30 = 40`, and a de-prioritized node also takes the -15 path penalty, so
|
|
67
|
-
* `80 * SCALE - 15 > 40` is what stops a damped WHOLE-QUERY exact match from
|
|
68
|
-
* losing to a mere prefix match. 0.75 clears it (45). Measured on a 62k-node
|
|
69
|
-
* django index: at 0.25 that invariant breaks in practice — `child`, `parent`
|
|
70
|
-
* and `method` lose rank 1 to `children`, `all_parents` and `method_decorator`
|
|
71
|
-
* — while crowd-out removal is almost flat between 0.75 and 0.5 (39 vs 40 of 88
|
|
72
|
-
* peripheral top-10 slots cleared), so a deeper discount buys little and costs
|
|
73
|
-
* the invariant. Pinned by a test.
|
|
74
|
-
*/
|
|
31
|
+
const THROUGH_NAMES = (column) => `(
|
|
32
|
+
${column} IN (SELECT value FROM json_each(?))
|
|
33
|
+
OR (instr(${column}, '.') > 1 AND substr(${column}, 1, instr(${column}, '.') - 1) IN (SELECT value FROM json_each(?)))
|
|
34
|
+
)`;
|
|
75
35
|
exports.DEPRIORITIZED_NAME_BONUS_SCALE = 0.75;
|
|
76
|
-
/**
|
|
77
|
-
* Last segment of a (possibly dotted/qualified) reference name — the part a
|
|
78
|
-
* new symbol's plain node name could match: 'util.greet' → 'greet',
|
|
79
|
-
* 'mod::fn' → 'fn', 'greet' → 'greet'. Written to unresolved_refs.name_tail
|
|
80
|
-
* when a ref is marked failed, so the #1240 retry lookup can match dotted
|
|
81
|
-
* refs against newly-added node names.
|
|
82
|
-
*/
|
|
83
|
-
function referenceNameTail(referenceName) {
|
|
84
|
-
// Erlang refs carry a written arity (`f/1`, `mod::fn/2` — #1610); the tail a
|
|
85
|
-
// new symbol's plain name could match is the arity-less function name.
|
|
86
|
-
const base = referenceName.replace(/\/\d{1,3}$/, '') || referenceName;
|
|
87
|
-
const idx = Math.max(base.lastIndexOf('.'), base.lastIndexOf(':'));
|
|
88
|
-
return idx >= 0 ? base.slice(idx + 1) : base;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Convert database row to Node object
|
|
92
|
-
*/
|
|
93
36
|
function rowToNode(row) {
|
|
94
37
|
return {
|
|
95
38
|
id: row.id,
|
|
@@ -115,9 +58,112 @@ function rowToNode(row) {
|
|
|
115
58
|
updatedAt: row.updated_at,
|
|
116
59
|
};
|
|
117
60
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
61
|
+
function arrayToNode(columns) {
|
|
62
|
+
const at = (column) => columns.indexOf(column);
|
|
63
|
+
const id = at('id');
|
|
64
|
+
const kind = at('kind');
|
|
65
|
+
const name = at('name');
|
|
66
|
+
const qualifiedName = at('qualified_name');
|
|
67
|
+
const filePath = at('file_path');
|
|
68
|
+
const language = at('language');
|
|
69
|
+
const startLine = at('start_line');
|
|
70
|
+
const endLine = at('end_line');
|
|
71
|
+
const startColumn = at('start_column');
|
|
72
|
+
const endColumn = at('end_column');
|
|
73
|
+
const docstring = at('docstring');
|
|
74
|
+
const signature = at('signature');
|
|
75
|
+
const visibility = at('visibility');
|
|
76
|
+
const isExported = at('is_exported');
|
|
77
|
+
const isAsync = at('is_async');
|
|
78
|
+
const isStatic = at('is_static');
|
|
79
|
+
const isAbstract = at('is_abstract');
|
|
80
|
+
const decorators = at('decorators');
|
|
81
|
+
const typeParameters = at('type_parameters');
|
|
82
|
+
const returnType = at('return_type');
|
|
83
|
+
const updatedAt = at('updated_at');
|
|
84
|
+
return (row) => ({
|
|
85
|
+
id: row[id],
|
|
86
|
+
kind: row[kind],
|
|
87
|
+
name: row[name],
|
|
88
|
+
qualifiedName: row[qualifiedName],
|
|
89
|
+
filePath: row[filePath],
|
|
90
|
+
language: row[language],
|
|
91
|
+
startLine: row[startLine],
|
|
92
|
+
endLine: row[endLine],
|
|
93
|
+
startColumn: row[startColumn],
|
|
94
|
+
endColumn: row[endColumn],
|
|
95
|
+
docstring: (row[docstring] ?? undefined),
|
|
96
|
+
signature: (row[signature] ?? undefined),
|
|
97
|
+
visibility: row[visibility],
|
|
98
|
+
isExported: row[isExported] === 1,
|
|
99
|
+
isAsync: row[isAsync] === 1,
|
|
100
|
+
isStatic: row[isStatic] === 1,
|
|
101
|
+
isAbstract: row[isAbstract] === 1,
|
|
102
|
+
decorators: row[decorators] ? (0, utils_1.safeJsonParse)(row[decorators], undefined) : undefined,
|
|
103
|
+
typeParameters: row[typeParameters] ? (0, utils_1.safeJsonParse)(row[typeParameters], undefined) : undefined,
|
|
104
|
+
returnType: (row[returnType] ?? undefined),
|
|
105
|
+
updatedAt: row[updatedAt],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function prepareNodeStatement(db, sql) {
|
|
109
|
+
const stmt = db.prepare(sql);
|
|
110
|
+
const columns = stmt.rowsAsArrays();
|
|
111
|
+
const toNode = (columns ? arrayToNode(columns) : rowToNode);
|
|
112
|
+
return {
|
|
113
|
+
all: (...params) => stmt.all(...params).map(toNode),
|
|
114
|
+
get: (...params) => {
|
|
115
|
+
const row = stmt.get(...params);
|
|
116
|
+
return row === undefined ? undefined : toNode(row);
|
|
117
|
+
},
|
|
118
|
+
*iterate(...params) {
|
|
119
|
+
for (const row of stmt.iterate(...params))
|
|
120
|
+
yield toNode(row);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function fieldFiltersOf(parsed) {
|
|
125
|
+
if (parsed.pathFilters.length === 0 && parsed.nameFilters.length === 0)
|
|
126
|
+
return undefined;
|
|
127
|
+
return {
|
|
128
|
+
paths: parsed.pathFilters.map((p) => p.toLowerCase()),
|
|
129
|
+
names: parsed.nameFilters.map((n) => n.toLowerCase()),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function passesNameFilters(name, filters) {
|
|
133
|
+
if (filters.names.length === 0)
|
|
134
|
+
return true;
|
|
135
|
+
const lowered = name.toLowerCase();
|
|
136
|
+
return filters.names.some((n) => lowered.includes(n));
|
|
137
|
+
}
|
|
138
|
+
function passesFieldFilters(name, filePath, filters) {
|
|
139
|
+
if (filters.paths.length > 0) {
|
|
140
|
+
const lowered = filePath.toLowerCase();
|
|
141
|
+
if (!filters.paths.some((p) => lowered.includes(p)))
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return passesNameFilters(name, filters);
|
|
145
|
+
}
|
|
146
|
+
const PRINTABLE_ASCII = /^[ -~]*$/;
|
|
147
|
+
function fieldFilterSql(filters, params) {
|
|
148
|
+
let sql = '';
|
|
149
|
+
for (const [column, values] of [['nodes.file_path', filters.paths], ['nodes.name', filters.names]]) {
|
|
150
|
+
if (values.length === 0)
|
|
151
|
+
continue;
|
|
152
|
+
const terms = [];
|
|
153
|
+
for (const value of values) {
|
|
154
|
+
if (!PRINTABLE_ASCII.test(value))
|
|
155
|
+
continue;
|
|
156
|
+
terms.push(`instr(lower(${column}), ?) > 0`);
|
|
157
|
+
params.push(value);
|
|
158
|
+
}
|
|
159
|
+
terms.push(`${column} GLOB '*[^ -~]*'`);
|
|
160
|
+
sql += ` AND (${terms.join(' OR ')})`;
|
|
161
|
+
}
|
|
162
|
+
return sql;
|
|
163
|
+
}
|
|
164
|
+
const FAILED_PY_ATTR_REF = `status = 'failed' AND language = 'python'
|
|
165
|
+
AND reference_name NOT GLOB '*.*.*.*'
|
|
166
|
+
AND (reference_name GLOB '*.*.*' OR reference_name GLOB '*().*')`;
|
|
121
167
|
function rowToEdge(row) {
|
|
122
168
|
return {
|
|
123
169
|
source: row.source,
|
|
@@ -129,9 +175,6 @@ function rowToEdge(row) {
|
|
|
129
175
|
provenance: row.provenance,
|
|
130
176
|
};
|
|
131
177
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Convert database row to FileRecord object
|
|
134
|
-
*/
|
|
135
178
|
function rowToFileRecord(row) {
|
|
136
179
|
return {
|
|
137
180
|
path: row.path,
|
|
@@ -145,52 +188,32 @@ function rowToFileRecord(row) {
|
|
|
145
188
|
generated: row.generated === 1,
|
|
146
189
|
};
|
|
147
190
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
191
|
+
exports.DOMINANT_FILE_SQL = `
|
|
192
|
+
SELECT n.file_path AS file_path, COUNT(*) AS edge_count
|
|
193
|
+
FROM edges e
|
|
194
|
+
CROSS JOIN nodes n ON e.source = n.id
|
|
195
|
+
CROSS JOIN nodes m ON e.target = m.id
|
|
196
|
+
WHERE n.file_path = m.file_path
|
|
197
|
+
GROUP BY n.file_path
|
|
198
|
+
ORDER BY edge_count DESC, n.file_path
|
|
199
|
+
`;
|
|
200
|
+
const DOMINANT_FILE_BATCH = 20;
|
|
151
201
|
class QueryBuilder {
|
|
152
202
|
db;
|
|
153
|
-
// Project-name tokens (go.mod / package.json / repo dir), normalized. A query
|
|
154
|
-
// word matching one is dropped from path-relevance scoring — it names the
|
|
155
|
-
// whole project, not a symbol, so it carries no discriminative signal (#720).
|
|
156
|
-
// Set once by the CodeGraph instance; empty by default (no down-weighting).
|
|
157
203
|
projectNameTokens = new Set();
|
|
158
204
|
isDeprioritizedPath;
|
|
159
|
-
// FTS5 availability flag — detected once at construction time (#1532)
|
|
160
205
|
_fts5Available;
|
|
161
|
-
// Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
|
|
162
206
|
nodeCache = new Map();
|
|
163
207
|
maxCacheSize = 1000;
|
|
164
|
-
// getDominantFile()'s answer, tagged with the database change stamp it was
|
|
165
|
-
// computed under (see getChangeStamp). Query-independent, so one value
|
|
166
|
-
// serves every explore until the database changes (#1864).
|
|
167
208
|
dominantFileMemo;
|
|
168
|
-
|
|
209
|
+
readMemos = new Map();
|
|
210
|
+
flowQueries;
|
|
169
211
|
stmts = {};
|
|
170
|
-
// Names whose segments were already written this session — skips re-splitting
|
|
171
|
-
// and re-inserting for the same-named nodes that repeat across files ("get",
|
|
172
|
-
// "render", …). Purely a write-path fast path; INSERT OR IGNORE is the
|
|
173
|
-
// correctness backstop. Bounded so a pathological repo can't grow it forever.
|
|
174
212
|
segmentedNames = new Set();
|
|
175
213
|
static MAX_SEGMENTED_NAMES = 65536;
|
|
176
|
-
// Multi-row INSERT statements, cached per (statement kind × row count). The
|
|
177
|
-
// bulk write path decomposes N rows into a few fixed batch sizes so each
|
|
178
|
-
// size's statement is prepared once and reused — one .run() binds a whole
|
|
179
|
-
// chunk instead of one row, which is where the per-call overhead lives.
|
|
180
|
-
// Row order within and across chunks is the input order, so rowid assignment
|
|
181
|
-
// (and therefore resolution's insertion-order disambiguation) is identical
|
|
182
|
-
// to the one-row-per-run path.
|
|
183
214
|
batchStmts = new Map();
|
|
184
|
-
// Kind-filtered edge reads build their SQL per call (a variable IN list),
|
|
185
|
-
// but from a handful of kind sets: prepare each shape once. Supertype walks
|
|
186
|
-
// and the member-lookup passes issue them per node, and preparing cost
|
|
187
|
-
// about a third of the read.
|
|
188
215
|
edgeKindStmts = new Map();
|
|
189
216
|
static BATCH_SIZES = [128, 32, 8, 1];
|
|
190
|
-
/**
|
|
191
|
-
* Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
|
|
192
|
-
* decomposed greedily into the cached batch sizes. Preserves row order.
|
|
193
|
-
*/
|
|
194
217
|
runBatched(kind, head, tuple, rows) {
|
|
195
218
|
if (rows.length === 0)
|
|
196
219
|
return;
|
|
@@ -221,7 +244,6 @@ class QueryBuilder {
|
|
|
221
244
|
}
|
|
222
245
|
constructor(db) {
|
|
223
246
|
this.db = db;
|
|
224
|
-
// Detect FTS5 availability once (#1532)
|
|
225
247
|
try {
|
|
226
248
|
db.prepare("SELECT * FROM nodes_fts LIMIT 0").get();
|
|
227
249
|
this._fts5Available = true;
|
|
@@ -230,27 +252,40 @@ class QueryBuilder {
|
|
|
230
252
|
this._fts5Available = false;
|
|
231
253
|
}
|
|
232
254
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Swap the underlying connection in place. Used by pool workers'
|
|
235
|
-
* connection recycling (plan §7a.6, writes-under-readers): a long-lived
|
|
236
|
-
* read connection pins WAL checkpoint progress, and the deep WAL that
|
|
237
|
-
* accumulates behind it taxes every main-thread B-tree page operation
|
|
238
|
-
* (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
|
|
239
|
-
* identical hardware). Workers therefore close and reopen their read-only
|
|
240
|
-
* connection at the pool-idle boundary; everything above the connection —
|
|
241
|
-
* this QueryBuilder, the resolver and its warm caches — survives, and only
|
|
242
|
-
* connection-derived state (prepared statements) resets, re-preparing
|
|
243
|
-
* lazily on next use.
|
|
244
|
-
*/
|
|
245
255
|
rebind(db) {
|
|
246
256
|
this.db = db;
|
|
247
257
|
this.stmts = {};
|
|
248
258
|
this.batchStmts.clear();
|
|
249
259
|
this.edgeKindStmts.clear();
|
|
250
|
-
|
|
251
|
-
// different databases report the same one — the memo goes with the old
|
|
252
|
-
// connection, or a worker following a rebuilt index keeps its answer (#1864).
|
|
260
|
+
this.flowQueries = undefined;
|
|
253
261
|
this.dominantFileMemo = undefined;
|
|
262
|
+
this.readMemos.clear();
|
|
263
|
+
this.presentSchema.clear();
|
|
264
|
+
}
|
|
265
|
+
presentSchema = new Set();
|
|
266
|
+
hasSchema(table, column) {
|
|
267
|
+
const key = column ? `${table}.${column}` : table;
|
|
268
|
+
if (this.presentSchema.has(key))
|
|
269
|
+
return true;
|
|
270
|
+
const found = column
|
|
271
|
+
? this.db.prepare('SELECT 1 FROM pragma_table_info(?) WHERE name = ?').get(table, column) !== undefined
|
|
272
|
+
: this.db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
|
|
273
|
+
if (found)
|
|
274
|
+
this.presentSchema.add(key);
|
|
275
|
+
return found;
|
|
276
|
+
}
|
|
277
|
+
memoizedRead(key, compute) {
|
|
278
|
+
if (this.db.inTransaction !== false) {
|
|
279
|
+
this.readMemos.delete(key);
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const stamp = this.getChangeStamp();
|
|
283
|
+
const memo = this.readMemos.get(key);
|
|
284
|
+
if (memo?.stamp === stamp)
|
|
285
|
+
return memo.value;
|
|
286
|
+
const value = compute();
|
|
287
|
+
this.readMemos.set(key, { stamp, value });
|
|
288
|
+
return value;
|
|
254
289
|
}
|
|
255
290
|
edgeKindStmt(sql) {
|
|
256
291
|
let stmt = this.edgeKindStmts.get(sql);
|
|
@@ -262,34 +297,22 @@ class QueryBuilder {
|
|
|
262
297
|
}
|
|
263
298
|
return stmt;
|
|
264
299
|
}
|
|
265
|
-
/** Set the normalized project-name tokens used to down-weight non-discriminative
|
|
266
|
-
* query words in path scoring (#720). Called once when the project opens. */
|
|
267
300
|
setProjectNameTokens(tokens) {
|
|
268
301
|
this.projectNameTokens = tokens;
|
|
269
302
|
}
|
|
270
|
-
/** The normalized project-name tokens (#720); empty if none were derived. */
|
|
271
303
|
getProjectNameTokens() {
|
|
272
304
|
return this.projectNameTokens;
|
|
273
305
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Set the predicate that marks a path as de-prioritized by the project's
|
|
276
|
-
* `codegraph.json` `deprioritize` patterns (#982). Ranking-only: those paths
|
|
277
|
-
* stay indexed and findable, they just stop outranking first-party code.
|
|
278
|
-
* Called once when the project opens; undefined disables the lever.
|
|
279
|
-
*/
|
|
280
306
|
setDeprioritizedPathMatcher(matcher) {
|
|
281
307
|
this.isDeprioritizedPath = matcher;
|
|
282
308
|
}
|
|
283
|
-
/** The `deprioritize` predicate (#982), so other rankers apply the same lever. */
|
|
284
309
|
getDeprioritizedPathMatcher() {
|
|
285
310
|
return this.isDeprioritizedPath;
|
|
286
311
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
* Insert a new node
|
|
292
|
-
*/
|
|
312
|
+
getDeprioritizedPathSnapshot() {
|
|
313
|
+
const matcher = this.isDeprioritizedPath;
|
|
314
|
+
return matcher?.snapshot ? matcher.snapshot() : matcher;
|
|
315
|
+
}
|
|
293
316
|
insertNode(node) {
|
|
294
317
|
if (!this.stmts.insertNode) {
|
|
295
318
|
this.stmts.insertNode = this.db.prepare(`
|
|
@@ -308,7 +331,6 @@ class QueryBuilder {
|
|
|
308
331
|
)
|
|
309
332
|
`);
|
|
310
333
|
}
|
|
311
|
-
// Validate required fields to prevent SQLite bind errors
|
|
312
334
|
if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
|
|
313
335
|
console.error('[CodeGraph] Skipping node with missing required fields:', {
|
|
314
336
|
id: node.id,
|
|
@@ -319,10 +341,6 @@ class QueryBuilder {
|
|
|
319
341
|
});
|
|
320
342
|
return;
|
|
321
343
|
}
|
|
322
|
-
// INSERT OR REPLACE may overwrite a node we have cached. Drop the
|
|
323
|
-
// stale entry so the next getNodeById sees the new row, not the old
|
|
324
|
-
// one (matches the cache-invalidation pattern used by updateNode and
|
|
325
|
-
// deleteNode below).
|
|
326
344
|
this.nodeCache.delete(node.id);
|
|
327
345
|
this.stmts.insertNode.run({
|
|
328
346
|
id: node.id,
|
|
@@ -347,40 +365,19 @@ class QueryBuilder {
|
|
|
347
365
|
returnType: node.returnType ?? null,
|
|
348
366
|
updatedAt: node.updatedAt ?? Date.now(),
|
|
349
367
|
});
|
|
350
|
-
// Segment vocabulary rides the same write path (and transaction) so it can
|
|
351
|
-
// never drift ahead of the nodes it describes. Deletes intentionally leave
|
|
352
|
-
// orphans behind — vocab rows are proposals re-verified against nodes
|
|
353
|
-
// before use, and a full index clears the table at its start. File nodes
|
|
354
|
-
// are excluded: a file's basename duplicates the symbols inside it
|
|
355
|
-
// (state-machine.ts / OrderStateMachine), which double-counts every
|
|
356
|
-
// concept and defeats the singleton-vs-cluster rarity statistics. Import
|
|
357
|
-
// nodes are excluded too (#1144): they're named after module specifiers
|
|
358
|
-
// ("external-unindexed-pkg", "./utils/helpers"), not symbols — an
|
|
359
|
-
// import-only name can never be surfaced (getSegmentMatches requires a
|
|
360
|
-
// real definition), so its rows would only inflate the rarity statistics.
|
|
361
368
|
if (this.isSegmentableKind(node.kind))
|
|
362
369
|
this.insertNameSegments(node.name);
|
|
363
370
|
}
|
|
364
|
-
/** Which node kinds contribute their name to the segment vocabulary — the
|
|
365
|
-
* single gate shared by insertNode, updateNode, and the rebuild page query
|
|
366
|
-
* (getDistinctNodeNames), so the write paths can't drift apart. */
|
|
367
371
|
isSegmentableKind(kind) {
|
|
368
372
|
return kind !== 'file' && kind !== 'import';
|
|
369
373
|
}
|
|
370
|
-
/** Write `name`'s segments into name_segment_vocab (idempotent). */
|
|
371
374
|
insertNameSegments(name) {
|
|
372
375
|
const rows = [];
|
|
373
376
|
this.collectNameSegmentRows(name, rows);
|
|
374
377
|
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
375
378
|
}
|
|
376
|
-
/**
|
|
377
|
-
* Insert multiple nodes in a transaction
|
|
378
|
-
*/
|
|
379
379
|
insertNodes(nodes) {
|
|
380
380
|
this.db.transaction(() => {
|
|
381
|
-
// Bulk path: same semantics as insertNode() per row (validation, cache
|
|
382
|
-
// invalidation, segment vocab), but bound as multi-row INSERTs — the
|
|
383
|
-
// per-.run() call overhead dominates the store phase on full indexes.
|
|
384
381
|
const rows = [];
|
|
385
382
|
const segmentRows = [];
|
|
386
383
|
for (const node of nodes) {
|
|
@@ -431,25 +428,9 @@ class QueryBuilder {
|
|
|
431
428
|
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
|
|
432
429
|
})();
|
|
433
430
|
}
|
|
434
|
-
/**
|
|
435
|
-
* Run `fn` as one transaction. The write helpers called inside join it
|
|
436
|
-
* rather than committing on their own, so a crash part-way leaves none of
|
|
437
|
-
* `fn`'s writes behind.
|
|
438
|
-
*/
|
|
439
431
|
runInTransaction(fn) {
|
|
440
432
|
return this.db.transaction(fn)();
|
|
441
433
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Store one file's whole extraction bundle — nodes, edges, unresolved refs,
|
|
444
|
-
* and the file record — in a SINGLE transaction. The bulk-index path calls
|
|
445
|
-
* this once per file instead of opening one transaction per table (#1015
|
|
446
|
-
* file-order commit discipline is unchanged: callers still invoke it in file
|
|
447
|
-
* order, and row order within is input order).
|
|
448
|
-
*
|
|
449
|
-
* Edges MUST already be endpoint-filtered by the caller (the store path
|
|
450
|
-
* filters to the file's own inserted node ids), so the per-file existence
|
|
451
|
-
* SELECT that insertEdges() pays is skipped here.
|
|
452
|
-
*/
|
|
453
434
|
storeFileBundle(bundle) {
|
|
454
435
|
this.db.transaction(() => {
|
|
455
436
|
this.insertNodes(bundle.nodes);
|
|
@@ -473,10 +454,6 @@ class QueryBuilder {
|
|
|
473
454
|
this.upsertFile(bundle.file);
|
|
474
455
|
})();
|
|
475
456
|
}
|
|
476
|
-
/**
|
|
477
|
-
* Collect (segment, name) rows for a name, honouring the same session-dedupe
|
|
478
|
-
* semantics as insertNameSegments(). Shared by the bulk write paths.
|
|
479
|
-
*/
|
|
480
457
|
collectNameSegmentRows(name, out) {
|
|
481
458
|
if (this.segmentedNames.has(name))
|
|
482
459
|
return;
|
|
@@ -486,9 +463,6 @@ class QueryBuilder {
|
|
|
486
463
|
for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
|
|
487
464
|
out.push([segment, name]);
|
|
488
465
|
}
|
|
489
|
-
/**
|
|
490
|
-
* Update an existing node
|
|
491
|
-
*/
|
|
492
466
|
updateNode(node) {
|
|
493
467
|
if (!this.stmts.updateNode) {
|
|
494
468
|
this.stmts.updateNode = this.db.prepare(`
|
|
@@ -516,9 +490,7 @@ class QueryBuilder {
|
|
|
516
490
|
WHERE id = @id
|
|
517
491
|
`);
|
|
518
492
|
}
|
|
519
|
-
// Invalidate cache before update
|
|
520
493
|
this.nodeCache.delete(node.id);
|
|
521
|
-
// Validate required fields
|
|
522
494
|
if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
|
|
523
495
|
console.error('[CodeGraph] Skipping node update with missing required fields:', node.id);
|
|
524
496
|
return;
|
|
@@ -546,36 +518,20 @@ class QueryBuilder {
|
|
|
546
518
|
returnType: node.returnType ?? null,
|
|
547
519
|
updatedAt: node.updatedAt ?? Date.now(),
|
|
548
520
|
});
|
|
549
|
-
// updateNode is a second real write path to `nodes` — framework
|
|
550
|
-
// post-extract passes rewrite names through it (NestJS route prefixing),
|
|
551
|
-
// and a renamed node's new name must reach the segment vocabulary just
|
|
552
|
-
// like an inserted one's (#1141). Without this the rename left the new
|
|
553
|
-
// name permanently unsearchable: the old name's rows became honest-gate
|
|
554
|
-
// orphans and the only backfill is gated on the vocab being EMPTY.
|
|
555
|
-
// insertNameSegments is idempotent (in-memory set + INSERT OR IGNORE),
|
|
556
|
-
// so no name-changed check is needed.
|
|
557
521
|
if (this.isSegmentableKind(node.kind))
|
|
558
522
|
this.insertNameSegments(node.name);
|
|
559
523
|
}
|
|
560
|
-
/**
|
|
561
|
-
* Delete a node by ID
|
|
562
|
-
*/
|
|
563
524
|
deleteNode(id) {
|
|
564
525
|
if (!this.stmts.deleteNode) {
|
|
565
526
|
this.stmts.deleteNode = this.db.prepare('DELETE FROM nodes WHERE id = ?');
|
|
566
527
|
}
|
|
567
|
-
// Invalidate cache
|
|
568
528
|
this.nodeCache.delete(id);
|
|
569
529
|
this.stmts.deleteNode.run(id);
|
|
570
530
|
}
|
|
571
|
-
/**
|
|
572
|
-
* Delete all nodes for a file
|
|
573
|
-
*/
|
|
574
531
|
deleteNodesByFile(filePath) {
|
|
575
532
|
if (!this.stmts.deleteNodesByFile) {
|
|
576
533
|
this.stmts.deleteNodesByFile = this.db.prepare('DELETE FROM nodes WHERE file_path = ?');
|
|
577
534
|
}
|
|
578
|
-
// Invalidate cache for nodes in this file
|
|
579
535
|
for (const [id, node] of this.nodeCache) {
|
|
580
536
|
if (node.filePath === filePath) {
|
|
581
537
|
this.nodeCache.delete(id);
|
|
@@ -583,32 +539,26 @@ class QueryBuilder {
|
|
|
583
539
|
}
|
|
584
540
|
this.stmts.deleteNodesByFile.run(filePath);
|
|
585
541
|
}
|
|
586
|
-
// ===========================================================================
|
|
587
|
-
// Name-segment vocabulary (prompt-hook graph-derived gate)
|
|
588
|
-
// ===========================================================================
|
|
589
|
-
/** Wipe the segment vocabulary. A full index calls this at its start; the
|
|
590
|
-
* node write path repopulates it as files (re-)index, so the end state is
|
|
591
|
-
* exactly the current names with no orphan rows. */
|
|
592
542
|
clearNameSegmentVocab() {
|
|
593
543
|
this.db.exec('DELETE FROM name_segment_vocab');
|
|
594
544
|
this.segmentedNames.clear();
|
|
595
545
|
}
|
|
596
|
-
|
|
597
|
-
|
|
546
|
+
pruneNameSegmentVocab() {
|
|
547
|
+
this.db.exec("DELETE FROM name_segment_vocab WHERE name NOT IN (SELECT name FROM nodes WHERE kind NOT IN ('file', 'import'))");
|
|
548
|
+
this.segmentedNames.clear();
|
|
549
|
+
}
|
|
598
550
|
isNameSegmentVocabEmpty() {
|
|
551
|
+
if (!this.hasSchema('name_segment_vocab'))
|
|
552
|
+
return true;
|
|
599
553
|
const row = this.db.prepare('SELECT 1 FROM name_segment_vocab LIMIT 1').get();
|
|
600
554
|
return row === undefined;
|
|
601
555
|
}
|
|
602
|
-
/** One page of distinct segmentable node names, for batched vocab rebuilds
|
|
603
|
-
* (file basenames and import specifiers are excluded from the vocab — see
|
|
604
|
-
* insertNode). */
|
|
605
556
|
getDistinctNodeNames(limit, offset) {
|
|
606
557
|
const rows = this.db
|
|
607
558
|
.prepare("SELECT DISTINCT name FROM nodes WHERE kind NOT IN ('file', 'import') ORDER BY name LIMIT ? OFFSET ?")
|
|
608
559
|
.all(limit, offset);
|
|
609
560
|
return rows.map((r) => r.name);
|
|
610
561
|
}
|
|
611
|
-
/** Insert segments for a batch of names in one transaction (vocab heal path). */
|
|
612
562
|
insertNameSegmentsBatch(names) {
|
|
613
563
|
this.db.transaction(() => {
|
|
614
564
|
const rows = [];
|
|
@@ -617,21 +567,8 @@ class QueryBuilder {
|
|
|
617
567
|
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
618
568
|
})();
|
|
619
569
|
}
|
|
620
|
-
/**
|
|
621
|
-
* Names whose segments cover at least `minWords` distinct PROMPT WORDS —
|
|
622
|
-
* the co-occurrence probe behind the prompt hook's medium tier: the words
|
|
623
|
-
* "state" and "machine" both being segments of `OrderStateMachine` is strong
|
|
624
|
-
* evidence the prompt names that symbol in prose. Ordered by coverage.
|
|
625
|
-
*
|
|
626
|
-
* Takes (segment variant → original word) pairs and folds variants back to
|
|
627
|
-
* their word INSIDE the SQL: a name matching both `service` and `services`
|
|
628
|
-
* counts ONE word, not two. Counting raw variants let plural-variant pairs
|
|
629
|
-
* of a single word tie with genuine two-word matches and — because ORDER
|
|
630
|
-
* BY/LIMIT run here, before any JS-side re-check — crowd a real match past
|
|
631
|
-
* the LIMIT on vocab-heavy repos (#1146).
|
|
632
|
-
*/
|
|
633
570
|
getSegmentCoOccurrence(variants, minWords, limit) {
|
|
634
|
-
if (variants.length === 0)
|
|
571
|
+
if (variants.length === 0 || !this.hasSchema('name_segment_vocab'))
|
|
635
572
|
return [];
|
|
636
573
|
const placeholders = variants.map(() => '?').join(', ');
|
|
637
574
|
const whens = variants.map(() => 'WHEN ? THEN ?').join(' ');
|
|
@@ -646,10 +583,8 @@ class QueryBuilder {
|
|
|
646
583
|
.all(...variants.flatMap((v) => [v.segment, v.word]), ...variants.map((v) => v.segment), minWords, limit);
|
|
647
584
|
return rows;
|
|
648
585
|
}
|
|
649
|
-
/** How many distinct names each segment appears in — the rarity signal that
|
|
650
|
-
* separates a discriminative word ("checkout") from a ubiquitous one ("state"). */
|
|
651
586
|
getSegmentNameCounts(segments) {
|
|
652
|
-
if (segments.length === 0)
|
|
587
|
+
if (segments.length === 0 || !this.hasSchema('name_segment_vocab'))
|
|
653
588
|
return new Map();
|
|
654
589
|
const placeholders = segments.map(() => '?').join(', ');
|
|
655
590
|
const rows = this.db
|
|
@@ -658,61 +593,39 @@ class QueryBuilder {
|
|
|
658
593
|
.all(...segments);
|
|
659
594
|
return new Map(rows.map((r) => [r.segment, r.n]));
|
|
660
595
|
}
|
|
661
|
-
/** Names containing the given segment (rare-single-word tier). */
|
|
662
596
|
getNamesForSegment(segment, limit) {
|
|
597
|
+
if (!this.hasSchema('name_segment_vocab'))
|
|
598
|
+
return [];
|
|
663
599
|
const rows = this.db
|
|
664
600
|
.prepare('SELECT name FROM name_segment_vocab WHERE segment = ? ORDER BY length(name) ASC LIMIT ?')
|
|
665
601
|
.all(segment, limit);
|
|
666
602
|
return rows.map((r) => r.name);
|
|
667
603
|
}
|
|
668
|
-
/**
|
|
669
|
-
* Get a node by ID
|
|
670
|
-
*/
|
|
671
604
|
getNodeById(id) {
|
|
672
|
-
// Check cache first
|
|
673
605
|
if (this.nodeCache.has(id)) {
|
|
674
606
|
const cached = this.nodeCache.get(id);
|
|
675
|
-
// Move to end to implement LRU (delete and re-add)
|
|
676
607
|
this.nodeCache.delete(id);
|
|
677
608
|
this.nodeCache.set(id, cached);
|
|
678
609
|
return cached;
|
|
679
610
|
}
|
|
680
611
|
if (!this.stmts.getNodeById) {
|
|
681
|
-
this.stmts.getNodeById = this.db
|
|
612
|
+
this.stmts.getNodeById = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE id = ?');
|
|
682
613
|
}
|
|
683
|
-
const
|
|
684
|
-
if (!
|
|
614
|
+
const node = this.stmts.getNodeById.get(id);
|
|
615
|
+
if (!node) {
|
|
685
616
|
return null;
|
|
686
617
|
}
|
|
687
|
-
const node = rowToNode(row);
|
|
688
618
|
this.cacheNode(node);
|
|
689
619
|
return node;
|
|
690
620
|
}
|
|
691
|
-
/**
|
|
692
|
-
* Batch lookup: fetch many nodes by ID in a single SQL round-trip.
|
|
693
|
-
*
|
|
694
|
-
* Replaces the N+1 pattern in graph traversal where every edge would
|
|
695
|
-
* trigger its own `getNodeById` call. For a function with 50 callers
|
|
696
|
-
* this collapses 50 point reads into one IN-list query (~10-50x
|
|
697
|
-
* faster end-to-end).
|
|
698
|
-
*
|
|
699
|
-
* Returns a Map keyed by id so callers can preserve their own ordering
|
|
700
|
-
* (typically the order edges were returned from the graph). Missing IDs
|
|
701
|
-
* are simply absent from the map.
|
|
702
|
-
*
|
|
703
|
-
* Cache-aware: ids already in the LRU cache are served from memory and
|
|
704
|
-
* the SQL query only touches the misses.
|
|
705
|
-
*/
|
|
706
621
|
getNodesByIds(ids) {
|
|
707
622
|
const out = new Map();
|
|
708
623
|
if (ids.length === 0)
|
|
709
624
|
return out;
|
|
710
|
-
// Serve cache hits first; build the miss list for SQL.
|
|
711
625
|
const misses = [];
|
|
712
626
|
for (const id of ids) {
|
|
713
627
|
const cached = this.nodeCache.get(id);
|
|
714
628
|
if (cached !== undefined) {
|
|
715
|
-
// LRU touch
|
|
716
629
|
this.nodeCache.delete(id);
|
|
717
630
|
this.nodeCache.set(id, cached);
|
|
718
631
|
out.set(id, cached);
|
|
@@ -723,9 +636,6 @@ class QueryBuilder {
|
|
|
723
636
|
}
|
|
724
637
|
if (misses.length === 0)
|
|
725
638
|
return out;
|
|
726
|
-
// Chunk under SQLite's parameter limit (default 999, raised to 32766
|
|
727
|
-
// in better-sqlite3 builds — chunk at 500 for safety across both
|
|
728
|
-
// backends and to keep the query plan simple).
|
|
729
639
|
for (let i = 0; i < misses.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
730
640
|
const chunk = misses.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
731
641
|
const placeholders = chunk.map(() => '?').join(',');
|
|
@@ -747,8 +657,6 @@ class QueryBuilder {
|
|
|
747
657
|
const uniqueIds = [...new Set(ids)];
|
|
748
658
|
for (let i = 0; i < uniqueIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
749
659
|
const chunk = uniqueIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
750
|
-
// Every edge insert checks its endpoints here, a chunk at a time: the
|
|
751
|
-
// full-size statement is prepared once, the final partial chunk ad hoc.
|
|
752
660
|
let stmt;
|
|
753
661
|
if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
|
|
754
662
|
stmt = this.stmts.existingNodeIdsFull ??= this.db.prepare(`SELECT id FROM nodes WHERE id IN (${new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',')})`);
|
|
@@ -763,12 +671,8 @@ class QueryBuilder {
|
|
|
763
671
|
}
|
|
764
672
|
return out;
|
|
765
673
|
}
|
|
766
|
-
/**
|
|
767
|
-
* Add a node to the cache, evicting oldest if needed
|
|
768
|
-
*/
|
|
769
674
|
cacheNode(node) {
|
|
770
675
|
if (this.nodeCache.size >= this.maxCacheSize) {
|
|
771
|
-
// Evict oldest (first) entry
|
|
772
676
|
const firstKey = this.nodeCache.keys().next().value;
|
|
773
677
|
if (firstKey) {
|
|
774
678
|
this.nodeCache.delete(firstKey);
|
|
@@ -776,51 +680,33 @@ class QueryBuilder {
|
|
|
776
680
|
}
|
|
777
681
|
this.nodeCache.set(node.id, node);
|
|
778
682
|
}
|
|
779
|
-
/**
|
|
780
|
-
* Clear the node cache
|
|
781
|
-
*/
|
|
782
683
|
clearCache() {
|
|
783
684
|
this.nodeCache.clear();
|
|
784
685
|
}
|
|
785
|
-
/**
|
|
786
|
-
* Whether any node in `filePath` is exported — `getNodesByFile(f).some((n) =>
|
|
787
|
-
* n.isExported)` as one indexed probe, without decoding the file's nodes.
|
|
788
|
-
*/
|
|
789
686
|
fileHasExportedNode(filePath) {
|
|
790
687
|
if (!this.stmts.fileHasExportedNode) {
|
|
791
688
|
this.stmts.fileHasExportedNode = this.db.prepare('SELECT 1 FROM nodes WHERE file_path = ? AND is_exported = 1 LIMIT 1');
|
|
792
689
|
}
|
|
793
690
|
return this.stmts.fileHasExportedNode.get(filePath) !== undefined;
|
|
794
691
|
}
|
|
795
|
-
/** The exported nodes of a file, in {@link getNodesByFile} order, decoding only those rows. */
|
|
796
692
|
getExportedNodesByFile(filePath) {
|
|
797
693
|
if (!this.stmts.getExportedNodesByFile) {
|
|
798
694
|
this.stmts.getExportedNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? AND is_exported = 1 ORDER BY start_line, id');
|
|
799
695
|
}
|
|
800
696
|
return this.stmts.getExportedNodesByFile.all(filePath).map(rowToNode);
|
|
801
697
|
}
|
|
802
|
-
/** The nodes of a file with one name, in {@link getNodesByFile} order, decoding only those rows. */
|
|
803
698
|
getNodesByFileAndName(filePath, name) {
|
|
804
699
|
if (!this.stmts.getNodesByFileAndName) {
|
|
805
|
-
this.stmts.getNodesByFileAndName = this.db
|
|
700
|
+
this.stmts.getNodesByFileAndName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE file_path = ? AND name = ? ORDER BY start_line, id');
|
|
806
701
|
}
|
|
807
|
-
return this.stmts.getNodesByFileAndName.all(filePath, name)
|
|
702
|
+
return this.stmts.getNodesByFileAndName.all(filePath, name);
|
|
808
703
|
}
|
|
809
|
-
/**
|
|
810
|
-
* Get all nodes in a file
|
|
811
|
-
*/
|
|
812
704
|
getNodesByFile(filePath) {
|
|
813
705
|
if (!this.stmts.getNodesByFile) {
|
|
814
|
-
this.stmts.getNodesByFile = this.db
|
|
706
|
+
this.stmts.getNodesByFile = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line, id');
|
|
815
707
|
}
|
|
816
|
-
|
|
817
|
-
return rows.map(rowToNode);
|
|
708
|
+
return this.stmts.getNodesByFile.all(filePath);
|
|
818
709
|
}
|
|
819
|
-
/**
|
|
820
|
-
* The {@link NodeIdentity} of every node in a file, without decoding whole
|
|
821
|
-
* nodes. Read before a re-index deletes the file, so each incoming
|
|
822
|
-
* cross-file edge can follow its target to the node that replaces it (#2276).
|
|
823
|
-
*/
|
|
824
710
|
getNodeIdentitiesByFile(filePath) {
|
|
825
711
|
if (!this.stmts.getNodeIdentitiesByFile) {
|
|
826
712
|
this.stmts.getNodeIdentitiesByFile = this.db.prepare('SELECT id, kind, name, qualified_name, signature, start_line, start_column FROM nodes WHERE file_path = ?');
|
|
@@ -836,10 +722,6 @@ class QueryBuilder {
|
|
|
836
722
|
startColumn: row.start_column,
|
|
837
723
|
}));
|
|
838
724
|
}
|
|
839
|
-
/**
|
|
840
|
-
* Get all nodes in several files at once — one chunked `IN` query rather than
|
|
841
|
-
* one {@link getNodesByFile} per file (#1975).
|
|
842
|
-
*/
|
|
843
725
|
getNodesByFiles(filePaths) {
|
|
844
726
|
const unique = [...new Set(filePaths)];
|
|
845
727
|
const out = [];
|
|
@@ -854,34 +736,7 @@ class QueryBuilder {
|
|
|
854
736
|
}
|
|
855
737
|
return out;
|
|
856
738
|
}
|
|
857
|
-
/**
|
|
858
|
-
* Find the file that holds the densest concentration of the project's
|
|
859
|
-
* internal call graph — the "core" file. Used by context-builder to
|
|
860
|
-
* boost ranking of symbols in that file's directory (so e.g. sinatra
|
|
861
|
-
* queries surface `lib/sinatra/base.rb`'s `route!` instead of
|
|
862
|
-
* `sinatra-contrib/lib/sinatra/multi_route.rb`'s `route` extension).
|
|
863
|
-
*
|
|
864
|
-
* Returns null if no file has a meaningful concentration (e.g. spread
|
|
865
|
-
* evenly across many files, or empty index).
|
|
866
|
-
*
|
|
867
|
-
* "Internal" = source and target are in the same file. Cross-file
|
|
868
|
-
* edges aren't useful here — they don't tell us which file is the
|
|
869
|
-
* functional center.
|
|
870
|
-
*
|
|
871
|
-
* Excludes test/spec files from candidacy via path-pattern. The agent's
|
|
872
|
-
* typical question is "how does X work", not "how is X tested", so
|
|
873
|
-
* boosting a test file's directory would be a misfire.
|
|
874
|
-
*
|
|
875
|
-
* The answer depends only on the graph, never on the query, and the
|
|
876
|
-
* aggregation behind it scans every edge — seconds on a large index, paid
|
|
877
|
-
* by every generic explore (#1864). So it is memoized per database change
|
|
878
|
-
* stamp: recomputed only after something wrote to the database.
|
|
879
|
-
*/
|
|
880
739
|
getDominantFile() {
|
|
881
|
-
// total_changes() counts writes that are later rolled back, so a result
|
|
882
|
-
// read inside a transaction could outlive a ROLLBACK under an unchanged
|
|
883
|
-
// stamp. Never keep one; `undefined` (a runtime without the getter) is
|
|
884
|
-
// treated the same way.
|
|
885
740
|
if (this.db.inTransaction !== false) {
|
|
886
741
|
this.dominantFileMemo = undefined;
|
|
887
742
|
return this.computeDominantFile();
|
|
@@ -893,16 +748,6 @@ class QueryBuilder {
|
|
|
893
748
|
this.dominantFileMemo = { stamp, value };
|
|
894
749
|
return value;
|
|
895
750
|
}
|
|
896
|
-
/**
|
|
897
|
-
* A value that differs whenever the database content may have changed
|
|
898
|
-
* since the last call, whoever changed it: `total_changes()` counts the
|
|
899
|
-
* rows this connection inserted, updated or deleted, and
|
|
900
|
-
* `PRAGMA data_version` moves when any OTHER connection — another process's
|
|
901
|
-
* sync, a CLI `codegraph index` beside a running MCP server — commits. Both
|
|
902
|
-
* are O(1), so no write path has to remember to invalidate anything.
|
|
903
|
-
* Coarse on purpose: any write, not just one to nodes/edges, forces a
|
|
904
|
-
* recompute, which only costs time, never a stale answer.
|
|
905
|
-
*/
|
|
906
751
|
getChangeStamp() {
|
|
907
752
|
if (!this.stmts.getChangeStamp) {
|
|
908
753
|
this.stmts.getChangeStamp = this.db.prepare('SELECT total_changes() AS changes, (SELECT data_version FROM pragma_data_version) AS version');
|
|
@@ -912,47 +757,29 @@ class QueryBuilder {
|
|
|
912
757
|
}
|
|
913
758
|
computeDominantFile() {
|
|
914
759
|
if (!this.stmts.getDominantFile) {
|
|
915
|
-
|
|
916
|
-
// in code (regex-grade matching that SQL LIKE can't express). The
|
|
917
|
-
// generated-file filter is critical — without it, etcd's
|
|
918
|
-
// `api/etcdserverpb/rpc.pb.go` (1916 in-file edges, generated
|
|
919
|
-
// protobuf stub) outranks the real `server/etcdserver/server.go`
|
|
920
|
-
// (470 edges) by 4×, and the boost would push the agent toward
|
|
921
|
-
// generated code.
|
|
922
|
-
this.stmts.getDominantFile = this.db.prepare(`
|
|
923
|
-
SELECT n.file_path AS file_path, COUNT(*) AS edge_count
|
|
924
|
-
FROM edges e
|
|
925
|
-
JOIN nodes n ON e.source = n.id
|
|
926
|
-
JOIN nodes m ON e.target = m.id
|
|
927
|
-
WHERE n.file_path = m.file_path
|
|
928
|
-
GROUP BY n.file_path
|
|
929
|
-
ORDER BY edge_count DESC
|
|
930
|
-
LIMIT 20
|
|
931
|
-
`);
|
|
760
|
+
this.stmts.getDominantFile = this.db.prepare(exports.DOMINANT_FILE_SQL);
|
|
932
761
|
}
|
|
933
762
|
const rows = this.stmts.getDominantFile.all();
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
|
|
763
|
+
const kept = [];
|
|
764
|
+
for (let i = 0; i < rows.length && kept.length < 2; i += DOMINANT_FILE_BATCH) {
|
|
765
|
+
const batch = rows.slice(i, i + DOMINANT_FILE_BATCH);
|
|
766
|
+
const generated = this.getGeneratedPathsAmong(batch.map(r => r.file_path));
|
|
767
|
+
for (const r of batch) {
|
|
768
|
+
if (isLowValueFile(r.file_path, generated))
|
|
769
|
+
continue;
|
|
770
|
+
kept.push(r);
|
|
771
|
+
if (kept.length === 2)
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (kept.length === 0 || kept[0].edge_count < 20)
|
|
937
776
|
return null;
|
|
938
777
|
return {
|
|
939
|
-
filePath:
|
|
940
|
-
edgeCount:
|
|
941
|
-
nextEdgeCount:
|
|
778
|
+
filePath: kept[0].file_path,
|
|
779
|
+
edgeCount: kept[0].edge_count,
|
|
780
|
+
nextEdgeCount: kept[1]?.edge_count ?? 0,
|
|
942
781
|
};
|
|
943
782
|
}
|
|
944
|
-
/**
|
|
945
|
-
* Find the file that holds the densest concentration of the project's
|
|
946
|
-
* `route` nodes (framework-emitted: Express/Gin/Flask/Rails/Drupal/etc.).
|
|
947
|
-
* Used by handleContext on small repos to inline the project's routing
|
|
948
|
-
* config when the agent's query is about request flow — eliminating the
|
|
949
|
-
* "Glob + Read routes.rb" pattern that beats codegraph on tiny realworld
|
|
950
|
-
* template repos.
|
|
951
|
-
*
|
|
952
|
-
* Excludes test/generated files from candidacy. Returns null if there
|
|
953
|
-
* are fewer than 3 non-test routes total, or if no file holds at least
|
|
954
|
-
* 30% of them (diffuse routing → no single answer file).
|
|
955
|
-
*/
|
|
956
783
|
getTopRouteFile() {
|
|
957
784
|
if (!this.stmts.getTopRouteFile) {
|
|
958
785
|
this.stmts.getTopRouteFile = this.db.prepare(`
|
|
@@ -960,8 +787,7 @@ class QueryBuilder {
|
|
|
960
787
|
FROM nodes
|
|
961
788
|
WHERE kind = 'route'
|
|
962
789
|
GROUP BY file_path
|
|
963
|
-
ORDER BY cnt DESC
|
|
964
|
-
LIMIT 20
|
|
790
|
+
ORDER BY cnt DESC, file_path
|
|
965
791
|
`);
|
|
966
792
|
}
|
|
967
793
|
const rows = this.stmts.getTopRouteFile.all();
|
|
@@ -977,24 +803,12 @@ class QueryBuilder {
|
|
|
977
803
|
return null;
|
|
978
804
|
return { filePath: top.file_path, routeCount: top.cnt, totalRoutes };
|
|
979
805
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
*
|
|
987
|
-
* Also returns the file with the most handler endpoints — used as the
|
|
988
|
-
* "top handler file" to inline source for, so the agent has both the
|
|
989
|
-
* mapping AND the handler implementations.
|
|
990
|
-
*/
|
|
991
|
-
getRoutingManifest(limit = 40) {
|
|
992
|
-
if (!this.stmts.getRoutingManifest) {
|
|
993
|
-
// Edge kind varies across framework resolvers: Spring/Rails/
|
|
994
|
-
// Laravel/Drupal emit `references`, Express emits `calls`. Accept
|
|
995
|
-
// both — the semantic is the same (route → its handler). A screen in
|
|
996
|
-
// a Vue / Svelte / Astro app is served by a `component`.
|
|
997
|
-
this.stmts.getRoutingManifest = this.db.prepare(`
|
|
806
|
+
getRoutingManifest(limit = 40, perRoute = false) {
|
|
807
|
+
const key = perRoute ? 'getRoutingManifestPerRoute' : 'getRoutingManifest';
|
|
808
|
+
if (!this.stmts[key]) {
|
|
809
|
+
const serves = `e.kind IN ('references', 'calls')
|
|
810
|
+
AND h.kind IN ('function', 'method', 'class', 'constant', 'variable', 'component')`;
|
|
811
|
+
this.stmts[key] = this.db.prepare(`
|
|
998
812
|
SELECT
|
|
999
813
|
r.name AS url,
|
|
1000
814
|
r.id AS route_id,
|
|
@@ -1008,19 +822,23 @@ class QueryBuilder {
|
|
|
1008
822
|
JOIN edges e ON e.source = r.id
|
|
1009
823
|
JOIN nodes h ON e.target = h.id
|
|
1010
824
|
WHERE r.kind = 'route'
|
|
1011
|
-
AND
|
|
1012
|
-
AND
|
|
825
|
+
AND ${serves}
|
|
826
|
+
${perRoute ? `AND r.id IN (
|
|
827
|
+
SELECT r2.id FROM nodes r2
|
|
828
|
+
WHERE r2.kind = 'route'
|
|
829
|
+
AND EXISTS (SELECT 1 FROM edges e JOIN nodes h ON e.target = h.id WHERE e.source = r2.id AND ${serves})
|
|
830
|
+
ORDER BY r2.file_path, r2.start_line
|
|
831
|
+
LIMIT ?
|
|
832
|
+
)` : ''}
|
|
1013
833
|
ORDER BY r.file_path, r.start_line
|
|
1014
|
-
LIMIT ?
|
|
834
|
+
${perRoute ? '' : 'LIMIT ?'}
|
|
1015
835
|
`);
|
|
1016
836
|
}
|
|
1017
|
-
const rows = this.stmts.
|
|
1018
|
-
// Drop test/generated handlers — same hygiene as elsewhere.
|
|
837
|
+
const rows = this.stmts[key].all(limit);
|
|
1019
838
|
const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
|
|
1020
839
|
const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
|
|
1021
840
|
if (filtered.length < 3)
|
|
1022
841
|
return null;
|
|
1023
|
-
// Identify the file holding the most handlers (the "primary handler file").
|
|
1024
842
|
const fileCounts = new Map();
|
|
1025
843
|
for (const r of filtered) {
|
|
1026
844
|
fileCounts.set(r.handler_file, (fileCounts.get(r.handler_file) ?? 0) + 1);
|
|
@@ -1049,112 +867,54 @@ class QueryBuilder {
|
|
|
1049
867
|
totalRoutes: filtered.length,
|
|
1050
868
|
};
|
|
1051
869
|
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Get all nodes of a specific kind
|
|
1054
|
-
*/
|
|
1055
870
|
getNodesByKind(kind) {
|
|
1056
871
|
if (!this.stmts.getNodesByKind) {
|
|
1057
|
-
this.stmts.getNodesByKind = this.db
|
|
872
|
+
this.stmts.getNodesByKind = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
|
|
1058
873
|
}
|
|
1059
|
-
|
|
1060
|
-
return rows.map(rowToNode);
|
|
874
|
+
return this.stmts.getNodesByKind.all(kind);
|
|
1061
875
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Stream every node of a kind one at a time (lazy) instead of materializing
|
|
1064
|
-
* them all like {@link getNodesByKind}. For unbounded kinds (`function`,
|
|
1065
|
-
* `method`) on a symbol-dense project the full array is gigabytes; the
|
|
1066
|
-
* dynamic-edge synthesizers only scan-and-filter, so they iterate to keep
|
|
1067
|
-
* memory O(1) in the node count rather than O(nodes) (#610).
|
|
1068
|
-
*/
|
|
1069
876
|
*iterateNodesByKind(kind) {
|
|
1070
|
-
|
|
1071
|
-
// cursor, so a shared statement would conflict across overlapping scans.
|
|
1072
|
-
// Synthesis uses first/last-match precedence and caps: insertion order
|
|
1073
|
-
// changes on sync. idx_nodes_kind streams this canonical order without
|
|
1074
|
-
// materializing/sorting all of a large project's methods in memory.
|
|
1075
|
-
const stmt = this.db.prepare('SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
|
|
1076
|
-
for (const row of stmt.iterate(kind)) {
|
|
1077
|
-
yield rowToNode(row);
|
|
1078
|
-
}
|
|
877
|
+
yield* prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id').iterate(kind);
|
|
1079
878
|
}
|
|
1080
|
-
/**
|
|
1081
|
-
* iterateNodesByKind narrowed to some languages, in the same canonical
|
|
1082
|
-
* order — the ORDER BY is total (`id` is unique), so this yields exactly the
|
|
1083
|
-
* nodes a caller filtering iterateNodesByKind by language would keep, in the
|
|
1084
|
-
* same sequence. A Go pass on a TypeScript monorepo otherwise materialized
|
|
1085
|
-
* every method in the project to find a couple of Go ones.
|
|
1086
|
-
*/
|
|
1087
879
|
*iterateNodesByKindIn(kind, languages) {
|
|
1088
|
-
|
|
880
|
+
const kinds = typeof kind === 'string' ? [kind] : kind;
|
|
881
|
+
if (kinds.length === 0 || languages.length === 0)
|
|
1089
882
|
return;
|
|
1090
|
-
const
|
|
1091
|
-
|
|
883
|
+
const kindTest = kinds.length === 1 ? 'kind = ?' : `kind IN (${kinds.map(() => '?').join(', ')})`;
|
|
884
|
+
const stmt = this.db.prepare(`SELECT * FROM nodes WHERE ${kindTest} AND language IN (${languages.map(() => '?').join(', ')}) ORDER BY file_path, start_line, id`);
|
|
885
|
+
for (const row of stmt.iterate(...kinds, ...languages)) {
|
|
1092
886
|
yield rowToNode(row);
|
|
1093
887
|
}
|
|
1094
888
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
889
|
+
getTopLevelSignaturesMentioning(kinds, languages, names) {
|
|
890
|
+
const marks = (n) => new Array(n).fill('?').join(', ');
|
|
891
|
+
const rows = this.db.prepare(`SELECT signature FROM nodes WHERE kind IN (${marks(kinds.length)}) AND language IN (${marks(languages.length)})
|
|
892
|
+
AND qualified_name = name AND (${names.map(() => 'instr(signature, ?) > 0').join(' OR ')})`).all(...kinds, ...languages, ...names);
|
|
893
|
+
return rows.map((row) => row.signature);
|
|
894
|
+
}
|
|
1098
895
|
getAllNodes() {
|
|
1099
896
|
const rows = this.db.prepare('SELECT * FROM nodes').all();
|
|
1100
897
|
return rows.map(rowToNode);
|
|
1101
898
|
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Stream nodes of one language whose `decorators` JSON array contains
|
|
1104
|
-
* `decorator`. The LIKE on the JSON text is a cheap index-free pre-filter
|
|
1105
|
-
* (a decorator name can appear as a substring of another), so callers must
|
|
1106
|
-
* still exact-check `node.decorators.includes(decorator)`. Exists so the
|
|
1107
|
-
* kotlin expect/actual synthesizer never materializes the whole node table
|
|
1108
|
-
* the way `getAllNodes().filter(...)` did — that array alone OOM'd Node's
|
|
1109
|
-
* default heap on a 2M-node graph (#1212).
|
|
1110
|
-
*/
|
|
1111
899
|
*iterateNodesByLanguageWithDecorator(language, decorator) {
|
|
1112
|
-
// Fresh statement per call — an iterator holds an open cursor (see
|
|
1113
|
-
// iterateNodesByKind).
|
|
1114
900
|
const stmt = this.db.prepare("SELECT * FROM nodes WHERE language = ? AND decorators LIKE '%' || ? || '%' ORDER BY file_path, start_line, id");
|
|
1115
901
|
for (const row of stmt.iterate(language, `"${decorator}"`)) {
|
|
1116
902
|
yield rowToNode(row);
|
|
1117
903
|
}
|
|
1118
904
|
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Distinct languages present in the files table. One indexed aggregate —
|
|
1121
|
-
* lets the dynamic-edge synthesizers skip passes for languages the project
|
|
1122
|
-
* doesn't contain at all (a Kotlin pass has no work on a pure-C repo), so
|
|
1123
|
-
* their cost is zero rather than a full-graph scan that finds nothing (#1212).
|
|
1124
|
-
*/
|
|
1125
905
|
getDistinctFileLanguages() {
|
|
1126
906
|
const rows = this.db.prepare('SELECT DISTINCT language FROM files').all();
|
|
1127
907
|
return new Set(rows.map((r) => r.language));
|
|
1128
908
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
* This is resolution's candidate list, and the ORDER BY is load-bearing for
|
|
1133
|
-
* index correctness, not cosmetic (CG-33). When a reference names a symbol
|
|
1134
|
-
* that several files define and nothing disambiguates them, resolution binds
|
|
1135
|
-
* to the first candidate — so without an ORDER BY the winner was decided by
|
|
1136
|
-
* rowid, i.e. by the order files happened to be WRITTEN. A full index writes
|
|
1137
|
-
* them in scan order; an incremental sync appends each file as it changes, so
|
|
1138
|
-
* the same tree resolved to different edges depending on how the index was
|
|
1139
|
-
* built, and a long-lived synced index drifted away from a rebuild of itself
|
|
1140
|
-
* (measured at 4.3% of distinct edges, mostly `calls`).
|
|
1141
|
-
*
|
|
1142
|
-
* `(file_path, start_line)` is a property of the CODE, so both paths now pick
|
|
1143
|
-
* the same candidate. The sort is paid once per distinct name per resolution
|
|
1144
|
-
* run — ReferenceResolver memoizes this in its nameCache — and the population
|
|
1145
|
-
* is capped by AMBIGUOUS_NAME_CEILING (#999).
|
|
1146
|
-
*/
|
|
909
|
+
hasDecoratedFunction(language, decorator) {
|
|
910
|
+
return !!this.db.prepare(`SELECT 1 FROM nodes WHERE kind = 'function' AND language = ? AND decorators LIKE ? LIMIT 1`).get(language, `%"${decorator}"%`);
|
|
911
|
+
}
|
|
1147
912
|
getNodesByName(name) {
|
|
1148
913
|
if (!this.stmts.getNodesByName) {
|
|
1149
|
-
this.stmts.getNodesByName = this.db
|
|
914
|
+
this.stmts.getNodesByName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line, id');
|
|
1150
915
|
}
|
|
1151
|
-
|
|
1152
|
-
return rows.map(rowToNode);
|
|
916
|
+
return this.stmts.getNodesByName.all(name);
|
|
1153
917
|
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Nodes whose name starts with `prefix`, by index range scan (a LIKE would
|
|
1156
|
-
* skip idx_nodes_name under SQLite's default case-insensitive LIKE).
|
|
1157
|
-
*/
|
|
1158
918
|
getNodesByNamePrefix(prefix, limit = 20) {
|
|
1159
919
|
if (!this.stmts.getNodesByNamePrefix) {
|
|
1160
920
|
this.stmts.getNodesByNamePrefix = this.db.prepare('SELECT * FROM nodes WHERE name >= ? AND name < ? ORDER BY name LIMIT ?');
|
|
@@ -1162,7 +922,12 @@ class QueryBuilder {
|
|
|
1162
922
|
const rows = this.stmts.getNodesByNamePrefix.all(prefix, prefix + '', limit);
|
|
1163
923
|
return rows.map(rowToNode);
|
|
1164
924
|
}
|
|
1165
|
-
|
|
925
|
+
getPhpDocumentRootIncludes(prefix) {
|
|
926
|
+
if (!this.stmts.getPhpDocumentRootIncludes) {
|
|
927
|
+
this.stmts.getPhpDocumentRootIncludes = this.db.prepare("SELECT file_path AS filePath, name FROM nodes WHERE name >= ? AND name < ? AND kind = 'import' AND language = 'php' ORDER BY name, file_path");
|
|
928
|
+
}
|
|
929
|
+
return this.stmts.getPhpDocumentRootIncludes.all(prefix, prefix + '');
|
|
930
|
+
}
|
|
1166
931
|
getFileNodesByNamePrefix(prefix) {
|
|
1167
932
|
if (!this.stmts.getFileNodesByNamePrefix) {
|
|
1168
933
|
this.stmts.getFileNodesByNamePrefix = this.db.prepare("SELECT * FROM nodes WHERE kind = 'file' AND name >= ? AND name < ? ORDER BY name");
|
|
@@ -1170,51 +935,42 @@ class QueryBuilder {
|
|
|
1170
935
|
const rows = this.stmts.getFileNodesByNamePrefix.all(prefix, prefix + '');
|
|
1171
936
|
return rows.map(rowToNode);
|
|
1172
937
|
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
|
|
1175
|
-
*/
|
|
1176
938
|
getNodesByQualifiedNameExact(qualifiedName) {
|
|
1177
939
|
if (!this.stmts.getNodesByQualifiedNameExact) {
|
|
1178
|
-
this.stmts.getNodesByQualifiedNameExact = this.db
|
|
940
|
+
this.stmts.getNodesByQualifiedNameExact = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE qualified_name = ? ORDER BY file_path, start_line, id');
|
|
1179
941
|
}
|
|
1180
|
-
|
|
1181
|
-
return rows.map(rowToNode);
|
|
942
|
+
return this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
|
|
1182
943
|
}
|
|
1183
|
-
/**
|
|
1184
|
-
* Get nodes by name, case-insensitively (seeks the idx_nodes_lower_name
|
|
1185
|
-
* expression index).
|
|
1186
|
-
*
|
|
1187
|
-
* The parameter is lowered in SQL rather than trusted to arrive lowered, so
|
|
1188
|
-
* the lookup means the same thing whatever casing a caller hands it. Written
|
|
1189
|
-
* as a bare `lower(name) = ?` it silently returned nothing for any input
|
|
1190
|
-
* carrying an uppercase letter, and — because SQLite's `lower()` folds ASCII
|
|
1191
|
-
* only while JavaScript's `.toLowerCase()` folds Unicode — a caller that
|
|
1192
|
-
* pre-lowered in JavaScript could not match a non-ASCII name at all.
|
|
1193
|
-
*
|
|
1194
|
-
* Note this hardens the query, not its one caller: `matchFuzzy` still lowers
|
|
1195
|
-
* in JavaScript before calling, so the non-ASCII gap remains open there.
|
|
1196
|
-
*/
|
|
1197
944
|
getNodesByLowerName(name) {
|
|
1198
945
|
if (!this.stmts.getNodesByLowerName) {
|
|
1199
|
-
this.stmts.getNodesByLowerName = this.db
|
|
946
|
+
this.stmts.getNodesByLowerName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE lower(name) = lower(?)');
|
|
1200
947
|
}
|
|
1201
|
-
|
|
948
|
+
return this.stmts.getNodesByLowerName.all(name);
|
|
949
|
+
}
|
|
950
|
+
hasFilesOfLanguage(language) {
|
|
951
|
+
if (!this.stmts.hasFilesOfLanguage) {
|
|
952
|
+
this.stmts.hasFilesOfLanguage = this.db.prepare('SELECT 1 FROM files WHERE language = ? LIMIT 1');
|
|
953
|
+
}
|
|
954
|
+
return this.stmts.hasFilesOfLanguage.get(language) !== undefined;
|
|
955
|
+
}
|
|
956
|
+
getCobolIncludesByMember(member, limit) {
|
|
957
|
+
if (!this.stmts.getCobolIncludesByMember) {
|
|
958
|
+
this.stmts.getCobolIncludesByMember = this.db.prepare("SELECT * FROM nodes WHERE lower(name) = lower(?) AND +kind = 'import' AND +language = 'cobol'"
|
|
959
|
+
+ ' ORDER BY file_path, start_line, id LIMIT ?');
|
|
960
|
+
}
|
|
961
|
+
const rows = this.stmts.getCobolIncludesByMember.all(member, limit);
|
|
962
|
+
return rows.map(rowToNode);
|
|
963
|
+
}
|
|
964
|
+
getCobolFilesByStem(member) {
|
|
965
|
+
if (!this.stmts.getCobolFilesByStem) {
|
|
966
|
+
this.stmts.getCobolFilesByStem = this.db.prepare("SELECT * FROM nodes WHERE lower(name) >= lower(?) || '.' AND lower(name) < lower(?) || '/'"
|
|
967
|
+
+ " AND +kind = 'file' AND +language = 'cobol' ORDER BY file_path");
|
|
968
|
+
}
|
|
969
|
+
const rows = this.stmts.getCobolFilesByStem.all(member, member);
|
|
1202
970
|
return rows.map(rowToNode);
|
|
1203
971
|
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Search nodes by name using FTS with fallback to LIKE for better matching
|
|
1206
|
-
*
|
|
1207
|
-
* Search strategy:
|
|
1208
|
-
* 1. Try FTS5 prefix match (query*) for word-start matching
|
|
1209
|
-
* 2. If no results, try LIKE for substring matching (e.g., "signIn" finds "signInWithGoogle")
|
|
1210
|
-
* 3. Score results based on match quality
|
|
1211
|
-
*/
|
|
1212
972
|
searchNodes(query, options = {}) {
|
|
1213
973
|
const { limit = 100, offset = 0 } = options;
|
|
1214
|
-
// Parse field-qualified bits out of the raw query (kind:, lang:,
|
|
1215
|
-
// path:, name:). Anything not recognised stays in `text` and goes
|
|
1216
|
-
// to FTS unchanged. Filters compose with the SearchOptions arg —
|
|
1217
|
-
// both are applied (intersection-style).
|
|
1218
974
|
const parsed = (0, query_parser_1.parseQuery)(query);
|
|
1219
975
|
const mergedKinds = parsed.kinds.length > 0
|
|
1220
976
|
? Array.from(new Set([...(options.kinds ?? []), ...parsed.kinds]))
|
|
@@ -1222,53 +978,21 @@ class QueryBuilder {
|
|
|
1222
978
|
const mergedLanguages = parsed.languages.length > 0
|
|
1223
979
|
? Array.from(new Set([...(options.languages ?? []), ...parsed.languages]))
|
|
1224
980
|
: options.languages;
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
// filters (`kind:function`), we still need *some* candidate set,
|
|
1229
|
-
// so synthesise an empty-text path that returns everything matching
|
|
1230
|
-
// the filters.
|
|
981
|
+
const filters = fieldFiltersOf(parsed);
|
|
982
|
+
if (filters && !this.fieldFiltersCanMatch(filters))
|
|
983
|
+
return [];
|
|
1231
984
|
const text = parsed.text;
|
|
1232
985
|
const kinds = mergedKinds;
|
|
1233
986
|
const languages = mergedLanguages;
|
|
1234
|
-
// First try FTS5 with prefix matching (skip if FTS5 not available, #1532)
|
|
1235
987
|
let results = text
|
|
1236
|
-
? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }) : [])
|
|
1237
|
-
|
|
1238
|
-
// post-scoring path: + name: filters can be very selective, so
|
|
1239
|
-
// a smaller multiplier risks returning fewer than `limit`
|
|
1240
|
-
// results despite the DB having plenty of matches.
|
|
1241
|
-
: this.searchAllByFilters({ kinds, languages, limit: limit * 5 });
|
|
1242
|
-
// If no FTS results, try LIKE-based substring search
|
|
988
|
+
? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }, filters) : [])
|
|
989
|
+
: this.searchAllByFilters({ kinds, languages, limit: limit * 5, offset }, filters);
|
|
1243
990
|
if (results.length === 0 && text.length >= 2) {
|
|
1244
|
-
results = this.searchNodesLike(text, { kinds, languages, limit, offset });
|
|
991
|
+
results = this.searchNodesLike(text, { kinds, languages, limit, offset }, filters);
|
|
1245
992
|
}
|
|
1246
|
-
// Final fuzzy fallback: scan all known names and keep those within
|
|
1247
|
-
// a tight Levenshtein distance. Only fires when both FTS and LIKE
|
|
1248
|
-
// returned nothing AND there's a text portion long enough to be
|
|
1249
|
-
// worth fuzzing (1-char queries would match too much).
|
|
1250
993
|
if (results.length === 0 && text.length >= 3) {
|
|
1251
|
-
results = this.searchNodesFuzzy(text, { kinds, languages, limit });
|
|
1252
|
-
}
|
|
1253
|
-
// Supplement: ensure exact name matches are always candidates.
|
|
1254
|
-
// BM25 can bury short exact-match names (e.g. "getBean") under hundreds of
|
|
1255
|
-
// compound names (e.g. "getBeanDescriptor") in large codebases,
|
|
1256
|
-
// pushing them past the FTS fetch limit before post-hoc scoring can help.
|
|
1257
|
-
// Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
|
|
1258
|
-
// prefix=20) actually differentiates them after rescoring.
|
|
1259
|
-
//
|
|
1260
|
-
// Whole-name equality MUST be written as `lower(name) = lower(?)` so it
|
|
1261
|
-
// seeks `idx_nodes_lower_name`. The equivalent `name = ? COLLATE NOCASE`
|
|
1262
|
-
// matches no index — `idx_nodes_name` is BINARY-collated and the expression
|
|
1263
|
-
// index only matches the same expression — and degrades to a full table
|
|
1264
|
-
// scan. The `LIMIT 20` does not rescue it: SQLite can only stop early once
|
|
1265
|
-
// it has produced 20 rows, and this runs once per query term, most of which
|
|
1266
|
-
// name nothing in the corpus. Measured per term on an unmatched term:
|
|
1267
|
-
// 0.08ms on gin (2.5k nodes), 0.39ms on excalidraw (11k), 2.4ms on django
|
|
1268
|
-
// (62k) — and growing with the corpus, where the seek is flat at ~0.002ms.
|
|
1269
|
-
// Lowering the parameter in SQL rather than in JS is deliberate: SQLite's
|
|
1270
|
-
// `lower()` and NOCASE both fold ASCII only, while JS `.toLowerCase()`
|
|
1271
|
-
// folds Unicode, which would silently stop matching non-ASCII names.
|
|
994
|
+
results = this.searchNodesFuzzy(text, { kinds, languages, limit }, filters);
|
|
995
|
+
}
|
|
1272
996
|
if (results.length > 0 && query) {
|
|
1273
997
|
const existingIds = new Set(results.map(r => r.node.id));
|
|
1274
998
|
const maxFtsScore = Math.max(...results.map(r => r.score));
|
|
@@ -1284,8 +1008,11 @@ class QueryBuilder {
|
|
|
1284
1008
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1285
1009
|
params.push(...languages);
|
|
1286
1010
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1011
|
+
if (filters)
|
|
1012
|
+
sql += fieldFilterSql(filters, params);
|
|
1013
|
+
const rows = filters
|
|
1014
|
+
? this.readFilteredPage(sql, params, filters, 20, 0)
|
|
1015
|
+
: this.db.prepare(`${sql} LIMIT 20`).all(...params);
|
|
1289
1016
|
for (const row of rows) {
|
|
1290
1017
|
if (!existingIds.has(row.id)) {
|
|
1291
1018
|
results.push({ node: rowToNode(row), score: maxFtsScore });
|
|
@@ -1294,18 +1021,14 @@ class QueryBuilder {
|
|
|
1294
1021
|
}
|
|
1295
1022
|
}
|
|
1296
1023
|
}
|
|
1297
|
-
|
|
1024
|
+
if (filters) {
|
|
1025
|
+
results = results.filter((r) => passesFieldFilters(r.node.name, r.node.filePath, filters));
|
|
1026
|
+
}
|
|
1298
1027
|
if (results.length > 0 && (text || query)) {
|
|
1299
1028
|
const scoringQuery = text || query;
|
|
1029
|
+
const isDeprioritizedPath = this.getDeprioritizedPathSnapshot();
|
|
1300
1030
|
results = results.map(r => {
|
|
1301
|
-
|
|
1302
|
-
// the answer, so the exact-name bonus has to be damped too. The -15 path
|
|
1303
|
-
// penalty alone cannot do it: the bonus is additive and larger (measured
|
|
1304
|
-
// on #982's repro, a `usage()` helper sat at 74.8 vs 51.2 for the top
|
|
1305
|
-
// product symbol — -15 lands at 59.8, still ahead). Damped, not zeroed,
|
|
1306
|
-
// so the tree stays findable when it genuinely is what you asked for.
|
|
1307
|
-
// Evaluated once and reused: the predicate stats the config file.
|
|
1308
|
-
const deprioritized = this.isDeprioritizedPath?.(r.node.filePath) ?? false;
|
|
1031
|
+
const deprioritized = isDeprioritizedPath?.(r.node.filePath) ?? false;
|
|
1309
1032
|
const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
|
|
1310
1033
|
return {
|
|
1311
1034
|
...r,
|
|
@@ -1316,39 +1039,32 @@ class QueryBuilder {
|
|
|
1316
1039
|
};
|
|
1317
1040
|
});
|
|
1318
1041
|
results.sort((a, b) => b.score - a.score);
|
|
1319
|
-
// Trim to requested limit after rescoring
|
|
1320
1042
|
if (results.length > limit) {
|
|
1321
1043
|
results = results.slice(0, limit);
|
|
1322
1044
|
}
|
|
1323
1045
|
}
|
|
1324
|
-
// Apply path: + name: filters AFTER scoring. Scoring already uses
|
|
1325
|
-
// path/name as a soft signal; the explicit filters here are a hard
|
|
1326
|
-
// gate. Done last so the FTS limit fetched plenty of candidates to
|
|
1327
|
-
// narrow from.
|
|
1328
|
-
if (pathFilters.length > 0) {
|
|
1329
|
-
const lowered = pathFilters.map((p) => p.toLowerCase());
|
|
1330
|
-
results = results.filter((r) => {
|
|
1331
|
-
const fp = r.node.filePath.toLowerCase();
|
|
1332
|
-
return lowered.some((p) => fp.includes(p));
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
if (nameFilters.length > 0) {
|
|
1336
|
-
const lowered = nameFilters.map((n) => n.toLowerCase());
|
|
1337
|
-
results = results.filter((r) => {
|
|
1338
|
-
const nm = r.node.name.toLowerCase();
|
|
1339
|
-
return lowered.some((n) => nm.includes(n));
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
1046
|
return results;
|
|
1343
1047
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1048
|
+
readFilteredPage(sql, params, filters, limit, offset) {
|
|
1049
|
+
const page = [];
|
|
1050
|
+
if (limit === 0)
|
|
1051
|
+
return page;
|
|
1052
|
+
let skipped = 0;
|
|
1053
|
+
for (const row of this.db.prepare(sql).iterate(...params)) {
|
|
1054
|
+
if (!passesFieldFilters(row.name, row.file_path, filters))
|
|
1055
|
+
continue;
|
|
1056
|
+
if (skipped < offset) {
|
|
1057
|
+
skipped++;
|
|
1058
|
+
continue;
|
|
1059
|
+
}
|
|
1060
|
+
page.push(row);
|
|
1061
|
+
if (page.length === limit)
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
return page;
|
|
1065
|
+
}
|
|
1066
|
+
searchAllByFilters(options, filters) {
|
|
1067
|
+
const { kinds, languages, limit, offset } = options;
|
|
1352
1068
|
let sql = 'SELECT * FROM nodes WHERE 1=1';
|
|
1353
1069
|
const params = [];
|
|
1354
1070
|
if (kinds && kinds.length > 0) {
|
|
@@ -1359,47 +1075,38 @@ class QueryBuilder {
|
|
|
1359
1075
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1360
1076
|
params.push(...languages);
|
|
1361
1077
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1078
|
+
if (filters)
|
|
1079
|
+
sql += fieldFilterSql(filters, params);
|
|
1080
|
+
sql += ' ORDER BY name';
|
|
1081
|
+
const rows = filters
|
|
1082
|
+
? this.readFilteredPage(sql, params, filters, limit, offset)
|
|
1083
|
+
: this.db.prepare(`${sql} LIMIT ? OFFSET ?`).all(...params, limit, offset);
|
|
1365
1084
|
return rows.map((row) => ({ node: rowToNode(row), score: 1 }));
|
|
1366
1085
|
}
|
|
1367
|
-
|
|
1368
|
-
* Fuzzy fallback: when zero FTS/LIKE hits, try an edit-distance
|
|
1369
|
-
* sweep over the distinct symbol-name set. Caps `maxDist` at 2 so
|
|
1370
|
-
* `getUssr` finds `getUser` but `process` doesn't match `prosody`.
|
|
1371
|
-
* Bounded edit distance keeps each comparison cheap; the per-query
|
|
1372
|
-
* scan is O(distinct-name-count) which is far smaller than total
|
|
1373
|
-
* node count on any real codebase.
|
|
1374
|
-
*/
|
|
1375
|
-
searchNodesFuzzy(text, options) {
|
|
1086
|
+
searchNodesFuzzy(text, options, filters) {
|
|
1376
1087
|
const { kinds, languages, limit } = options;
|
|
1377
1088
|
const lowered = text.toLowerCase();
|
|
1378
1089
|
const maxDist = lowered.length <= 4 ? 1 : 2;
|
|
1379
|
-
|
|
1380
|
-
// by getAllNodeNames(); even on a 200k-node project the distinct
|
|
1381
|
-
// name set is typically O(10k) because most names repeat. The
|
|
1382
|
-
// candidate-cap below bounds memory regardless.
|
|
1383
|
-
const allNames = this.getAllNodeNames();
|
|
1090
|
+
const { names, lowered: loweredNames, starts } = this.fuzzyNames();
|
|
1384
1091
|
const candidates = [];
|
|
1385
|
-
for (
|
|
1386
|
-
const
|
|
1092
|
+
for (let i = 0; i < names.length; i++) {
|
|
1093
|
+
const end = starts[i + 1] - 1;
|
|
1094
|
+
if (Math.abs(end - starts[i] - lowered.length) > maxDist)
|
|
1095
|
+
continue;
|
|
1096
|
+
const dist = (0, query_parser_1.boundedEditDistance)(loweredNames.slice(starts[i], end), lowered, maxDist);
|
|
1387
1097
|
if (dist <= maxDist)
|
|
1388
|
-
candidates.push({ name, dist });
|
|
1098
|
+
candidates.push({ name: names[i], dist });
|
|
1389
1099
|
}
|
|
1390
1100
|
candidates.sort((a, b) => a.dist - b.dist);
|
|
1391
|
-
// Cap the per-name follow-up queries. Each survivor triggers a
|
|
1392
|
-
// separate `SELECT * FROM nodes WHERE name = ?`; without this cap
|
|
1393
|
-
// a project with many similar names (`getUser1`, `getUser2`...)
|
|
1394
|
-
// could fan out far beyond `limit` queries before the inner-loop
|
|
1395
|
-
// limit kicks in.
|
|
1396
1101
|
const FUZZY_FOLLOWUP_CAP = Math.max(limit * 2, 50);
|
|
1397
|
-
const cappedCandidates = candidates.slice(0, FUZZY_FOLLOWUP_CAP);
|
|
1102
|
+
const cappedCandidates = filters ? candidates : candidates.slice(0, FUZZY_FOLLOWUP_CAP);
|
|
1398
1103
|
const results = [];
|
|
1399
1104
|
const seen = new Set();
|
|
1400
1105
|
for (const c of cappedCandidates) {
|
|
1401
1106
|
if (results.length >= limit)
|
|
1402
1107
|
break;
|
|
1108
|
+
if (filters && !passesNameFilters(c.name, filters))
|
|
1109
|
+
continue;
|
|
1403
1110
|
let sql = 'SELECT * FROM nodes WHERE name = ?';
|
|
1404
1111
|
const params = [c.name];
|
|
1405
1112
|
if (kinds && kinds.length > 0) {
|
|
@@ -1410,14 +1117,15 @@ class QueryBuilder {
|
|
|
1410
1117
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1411
1118
|
params.push(...languages);
|
|
1412
1119
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1120
|
+
if (filters)
|
|
1121
|
+
sql += fieldFilterSql(filters, params);
|
|
1122
|
+
const rows = filters
|
|
1123
|
+
? this.readFilteredPage(sql, params, filters, 5, 0)
|
|
1124
|
+
: this.db.prepare(`${sql} LIMIT 5`).all(...params);
|
|
1415
1125
|
for (const row of rows) {
|
|
1416
1126
|
if (seen.has(row.id))
|
|
1417
1127
|
continue;
|
|
1418
1128
|
seen.add(row.id);
|
|
1419
|
-
// Lower the score for each edit step away from the query so
|
|
1420
|
-
// exact-match fallbacks (dist 0) outrank dist-2 typos.
|
|
1421
1129
|
results.push({ node: rowToNode(row), score: 1 / (1 + c.dist) });
|
|
1422
1130
|
if (results.length >= limit)
|
|
1423
1131
|
break;
|
|
@@ -1425,39 +1133,37 @@ class QueryBuilder {
|
|
|
1425
1133
|
}
|
|
1426
1134
|
return results;
|
|
1427
1135
|
}
|
|
1428
|
-
/** Bounded miss diagnostics, independent of relevance filters and ranking. */
|
|
1429
1136
|
getExploreMissDiagnostics(query) {
|
|
1430
1137
|
const words = [...new Set((query.match(/[\p{L}\p{N}]+/gu) ?? []).map(w => w.toLowerCase()))];
|
|
1431
1138
|
const checked = words.filter(w => w.length <= 64).slice(0, 16);
|
|
1432
1139
|
const limited = checked.length !== words.length;
|
|
1433
1140
|
if (checked.length === 0)
|
|
1434
1141
|
return { matched: [], unmatched: [], candidates: [], limited };
|
|
1435
|
-
|
|
1436
|
-
// Vocab rows can outlive deleted definitions, so verify them against nodes.
|
|
1142
|
+
const vocab = this.hasSchema('name_segment_vocab');
|
|
1437
1143
|
const rows = this.db.prepare(`
|
|
1438
1144
|
WITH words(word, pattern) AS (VALUES ${checked.map(() => '(?, ?)').join(', ')})
|
|
1439
1145
|
SELECT word, (
|
|
1440
|
-
EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)
|
|
1146
|
+
EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)${vocab ? `
|
|
1441
1147
|
OR EXISTS (
|
|
1442
1148
|
SELECT 1 FROM name_segment_vocab v WHERE v.segment = word
|
|
1443
1149
|
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1444
|
-
)
|
|
1150
|
+
)` : ''}
|
|
1445
1151
|
) AS matched FROM words
|
|
1446
1152
|
`).all(...checked.flatMap(w => [w, `{name qualified_name signature docstring} : "${w}"*`]));
|
|
1447
|
-
const names = this.db.prepare(`
|
|
1153
|
+
const names = this.db.prepare(`${vocab ? `
|
|
1448
1154
|
SELECT name FROM (
|
|
1449
1155
|
SELECT v.name FROM name_segment_vocab v
|
|
1450
1156
|
WHERE v.segment IN (${checked.map(() => '?').join(', ')})
|
|
1451
1157
|
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1452
1158
|
LIMIT 12
|
|
1453
1159
|
)
|
|
1454
|
-
UNION ALL
|
|
1160
|
+
UNION ALL` : ''}
|
|
1455
1161
|
SELECT name FROM (
|
|
1456
1162
|
SELECT n.name FROM nodes_fts JOIN nodes n ON n.rowid = nodes_fts.rowid
|
|
1457
1163
|
WHERE nodes_fts MATCH ? AND n.kind NOT IN ('file', 'import')
|
|
1458
1164
|
LIMIT 12
|
|
1459
1165
|
)
|
|
1460
|
-
`).all(...checked, `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
|
|
1166
|
+
`).all(...(vocab ? checked : []), `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
|
|
1461
1167
|
return {
|
|
1462
1168
|
matched: rows.filter(r => r.matched).map(r => r.word),
|
|
1463
1169
|
unmatched: rows.filter(r => !r.matched).map(r => r.word),
|
|
@@ -1465,40 +1171,44 @@ class QueryBuilder {
|
|
|
1465
1171
|
limited,
|
|
1466
1172
|
};
|
|
1467
1173
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1174
|
+
getUnseenNames(names) {
|
|
1175
|
+
const checked = [...new Set(names)].filter((n) => n.length > 0 && n.length <= 128).slice(0, 16);
|
|
1176
|
+
if (checked.length === 0)
|
|
1177
|
+
return [];
|
|
1178
|
+
if (!this.stmts.unseenName) {
|
|
1179
|
+
this.stmts.unseenName = this.db.prepare(`
|
|
1180
|
+
SELECT EXISTS (SELECT 1 FROM nodes WHERE lower(name) = lower(?))
|
|
1181
|
+
OR EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH ?) AS seen
|
|
1182
|
+
`);
|
|
1183
|
+
}
|
|
1184
|
+
const stmt = this.stmts.unseenName;
|
|
1185
|
+
return checked.filter((name) => {
|
|
1186
|
+
const member = name.split(/::|\./).pop();
|
|
1187
|
+
const phrase = member.replace(/"/g, '');
|
|
1188
|
+
if (phrase.length === 0)
|
|
1189
|
+
return false;
|
|
1190
|
+
const row = stmt.get(member, `{name qualified_name signature docstring} : "${phrase}"*`);
|
|
1191
|
+
return !row.seen;
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
searchNodesFTS(query, options, filters) {
|
|
1472
1195
|
const { kinds, languages, limit = 100, offset = 0 } = options;
|
|
1473
|
-
// Add prefix wildcard for better matching (e.g., "auth" matches "AuthService", "authenticate")
|
|
1474
|
-
// Escape special FTS5 characters and add prefix wildcard.
|
|
1475
|
-
//
|
|
1476
|
-
// `::` is a qualifier separator in Rust/C++/Ruby, not a token char,
|
|
1477
|
-
// so treat it as whitespace before the strip step. Otherwise queries
|
|
1478
|
-
// like `stage_apply::run` collapse to `stage_applyrun` (the colons
|
|
1479
|
-
// are stripped without splitting) and find nothing. See #173.
|
|
1480
1196
|
const ftsQuery = query
|
|
1481
|
-
.replace(/::/g, ' ')
|
|
1482
|
-
.replace(/['"*():^]/g, '')
|
|
1197
|
+
.replace(/::/g, ' ')
|
|
1198
|
+
.replace(/['"*():^]/g, ' ')
|
|
1483
1199
|
.split(/\s+/)
|
|
1484
1200
|
.filter(term => term.length > 0)
|
|
1485
|
-
// Strip FTS5 boolean operators to prevent query manipulation
|
|
1486
1201
|
.filter(term => !/^(AND|OR|NOT|NEAR)$/i.test(term))
|
|
1487
|
-
.map(term => `"${term}"*`)
|
|
1202
|
+
.map(term => `"${term}"*`)
|
|
1488
1203
|
.join(' OR ');
|
|
1489
1204
|
if (!ftsQuery) {
|
|
1490
1205
|
return [];
|
|
1491
1206
|
}
|
|
1492
|
-
// BM25 column weights: id=0, name=20, qualified_name=5, docstring=1, signature=2
|
|
1493
|
-
// Heavy name weight ensures exact/prefix name matches rank above incidental
|
|
1494
|
-
// mentions in long docstrings or qualified names of nested symbols.
|
|
1495
|
-
// Fetch 5x requested limit so post-hoc rescoring (kindBonus, pathRelevance,
|
|
1496
|
-
// nameMatchBonus) can promote results that BM25 alone undervalues.
|
|
1497
1207
|
const ftsLimit = Math.max(limit * 5, 100);
|
|
1498
1208
|
let sql = `
|
|
1499
1209
|
SELECT nodes.*, bm25(nodes_fts, 0, 20, 5, 1, 2) as score
|
|
1500
1210
|
FROM nodes_fts
|
|
1501
|
-
JOIN nodes ON
|
|
1211
|
+
CROSS JOIN nodes ON nodes.rowid = nodes_fts.rowid
|
|
1502
1212
|
WHERE nodes_fts MATCH ?
|
|
1503
1213
|
`;
|
|
1504
1214
|
const params = [ftsQuery];
|
|
@@ -1510,26 +1220,38 @@ class QueryBuilder {
|
|
|
1510
1220
|
sql += ` AND nodes.language IN (${languages.map(() => '?').join(',')})`;
|
|
1511
1221
|
params.push(...languages);
|
|
1512
1222
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1223
|
+
if (filters)
|
|
1224
|
+
sql += fieldFilterSql(filters, params);
|
|
1225
|
+
sql += ' ORDER BY score';
|
|
1515
1226
|
try {
|
|
1516
|
-
|
|
1227
|
+
let rows;
|
|
1228
|
+
if (filters) {
|
|
1229
|
+
rows = this.readFilteredPage(sql, params, filters, ftsLimit, offset);
|
|
1230
|
+
}
|
|
1231
|
+
else {
|
|
1232
|
+
sql += ' LIMIT ? OFFSET ?';
|
|
1233
|
+
params.push(ftsLimit, offset);
|
|
1234
|
+
rows = this.db.prepare(sql).all(...params);
|
|
1235
|
+
}
|
|
1517
1236
|
return rows.map((row) => ({
|
|
1518
1237
|
node: rowToNode(row),
|
|
1519
|
-
score: Math.abs(row.score),
|
|
1238
|
+
score: Math.abs(row.score),
|
|
1520
1239
|
}));
|
|
1521
1240
|
}
|
|
1522
1241
|
catch {
|
|
1523
|
-
// FTS query failed, return empty
|
|
1524
1242
|
return [];
|
|
1525
1243
|
}
|
|
1526
1244
|
}
|
|
1527
|
-
|
|
1528
|
-
* LIKE-based substring search for cases where FTS doesn't match
|
|
1529
|
-
* Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
|
|
1530
|
-
*/
|
|
1531
|
-
searchNodesLike(query, options) {
|
|
1245
|
+
searchNodesLike(query, options, filters) {
|
|
1532
1246
|
const { kinds, languages, limit = 100, offset = 0 } = options;
|
|
1247
|
+
if (/^[A-Za-z0-9]+$/.test(query)) {
|
|
1248
|
+
const runs = this.memoizedRead('qualifiedNameRuns', () => this.readQualifiedNameRuns());
|
|
1249
|
+
if (runs !== null) {
|
|
1250
|
+
const word = query.toLowerCase();
|
|
1251
|
+
if (!this.fuzzyNames().lowered.includes(word) && !runs.includes(word))
|
|
1252
|
+
return [];
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1533
1255
|
let sql = `
|
|
1534
1256
|
SELECT nodes.*,
|
|
1535
1257
|
CASE
|
|
@@ -1546,18 +1268,17 @@ class QueryBuilder {
|
|
|
1546
1268
|
name LIKE ?
|
|
1547
1269
|
)
|
|
1548
1270
|
`;
|
|
1549
|
-
// Pattern variants for better matching
|
|
1550
1271
|
const exactMatch = query;
|
|
1551
1272
|
const startsWith = `${query}%`;
|
|
1552
1273
|
const contains = `%${query}%`;
|
|
1553
1274
|
const params = [
|
|
1554
|
-
exactMatch,
|
|
1555
|
-
startsWith,
|
|
1556
|
-
contains,
|
|
1557
|
-
contains,
|
|
1558
|
-
contains,
|
|
1559
|
-
contains,
|
|
1560
|
-
startsWith,
|
|
1275
|
+
exactMatch,
|
|
1276
|
+
startsWith,
|
|
1277
|
+
contains,
|
|
1278
|
+
contains,
|
|
1279
|
+
contains,
|
|
1280
|
+
contains,
|
|
1281
|
+
startsWith,
|
|
1561
1282
|
];
|
|
1562
1283
|
if (kinds && kinds.length > 0) {
|
|
1563
1284
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1567,39 +1288,27 @@ class QueryBuilder {
|
|
|
1567
1288
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1568
1289
|
params.push(...languages);
|
|
1569
1290
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1291
|
+
if (filters)
|
|
1292
|
+
sql += fieldFilterSql(filters, params);
|
|
1293
|
+
sql += ' ORDER BY score DESC, length(name) ASC';
|
|
1294
|
+
let rows;
|
|
1295
|
+
if (filters) {
|
|
1296
|
+
rows = this.readFilteredPage(sql, params, filters, limit, offset);
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
sql += ' LIMIT ? OFFSET ?';
|
|
1300
|
+
params.push(limit, offset);
|
|
1301
|
+
rows = this.db.prepare(sql).all(...params);
|
|
1302
|
+
}
|
|
1573
1303
|
return rows.map((row) => ({
|
|
1574
1304
|
node: rowToNode(row),
|
|
1575
1305
|
score: row.score,
|
|
1576
1306
|
}));
|
|
1577
1307
|
}
|
|
1578
|
-
/**
|
|
1579
|
-
* Find nodes by exact name match
|
|
1580
|
-
*
|
|
1581
|
-
* Used for hybrid search - looks up symbols by exact name or case-insensitive match.
|
|
1582
|
-
* Returns high-confidence matches for known symbol names extracted from query.
|
|
1583
|
-
*
|
|
1584
|
-
* @param names - Array of symbol names to look up
|
|
1585
|
-
* @param options - Search options (kinds, languages, limit)
|
|
1586
|
-
* @returns SearchResult array with exact matches scored at 1.0
|
|
1587
|
-
*/
|
|
1588
1308
|
findNodesByExactName(names, options = {}) {
|
|
1589
1309
|
if (names.length === 0)
|
|
1590
1310
|
return [];
|
|
1591
1311
|
const { kinds, languages, limit = 50 } = options;
|
|
1592
|
-
// Two-pass approach to handle common names (e.g., "run" has 40+ matches):
|
|
1593
|
-
// Pass 1: Find which files contain distinctive (rare) symbols from the query.
|
|
1594
|
-
// Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
|
|
1595
|
-
// Pass 1: Find files containing each queried name, identify distinctive names
|
|
1596
|
-
//
|
|
1597
|
-
// Both passes spell whole-name equality as `lower(name) = lower(?)` so they
|
|
1598
|
-
// seek `idx_nodes_lower_name` — see the note in `searchNodes` for why the
|
|
1599
|
-
// `name = ? COLLATE NOCASE` form full-scans instead. This path is the one
|
|
1600
|
-
// that hurts most: it runs both passes for every symbol extracted from the
|
|
1601
|
-
// query, and extraction is generous, so most of those names are absent from
|
|
1602
|
-
// the corpus and never reach either LIMIT.
|
|
1603
1312
|
const nameToFiles = new Map();
|
|
1604
1313
|
for (const name of names) {
|
|
1605
1314
|
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
|
|
@@ -1612,7 +1321,6 @@ class QueryBuilder {
|
|
|
1612
1321
|
const rows = this.db.prepare(sql).all(...params);
|
|
1613
1322
|
nameToFiles.set(name.toLowerCase(), new Set(rows.map(r => r.file_path)));
|
|
1614
1323
|
}
|
|
1615
|
-
// Distinctive names are those with fewer than 10 file matches (e.g., "scrapeLoop" = 1 file)
|
|
1616
1324
|
const distinctiveFiles = new Set();
|
|
1617
1325
|
for (const [, files] of nameToFiles) {
|
|
1618
1326
|
if (files.size > 0 && files.size < 10) {
|
|
@@ -1620,7 +1328,6 @@ class QueryBuilder {
|
|
|
1620
1328
|
distinctiveFiles.add(f);
|
|
1621
1329
|
}
|
|
1622
1330
|
}
|
|
1623
|
-
// Pass 2: Query each name with per-name limit, scoring by co-location
|
|
1624
1331
|
const perNameLimit = Math.max(8, Math.ceil(limit / names.length));
|
|
1625
1332
|
const allResults = [];
|
|
1626
1333
|
const seenIds = new Set();
|
|
@@ -1639,7 +1346,6 @@ class QueryBuilder {
|
|
|
1639
1346
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1640
1347
|
params.push(...languages);
|
|
1641
1348
|
}
|
|
1642
|
-
// Fetch enough to find co-located results among common names
|
|
1643
1349
|
sql += ' LIMIT ?';
|
|
1644
1350
|
params.push(Math.max(perNameLimit * 3, 50));
|
|
1645
1351
|
const rows = this.db.prepare(sql).all(...params);
|
|
@@ -1648,28 +1354,18 @@ class QueryBuilder {
|
|
|
1648
1354
|
const node = rowToNode(row);
|
|
1649
1355
|
if (seenIds.has(node.id))
|
|
1650
1356
|
continue;
|
|
1651
|
-
// Boost results in files that also contain distinctive symbols
|
|
1652
1357
|
const coLocationBoost = distinctiveFiles.has(node.filePath) ? 20 : 0;
|
|
1653
1358
|
nameResults.push({ node, score: row.score + coLocationBoost });
|
|
1654
1359
|
}
|
|
1655
|
-
// Sort by score (co-located first), take per-name limit
|
|
1656
1360
|
nameResults.sort((a, b) => b.score - a.score);
|
|
1657
1361
|
for (const r of nameResults.slice(0, perNameLimit)) {
|
|
1658
1362
|
seenIds.add(r.node.id);
|
|
1659
1363
|
allResults.push(r);
|
|
1660
1364
|
}
|
|
1661
1365
|
}
|
|
1662
|
-
// Sort all results by score so co-located results bubble up
|
|
1663
1366
|
allResults.sort((a, b) => b.score - a.score);
|
|
1664
1367
|
return allResults.slice(0, limit);
|
|
1665
1368
|
}
|
|
1666
|
-
/**
|
|
1667
|
-
* Find nodes whose name contains a substring (LIKE-based).
|
|
1668
|
-
* Useful for CamelCase-part matching where FTS fails because
|
|
1669
|
-
* e.g. "TransportSearchAction" is one FTS token, not matchable by "Search"*.
|
|
1670
|
-
*
|
|
1671
|
-
* Results are ordered by name length (shorter = more likely to be the core type).
|
|
1672
|
-
*/
|
|
1673
1369
|
findNodesByNameSubstring(substring, options = {}) {
|
|
1674
1370
|
const { kinds, languages, limit = 30, excludePrefix } = options;
|
|
1675
1371
|
let sql = `
|
|
@@ -1678,7 +1374,6 @@ class QueryBuilder {
|
|
|
1678
1374
|
WHERE name LIKE ?
|
|
1679
1375
|
`;
|
|
1680
1376
|
const params = [`%${substring}%`];
|
|
1681
|
-
// Exclude prefix matches (handled by FTS-based prefix search in Step 2b)
|
|
1682
1377
|
if (excludePrefix) {
|
|
1683
1378
|
sql += ` AND name NOT LIKE ?`;
|
|
1684
1379
|
params.push(`${substring}%`);
|
|
@@ -1693,16 +1388,71 @@ class QueryBuilder {
|
|
|
1693
1388
|
}
|
|
1694
1389
|
sql += ' ORDER BY length(name) ASC LIMIT ?';
|
|
1695
1390
|
params.push(limit);
|
|
1391
|
+
if (kinds && kinds.length > 0 && !(languages && languages.length > 0)) {
|
|
1392
|
+
const index = this.memoizedRead('nameSubstringIndex', () => this.readNameSubstringIndex());
|
|
1393
|
+
const order = index ? this.substringScanOrder(index, sql, params, excludePrefix ? 2 : 1) : null;
|
|
1394
|
+
const rowids = order ? (0, name_substring_index_1.searchNameSubstring)(index.index, substring, kinds, excludePrefix === true, limit, order) : null;
|
|
1395
|
+
if (rowids) {
|
|
1396
|
+
return this.getNodeRowsByRowid(rowids).map((row) => ({ node: rowToNode(row), score: 1.0 }));
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1696
1399
|
const rows = this.db.prepare(sql).all(...params);
|
|
1697
1400
|
return rows.map((row) => ({
|
|
1698
1401
|
node: rowToNode(row),
|
|
1699
1402
|
score: row.score,
|
|
1700
1403
|
}));
|
|
1701
1404
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1405
|
+
substringScanOrder(memo, sql, params, patternCount) {
|
|
1406
|
+
const key = `${sql}\u0000${params.slice(patternCount).join('\u0000')}`;
|
|
1407
|
+
let order = memo.plans.get(key);
|
|
1408
|
+
if (order === undefined) {
|
|
1409
|
+
order = null;
|
|
1410
|
+
try {
|
|
1411
|
+
const details = this.db.prepare(`EXPLAIN QUERY PLAN ${sql}`).all(...params)
|
|
1412
|
+
.map((row) => row.detail)
|
|
1413
|
+
.filter((detail) => /^(SCAN|SEARCH) (TABLE )?nodes\b/.test(detail));
|
|
1414
|
+
if (details.length === 1) {
|
|
1415
|
+
if (/^SEARCH (TABLE )?nodes USING (COVERING )?INDEX idx_nodes_kind \(/.test(details[0]))
|
|
1416
|
+
order = 'index';
|
|
1417
|
+
else if (/^SCAN (TABLE )?nodes$/.test(details[0]))
|
|
1418
|
+
order = 'rowid';
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
catch {
|
|
1422
|
+
order = null;
|
|
1423
|
+
}
|
|
1424
|
+
memo.plans.set(key, order);
|
|
1425
|
+
}
|
|
1426
|
+
return order;
|
|
1427
|
+
}
|
|
1428
|
+
readNameSubstringIndex() {
|
|
1429
|
+
const rows = this.db
|
|
1430
|
+
.prepare(`SELECT rowid AS rowid, kind, name FROM nodes WHERE kind IN (${name_substring_index_1.NAME_SUBSTRING_KINDS.map(() => '?').join(',')})`
|
|
1431
|
+
+ ' ORDER BY kind, file_path, start_line, id')
|
|
1432
|
+
.all(...name_substring_index_1.NAME_SUBSTRING_KINDS);
|
|
1433
|
+
const index = (0, name_substring_index_1.buildNameSubstringIndex)(rows);
|
|
1434
|
+
return index ? { index, plans: new Map() } : null;
|
|
1435
|
+
}
|
|
1436
|
+
getNodeRowsByRowid(rowids) {
|
|
1437
|
+
if (rowids.length === 0)
|
|
1438
|
+
return [];
|
|
1439
|
+
const byRowid = new Map();
|
|
1440
|
+
for (let i = 0; i < rowids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1441
|
+
const chunk = rowids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1442
|
+
const rows = this.db
|
|
1443
|
+
.prepare(`SELECT rowid AS rowid_, nodes.* FROM nodes WHERE rowid IN (${chunk.map(() => '?').join(',')})`)
|
|
1444
|
+
.all(...chunk);
|
|
1445
|
+
for (const row of rows)
|
|
1446
|
+
byRowid.set(row.rowid_, row);
|
|
1447
|
+
}
|
|
1448
|
+
const out = [];
|
|
1449
|
+
for (const rowid of rowids) {
|
|
1450
|
+
const row = byRowid.get(rowid);
|
|
1451
|
+
if (row)
|
|
1452
|
+
out.push(row);
|
|
1453
|
+
}
|
|
1454
|
+
return out;
|
|
1455
|
+
}
|
|
1706
1456
|
hasSynthesizedEdgesTouchingFile(filePath) {
|
|
1707
1457
|
const owned = "CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.synthesizedBy') END IS NOT NULL";
|
|
1708
1458
|
for (const endpoint of ['source', 'target']) {
|
|
@@ -1710,7 +1460,6 @@ class QueryBuilder {
|
|
|
1710
1460
|
WHERE n.file_path = ? AND ${owned} LIMIT 1`).get(filePath))
|
|
1711
1461
|
return true;
|
|
1712
1462
|
}
|
|
1713
|
-
// Wiring often lives in a third file, with neither endpoint in it.
|
|
1714
1463
|
return !!this.db.prepare(`SELECT 1 FROM edges e WHERE ${owned}
|
|
1715
1464
|
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END >= ?
|
|
1716
1465
|
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END < ? LIMIT 1`).get(`${filePath}:`, `${filePath};`);
|
|
@@ -1721,14 +1470,11 @@ class QueryBuilder {
|
|
|
1721
1470
|
replaceSynthesisInputs(files) {
|
|
1722
1471
|
this.db.transaction(() => {
|
|
1723
1472
|
this.db.exec('DELETE FROM synthesis_inputs');
|
|
1724
|
-
const insert = this.db.prepare('INSERT INTO synthesis_inputs(file_path)
|
|
1473
|
+
const insert = this.db.prepare('INSERT OR IGNORE INTO synthesis_inputs(file_path) SELECT path FROM files WHERE path = ?');
|
|
1725
1474
|
for (const file of files)
|
|
1726
1475
|
insert.run(file);
|
|
1727
1476
|
})();
|
|
1728
1477
|
}
|
|
1729
|
-
/**
|
|
1730
|
-
* Insert a new edge
|
|
1731
|
-
*/
|
|
1732
1478
|
insertEdge(edge) {
|
|
1733
1479
|
if (!this.stmts.insertEdge) {
|
|
1734
1480
|
this.stmts.insertEdge = this.db.prepare(`
|
|
@@ -1746,9 +1492,6 @@ class QueryBuilder {
|
|
|
1746
1492
|
provenance: edge.provenance ?? null,
|
|
1747
1493
|
});
|
|
1748
1494
|
}
|
|
1749
|
-
/**
|
|
1750
|
-
* Insert multiple edges in a transaction
|
|
1751
|
-
*/
|
|
1752
1495
|
insertEdges(edges) {
|
|
1753
1496
|
if (edges.length === 0)
|
|
1754
1497
|
return;
|
|
@@ -1777,21 +1520,14 @@ class QueryBuilder {
|
|
|
1777
1520
|
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
1778
1521
|
})();
|
|
1779
1522
|
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Delete all edges from a source node
|
|
1782
|
-
*/
|
|
1783
1523
|
deleteEdgesBySource(sourceId) {
|
|
1784
1524
|
if (!this.stmts.deleteEdgesBySource) {
|
|
1785
1525
|
this.stmts.deleteEdgesBySource = this.db.prepare('DELETE FROM edges WHERE source = ?');
|
|
1786
1526
|
}
|
|
1787
1527
|
this.stmts.deleteEdgesBySource.run(sourceId);
|
|
1788
1528
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
* (calls before imports/references), then break ties deterministically.
|
|
1792
|
-
*/
|
|
1793
|
-
getOutgoingEdges(sourceId, kinds, provenance) {
|
|
1794
|
-
if ((kinds && kinds.length > 0) || provenance) {
|
|
1529
|
+
getOutgoingEdges(sourceId, kinds, provenance, limit) {
|
|
1530
|
+
if ((kinds && kinds.length > 0) || provenance || limit !== undefined) {
|
|
1795
1531
|
let sql = 'SELECT * FROM edges WHERE source = ?';
|
|
1796
1532
|
const params = [sourceId];
|
|
1797
1533
|
if (kinds && kinds.length > 0) {
|
|
@@ -1803,6 +1539,10 @@ class QueryBuilder {
|
|
|
1803
1539
|
params.push(provenance);
|
|
1804
1540
|
}
|
|
1805
1541
|
sql += ' ORDER BY kind, target, line, col';
|
|
1542
|
+
if (limit !== undefined) {
|
|
1543
|
+
sql += ' LIMIT ?';
|
|
1544
|
+
params.push(Math.max(0, Math.floor(limit)));
|
|
1545
|
+
}
|
|
1806
1546
|
const rows = this.edgeKindStmt(sql).all(...params);
|
|
1807
1547
|
return rows.map(rowToEdge);
|
|
1808
1548
|
}
|
|
@@ -1812,16 +1552,27 @@ class QueryBuilder {
|
|
|
1812
1552
|
const rows = this.stmts.getEdgesBySource.all(sourceId);
|
|
1813
1553
|
return rows.map(rowToEdge);
|
|
1814
1554
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1555
|
+
getIncomingEdgesExceptContains(targetId) {
|
|
1556
|
+
if (!this.stmts.getDependentEdgesByTarget) {
|
|
1557
|
+
this.stmts.getDependentEdgesByTarget = this.db.prepare("SELECT * FROM edges WHERE target = ? AND kind != 'contains' ORDER BY kind, source, line, col");
|
|
1558
|
+
}
|
|
1559
|
+
const rows = this.stmts.getDependentEdgesByTarget.all(targetId);
|
|
1560
|
+
return rows.map(rowToEdge);
|
|
1561
|
+
}
|
|
1562
|
+
getIncomingEdges(targetId, kinds, limit) {
|
|
1563
|
+
if ((kinds && kinds.length > 0) || limit !== undefined) {
|
|
1564
|
+
let sql = 'SELECT * FROM edges WHERE target = ?';
|
|
1565
|
+
const params = [targetId];
|
|
1566
|
+
if (kinds && kinds.length > 0) {
|
|
1567
|
+
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
1568
|
+
params.push(...kinds);
|
|
1569
|
+
}
|
|
1570
|
+
sql += ' ORDER BY kind, source, line, col';
|
|
1571
|
+
if (limit !== undefined) {
|
|
1572
|
+
sql += ' LIMIT ?';
|
|
1573
|
+
params.push(Math.max(0, Math.floor(limit)));
|
|
1574
|
+
}
|
|
1575
|
+
const rows = this.edgeKindStmt(sql).all(...params);
|
|
1825
1576
|
return rows.map(rowToEdge);
|
|
1826
1577
|
}
|
|
1827
1578
|
if (!this.stmts.getEdgesByTarget) {
|
|
@@ -1830,13 +1581,6 @@ class QueryBuilder {
|
|
|
1830
1581
|
const rows = this.stmts.getEdgesByTarget.all(targetId);
|
|
1831
1582
|
return rows.map(rowToEdge);
|
|
1832
1583
|
}
|
|
1833
|
-
/**
|
|
1834
|
-
* Outgoing edges for MANY source nodes in one query.
|
|
1835
|
-
*
|
|
1836
|
-
* The batch form of {@link getOutgoingEdges}. Building a nested outline needs
|
|
1837
|
-
* the `contains` edges of every container in a file at once; doing that one
|
|
1838
|
-
* source at a time is a query per symbol on files that have hundreds.
|
|
1839
|
-
*/
|
|
1840
1584
|
getOutgoingEdgesFrom(sourceIds, kinds) {
|
|
1841
1585
|
if (sourceIds.length === 0)
|
|
1842
1586
|
return [];
|
|
@@ -1857,15 +1601,6 @@ class QueryBuilder {
|
|
|
1857
1601
|
}
|
|
1858
1602
|
return out;
|
|
1859
1603
|
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Fan-in (total incoming edge count) for MANY nodes in one query.
|
|
1862
|
-
*
|
|
1863
|
-
* The per-node alternative — `getIncomingEdges(id).length` — is an indexed
|
|
1864
|
-
* lookup each, but a symbol screen rendering a couple of hundred callees
|
|
1865
|
-
* would issue a couple of hundred of them. Ids with no incoming edges are
|
|
1866
|
-
* absent from the map rather than present as 0, so callers can tell "no
|
|
1867
|
-
* edges" from "not asked about".
|
|
1868
|
-
*/
|
|
1869
1604
|
countIncomingEdges(ids) {
|
|
1870
1605
|
const out = new Map();
|
|
1871
1606
|
if (ids.length === 0)
|
|
@@ -1875,11 +1610,7 @@ class QueryBuilder {
|
|
|
1875
1610
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1876
1611
|
const placeholders = chunk.map(() => '?').join(',');
|
|
1877
1612
|
const rows = this.db
|
|
1878
|
-
.prepare(
|
|
1879
|
-
// A test's request onto a route (tier-synthesizer's `test-request`)
|
|
1880
|
-
// is not a production caller: forty tests hitting one endpoint must
|
|
1881
|
-
// not make it a hub the Steps walk refuses to enter.
|
|
1882
|
-
`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders})
|
|
1613
|
+
.prepare(`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders})
|
|
1883
1614
|
AND (metadata IS NULL OR metadata NOT LIKE '%"synthesizedBy":"test-request"%') GROUP BY target`)
|
|
1884
1615
|
.all(...chunk);
|
|
1885
1616
|
for (const row of rows)
|
|
@@ -1887,11 +1618,6 @@ class QueryBuilder {
|
|
|
1887
1618
|
}
|
|
1888
1619
|
return out;
|
|
1889
1620
|
}
|
|
1890
|
-
/**
|
|
1891
|
-
* Incoming edges for MANY target nodes in one query — the mirror of
|
|
1892
|
-
* {@link getOutgoingEdgesFrom}. Needed wherever a whole file's inbound edges
|
|
1893
|
-
* are wanted at once ("which files import anything in this one?").
|
|
1894
|
-
*/
|
|
1895
1621
|
getIncomingEdgesTo(targetIds, kinds) {
|
|
1896
1622
|
if (targetIds.length === 0)
|
|
1897
1623
|
return [];
|
|
@@ -1912,11 +1638,6 @@ class QueryBuilder {
|
|
|
1912
1638
|
}
|
|
1913
1639
|
return out;
|
|
1914
1640
|
}
|
|
1915
|
-
/**
|
|
1916
|
-
* Fan-out (total outgoing edge count) for MANY nodes in one query — the
|
|
1917
|
-
* mirror of {@link countIncomingEdges}. Ids with no outgoing edges are absent
|
|
1918
|
-
* from the map rather than present as 0.
|
|
1919
|
-
*/
|
|
1920
1641
|
countOutgoingEdges(ids) {
|
|
1921
1642
|
const out = new Map();
|
|
1922
1643
|
if (ids.length === 0)
|
|
@@ -1933,32 +1654,13 @@ class QueryBuilder {
|
|
|
1933
1654
|
}
|
|
1934
1655
|
return out;
|
|
1935
1656
|
}
|
|
1936
|
-
/**
|
|
1937
|
-
* Symbols nothing in the index points at — the candidate set behind the dead
|
|
1938
|
-
* code list (`src/graph/dead-code.ts`).
|
|
1939
|
-
*
|
|
1940
|
-
* "Points at" is every edge kind EXCEPT `contains`: a class containing a
|
|
1941
|
-
* method is structure, not use, and counting it would make every member look
|
|
1942
|
-
* reached by its own container. A self-edge is excluded for the same reason
|
|
1943
|
-
* a recursive function is not its own caller.
|
|
1944
|
-
*
|
|
1945
|
-
* One scan, one index probe per candidate. `NOT EXISTS` over
|
|
1946
|
-
* `idx_edges_target_kind` is what keeps it that way — the alternative
|
|
1947
|
-
* (`LEFT JOIN edges … GROUP BY`) builds a row per edge for the whole table
|
|
1948
|
-
* before discarding all but the empty groups. Ordered by position so the
|
|
1949
|
-
* answer is stable across runs and groups by file without a second sort.
|
|
1950
|
-
*
|
|
1951
|
-
* The result is deliberately NOT called dead code: an unreferenced symbol is
|
|
1952
|
-
* a symbol with no STATIC reference, and the caller applies the exclusions
|
|
1953
|
-
* (tests, generated files, overrides, unresolved names) that turn the
|
|
1954
|
-
* candidate set into a claim worth making.
|
|
1955
|
-
*/
|
|
1956
1657
|
getUnreferencedNodes(kinds, limit) {
|
|
1957
1658
|
if (kinds.length === 0 || limit <= 0)
|
|
1958
1659
|
return [];
|
|
1959
1660
|
const placeholders = kinds.map(() => '?').join(',');
|
|
1661
|
+
const generated = this.hasSchema('files', 'generated') ? 'COALESCE(f.generated, 0)' : '0';
|
|
1960
1662
|
const rows = this.db
|
|
1961
|
-
.prepare(`SELECT n.*,
|
|
1663
|
+
.prepare(`SELECT n.*, ${generated} AS file_generated
|
|
1962
1664
|
FROM nodes n
|
|
1963
1665
|
LEFT JOIN files f ON f.path = n.file_path
|
|
1964
1666
|
WHERE n.kind IN (${placeholders})
|
|
@@ -1973,84 +1675,84 @@ class QueryBuilder {
|
|
|
1973
1675
|
.all(...kinds, limit);
|
|
1974
1676
|
return rows.map((row) => ({ node: rowToNode(row), generated: row.file_generated === 1 }));
|
|
1975
1677
|
}
|
|
1976
|
-
/**
|
|
1977
|
-
* Which of `names` the index holds an UNRESOLVED reference to.
|
|
1978
|
-
*
|
|
1979
|
-
* The point is honesty about our own blind spots. A `failed` row in
|
|
1980
|
-
* `unresolved_refs` records that some file referenced a name and the resolver
|
|
1981
|
-
* could not decide what it meant — so a symbol with that name cannot be
|
|
1982
|
-
* called unreferenced, whatever the edge table says. It is deliberately
|
|
1983
|
-
* matched loosely, on the reference name AND on its tail (`util.greet` →
|
|
1984
|
-
* `greet`), because the question being asked is "could this name be the one
|
|
1985
|
-
* we failed to follow", and a maybe has to count as a yes.
|
|
1986
|
-
*
|
|
1987
|
-
* Bounded-lookup like {@link getGeneratedPathsAmong}: the caller holds a
|
|
1988
|
-
* candidate list, so this is a chunked probe over `idx_unresolved_name`, not
|
|
1989
|
-
* a scan of the table.
|
|
1990
|
-
*/
|
|
1991
1678
|
getUnresolvedNamesAmong(names) {
|
|
1992
1679
|
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
1993
1680
|
const found = new Set();
|
|
1994
1681
|
if (unique.length === 0)
|
|
1995
1682
|
return found;
|
|
1683
|
+
const parked = this.hasSchema('unresolved_refs', 'status');
|
|
1996
1684
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1997
1685
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1998
1686
|
const placeholders = chunk.map(() => '?').join(',');
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
1687
|
+
const byName = `SELECT DISTINCT reference_name AS name FROM unresolved_refs
|
|
1688
|
+
WHERE reference_name IN (${placeholders})`;
|
|
1689
|
+
const rows = (parked
|
|
1690
|
+
? this.db
|
|
1691
|
+
.prepare(`${byName}
|
|
2002
1692
|
UNION
|
|
2003
1693
|
SELECT DISTINCT name_tail AS name FROM unresolved_refs
|
|
2004
|
-
WHERE name_tail IN (${placeholders})
|
|
2005
|
-
|
|
1694
|
+
WHERE name_tail IN (${placeholders})
|
|
1695
|
+
UNION
|
|
1696
|
+
SELECT DISTINCT ${reference_tail_1.MEMBER_TAIL_SQL} AS name FROM unresolved_refs
|
|
1697
|
+
WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
|
|
1698
|
+
.all(...chunk, ...chunk, ...chunk)
|
|
1699
|
+
: this.db.prepare(byName).all(...chunk));
|
|
2006
1700
|
for (const row of rows)
|
|
2007
1701
|
found.add(row.name);
|
|
2008
1702
|
}
|
|
2009
1703
|
return found;
|
|
2010
1704
|
}
|
|
2011
|
-
/**
|
|
2012
|
-
* Which of `nodeIds` extend or implement a type the resolver could not follow.
|
|
2013
|
-
* An ancestor outside the index (`React.Component`, `stream.Transform`, a
|
|
2014
|
-
* framework interface) leaves no edge, only this `extends` / `implements`
|
|
2015
|
-
* row, so it is the one record that such an ancestor exists (#1973).
|
|
2016
|
-
* Chunked probe over `idx_unresolved_from_node`.
|
|
2017
|
-
*/
|
|
2018
1705
|
getUnresolvedSupertypeSourcesAmong(nodeIds) {
|
|
1706
|
+
return new Set(this.getUnresolvedReferenceNamesFrom(nodeIds, ['extends', 'implements']).keys());
|
|
1707
|
+
}
|
|
1708
|
+
getUnresolvedReferenceNamesFrom(nodeIds, kinds) {
|
|
2019
1709
|
const unique = [...new Set(nodeIds)];
|
|
2020
|
-
const found = new
|
|
1710
|
+
const found = new Map();
|
|
1711
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
1712
|
+
return found;
|
|
1713
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
2021
1714
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2022
1715
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2023
1716
|
const placeholders = chunk.map(() => '?').join(',');
|
|
2024
1717
|
const rows = this.db
|
|
2025
|
-
.prepare(`SELECT DISTINCT from_node_id AS id FROM unresolved_refs
|
|
1718
|
+
.prepare(`SELECT DISTINCT from_node_id AS id, reference_name AS name FROM unresolved_refs
|
|
2026
1719
|
WHERE from_node_id IN (${placeholders})
|
|
2027
|
-
AND reference_kind IN (
|
|
2028
|
-
.all(...chunk);
|
|
2029
|
-
for (const row of rows)
|
|
2030
|
-
found.
|
|
1720
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
1721
|
+
.all(...chunk, ...kinds);
|
|
1722
|
+
for (const row of rows) {
|
|
1723
|
+
const names = found.get(row.id);
|
|
1724
|
+
if (names)
|
|
1725
|
+
names.push(row.name);
|
|
1726
|
+
else
|
|
1727
|
+
found.set(row.id, [row.name]);
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
return found;
|
|
1731
|
+
}
|
|
1732
|
+
getUnresolvedReferenceSourcesNamed(names, kinds) {
|
|
1733
|
+
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
1734
|
+
const found = new Map();
|
|
1735
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
1736
|
+
return found;
|
|
1737
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
1738
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1739
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1740
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1741
|
+
const rows = this.db
|
|
1742
|
+
.prepare(`SELECT DISTINCT reference_name AS name, from_node_id AS id FROM unresolved_refs
|
|
1743
|
+
WHERE reference_name IN (${placeholders})
|
|
1744
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
1745
|
+
.all(...chunk, ...kinds);
|
|
1746
|
+
for (const row of rows) {
|
|
1747
|
+
const ids = found.get(row.name);
|
|
1748
|
+
if (ids)
|
|
1749
|
+
ids.add(row.id);
|
|
1750
|
+
else
|
|
1751
|
+
found.set(row.name, new Set([row.id]));
|
|
1752
|
+
}
|
|
2031
1753
|
}
|
|
2032
1754
|
return found;
|
|
2033
1755
|
}
|
|
2034
|
-
/**
|
|
2035
|
-
* Which of `names` are carried by MORE THAN ONE symbol, at least one of which
|
|
2036
|
-
* something points at.
|
|
2037
|
-
*
|
|
2038
|
-
* The false positive this exists to kill: `CodeGraph.getTopRouteFile` calls
|
|
2039
|
-
* `this.queries.getTopRouteFile()`, and the resolver — which prefers a
|
|
2040
|
-
* same-name definition in the call site's own file — attaches that edge to
|
|
2041
|
-
* the *calling* method. One of the two ends up with a self-edge and the other
|
|
2042
|
-
* with nothing at all, and neither is unreferenced. From the edge table the
|
|
2043
|
-
* mis-resolution and a genuinely unused twin are the same picture, so the
|
|
2044
|
-
* claim is not made about either.
|
|
2045
|
-
*
|
|
2046
|
-
* Both halves of the condition are load-bearing. **More than one symbol**:
|
|
2047
|
-
* a uniquely-named function that only calls itself is genuinely dead, and
|
|
2048
|
-
* excluding every recursive function would gut the list. **Self-edges
|
|
2049
|
-
* counted**: the self-edge IS the fingerprint of the mis-resolution above, so
|
|
2050
|
-
* it has to count as evidence that this name resolves somewhere.
|
|
2051
|
-
*
|
|
2052
|
-
* Chunked probe over `idx_nodes_name`, bounded by the caller's candidate list.
|
|
2053
|
-
*/
|
|
2054
1756
|
getAmbiguousReferencedNames(names) {
|
|
2055
1757
|
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
2056
1758
|
const found = new Set();
|
|
@@ -2077,22 +1779,6 @@ class QueryBuilder {
|
|
|
2077
1779
|
}
|
|
2078
1780
|
return found;
|
|
2079
1781
|
}
|
|
2080
|
-
/**
|
|
2081
|
-
* Which of the given languages the index records an EXPORT marker for.
|
|
2082
|
-
*
|
|
2083
|
-
* A self-measurement, and the honest basis for a whole class of exclusion.
|
|
2084
|
-
* The dead code report's strongest filter is "exported symbols may be reached
|
|
2085
|
-
* from outside this repository" — and that filter silently does nothing for a
|
|
2086
|
-
* language whose exports are not recorded, either because the extractor does
|
|
2087
|
-
* not record them (Rust `pub`) or because the language has no such concept at
|
|
2088
|
-
* all (Python, C, Ruby: the header or the module IS the surface). Rather than
|
|
2089
|
-
* carry a table of which is which, ask the index: if nothing in this language
|
|
2090
|
-
* is marked exported, the filter did not run, and no claim about outside
|
|
2091
|
-
* reachability can be made for it.
|
|
2092
|
-
*
|
|
2093
|
-
* `idx_nodes_language` covers the grouping; the caller passes the handful of
|
|
2094
|
-
* languages its candidates are actually in.
|
|
2095
|
-
*/
|
|
2096
1782
|
getLanguagesWithExports(languages) {
|
|
2097
1783
|
const unique = [...new Set(languages)].filter((language) => language.length > 0);
|
|
2098
1784
|
const found = new Set();
|
|
@@ -2113,17 +1799,6 @@ class QueryBuilder {
|
|
|
2113
1799
|
}
|
|
2114
1800
|
return found;
|
|
2115
1801
|
}
|
|
2116
|
-
/**
|
|
2117
|
-
* The nodes with the most DISTINCT dependents, most first.
|
|
2118
|
-
*
|
|
2119
|
-
* "Distinct" is the difference that matters: a helper called forty times from
|
|
2120
|
-
* one function has a fan-in of 40 but exactly one dependent. This counts the
|
|
2121
|
-
* second thing — the number a reader means by "N callers" — so the top of
|
|
2122
|
-
* this list is the set of symbols a change actually radiates furthest from.
|
|
2123
|
-
*
|
|
2124
|
-
* `contains` is excluded because it is structure, not dependency: counting it
|
|
2125
|
-
* would rank every file and class above the code they hold.
|
|
2126
|
-
*/
|
|
2127
1802
|
getTopDependedOn(limit) {
|
|
2128
1803
|
if (limit <= 0)
|
|
2129
1804
|
return [];
|
|
@@ -2137,30 +1812,6 @@ class QueryBuilder {
|
|
|
2137
1812
|
.all(limit);
|
|
2138
1813
|
return rows;
|
|
2139
1814
|
}
|
|
2140
|
-
/**
|
|
2141
|
-
* The graph's executable roots — files that RUN something at module level,
|
|
2142
|
-
* ranked by how much of the project they set in motion.
|
|
2143
|
-
*
|
|
2144
|
-
* The engine records a statement at the top level of a file as an edge from
|
|
2145
|
-
* the *file* node, so `src/bin/codegraph.ts` calling `program.parse()` at
|
|
2146
|
-
* module scope is a `calls` edge out of a `file`. That set is what makes the
|
|
2147
|
-
* roots of a dependency graph visible: a library module holds definitions and
|
|
2148
|
-
* runs nothing until someone imports it, while a CLI, a worker entry or a
|
|
2149
|
-
* build script does its work on the way down the file. `instantiates` counts
|
|
2150
|
-
* the same way — `new Server(...)` at module scope is the same act.
|
|
2151
|
-
*
|
|
2152
|
-
* A call made while initializing a module-level `variable` / `constant` —
|
|
2153
|
-
* `const service = new Service()`, `app = FastAPI()` — is attributed to the
|
|
2154
|
-
* declared name (#693), not to the file, so the file's own edges alone would
|
|
2155
|
-
* miss most of what a real entry point runs. Those names are the file's
|
|
2156
|
-
* top-level code too, so `tops` counts them alongside the file node.
|
|
2157
|
-
*
|
|
2158
|
-
* Ranking multiplies the two things an entry point does: it runs (calls), and
|
|
2159
|
-
* it wires the project together (distinct other files its symbols reach). One
|
|
2160
|
-
* alone is misleading — a registration table makes hundreds of module-level
|
|
2161
|
-
* calls into itself, and a barrel file imports everything and runs nothing.
|
|
2162
|
-
* The product puts the file that does both at the top.
|
|
2163
|
-
*/
|
|
2164
1815
|
getTopCallingFiles(limit) {
|
|
2165
1816
|
if (limit <= 0)
|
|
2166
1817
|
return [];
|
|
@@ -2209,15 +1860,6 @@ class QueryBuilder {
|
|
|
2209
1860
|
LIMIT ?`)
|
|
2210
1861
|
.all(limit);
|
|
2211
1862
|
}
|
|
2212
|
-
/**
|
|
2213
|
-
* How many OTHER files depend on each of the given files.
|
|
2214
|
-
*
|
|
2215
|
-
* Counted through the symbols, not the file nodes: an `imports` edge points
|
|
2216
|
-
* at the imported symbol, so a file node almost never receives one and
|
|
2217
|
-
* counting edges into it would report every file as depended on by nobody.
|
|
2218
|
-
* Same-file edges are excluded, which is what makes zero mean "nothing else
|
|
2219
|
-
* in the index reaches into this file" — the honest reading of a root.
|
|
2220
|
-
*/
|
|
2221
1863
|
getFileDependentCounts(filePaths) {
|
|
2222
1864
|
if (filePaths.length === 0)
|
|
2223
1865
|
return [];
|
|
@@ -2232,17 +1874,6 @@ class QueryBuilder {
|
|
|
2232
1874
|
GROUP BY tn.file_path`)
|
|
2233
1875
|
.all(JSON.stringify(filePaths));
|
|
2234
1876
|
}
|
|
2235
|
-
/**
|
|
2236
|
-
* How far each of the given files reaches OUT: distinct other files its
|
|
2237
|
-
* symbols touch, and how many references that is.
|
|
2238
|
-
*
|
|
2239
|
-
* The mirror of {@link getFileDependentCounts}, and the same reasoning about
|
|
2240
|
-
* `contains` and same-file edges applies. It is driven from `nodes` rather
|
|
2241
|
-
* than from `edges` so the work is proportional to the files asked about —
|
|
2242
|
-
* the entry-points endpoint asks it about every test file in the index, and
|
|
2243
|
-
* an edge-first plan would scan the whole table to answer a question about a
|
|
2244
|
-
* tenth of it.
|
|
2245
|
-
*/
|
|
2246
1877
|
getFileReachCounts(filePaths) {
|
|
2247
1878
|
if (filePaths.length === 0)
|
|
2248
1879
|
return [];
|
|
@@ -2259,13 +1890,6 @@ class QueryBuilder {
|
|
|
2259
1890
|
GROUP BY sn.file_path`)
|
|
2260
1891
|
.all(JSON.stringify(filePaths));
|
|
2261
1892
|
}
|
|
2262
|
-
/**
|
|
2263
|
-
* The `file` nodes for the given paths, in one query.
|
|
2264
|
-
*
|
|
2265
|
-
* A file's own node is what makes a file row navigable, and looking it up
|
|
2266
|
-
* with {@link getNodesInFile} means materialising every symbol in the file to
|
|
2267
|
-
* throw all but one away.
|
|
2268
|
-
*/
|
|
2269
1893
|
getFileNodes(filePaths) {
|
|
2270
1894
|
if (filePaths.length === 0)
|
|
2271
1895
|
return [];
|
|
@@ -2276,39 +1900,6 @@ class QueryBuilder {
|
|
|
2276
1900
|
.all(JSON.stringify(filePaths));
|
|
2277
1901
|
return rows.map(rowToNode);
|
|
2278
1902
|
}
|
|
2279
|
-
/**
|
|
2280
|
-
* Roll the whole edge table up to module granularity in one pass.
|
|
2281
|
-
*
|
|
2282
|
-
* The caller decides what a module IS — it hands in a file → module
|
|
2283
|
-
* assignment and gets back the cross-module traffic. That split is
|
|
2284
|
-
* deliberate: naming modules is a *policy* (top-level directories, a façade
|
|
2285
|
-
* file kept separate, a monorepo root) that belongs where the reader lives,
|
|
2286
|
-
* while grouping a million edges by it is *mechanics* that must happen in
|
|
2287
|
-
* SQLite. Doing the fold in JavaScript instead means materialising every
|
|
2288
|
-
* cross-file edge in memory; doing the naming in SQL means a tower of
|
|
2289
|
-
* `instr`/`substr` no one can read.
|
|
2290
|
-
*
|
|
2291
|
-
* The assignment lands in a TEMP table with a primary key, so the join is
|
|
2292
|
-
* indexed and the result set is bounded by modules², not by edges. Temp
|
|
2293
|
-
* tables live in SQLite's own temp database, so this stays valid against a
|
|
2294
|
-
* read-only main.
|
|
2295
|
-
*
|
|
2296
|
-
* Two result sets, because they need two different groupings over the same
|
|
2297
|
-
* join: `links` counts edges per (module, module, kind), and `pairs` names
|
|
2298
|
-
* the busiest symbol pairs behind each link (the map's tooltip). `pairs` is
|
|
2299
|
-
* ranked and cut inside SQLite — the un-cut grouping is the one thing here
|
|
2300
|
-
* that scales with distinct symbol names rather than with modules. Pairs are
|
|
2301
|
-
* ranked by `declared` before raw count, so a link's tooltip names the
|
|
2302
|
-
* symbols the source actually points at rather than whichever `has`/`get`
|
|
2303
|
-
* happened to name-match most often.
|
|
2304
|
-
*
|
|
2305
|
-
* `declared` is the subset of a link's edges that came from something the
|
|
2306
|
-
* source *writes down*: an import, a qualified name, an inheritance clause,
|
|
2307
|
-
* or a call through a typed receiver. It exists because bare name matching
|
|
2308
|
-
* (`resolvedBy: 'exact-match'`) is what invents cross-module links out of
|
|
2309
|
-
* common method names — `run`, `push`, `finish` — and a map that lets those
|
|
2310
|
-
* decide the layering puts the storage layer above the CLI.
|
|
2311
|
-
*/
|
|
2312
1903
|
aggregateModuleGraph(assignments, options) {
|
|
2313
1904
|
if (assignments.length === 0 || options.kinds.length === 0)
|
|
2314
1905
|
return { links: [], pairs: [] };
|
|
@@ -2331,13 +1922,6 @@ class QueryBuilder {
|
|
|
2331
1922
|
this.db.exec('ROLLBACK');
|
|
2332
1923
|
throw err;
|
|
2333
1924
|
}
|
|
2334
|
-
// ONE pass over the edge table. Grouping by the symbol names as well as
|
|
2335
|
-
// the modules costs nothing extra in scan time — the join is what is
|
|
2336
|
-
// expensive — and it buys both results from a single scan. Measured on
|
|
2337
|
-
// this index inflated to 1.6M edges: 1.66s for this query against 3.0s
|
|
2338
|
-
// for the module-level and name-level queries run separately, which is
|
|
2339
|
-
// the difference between meeting and missing the map's cold budget on a
|
|
2340
|
-
// ten-thousand-file repository.
|
|
2341
1925
|
const rows = this.db
|
|
2342
1926
|
.prepare(`SELECT ms.mod AS source, mt.mod AS target, e.kind AS kind,
|
|
2343
1927
|
sn.name AS "from", tn.name AS "to",
|
|
@@ -2359,20 +1943,6 @@ class QueryBuilder {
|
|
|
2359
1943
|
this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
|
|
2360
1944
|
}
|
|
2361
1945
|
}
|
|
2362
|
-
/**
|
|
2363
|
-
* Every ordered pair of files where one reaches into the other, once each.
|
|
2364
|
-
*
|
|
2365
|
-
* The input a cycle finder wants: file-level circular dependencies are the
|
|
2366
|
-
* strongly connected components of this graph. One query instead of the
|
|
2367
|
-
* dependency lookup per file that {@link GraphQueryManager.findCircularDependencies}
|
|
2368
|
-
* does — which matters because a cycle report is only interesting on a large
|
|
2369
|
-
* repo, and that is exactly where a query per file stops being affordable.
|
|
2370
|
-
*
|
|
2371
|
-
* `contains` is excluded (a file "contains" its own symbols, which is not a
|
|
2372
|
-
* dependency), and so are same-file edges and low-confidence name matches:
|
|
2373
|
-
* a cycle conjured by a common method name is a false alarm a reader cannot
|
|
2374
|
-
* check.
|
|
2375
|
-
*/
|
|
2376
1946
|
getCrossFileDependencyPairs(minConfidence) {
|
|
2377
1947
|
return this.db
|
|
2378
1948
|
.prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
|
|
@@ -2384,20 +1954,16 @@ class QueryBuilder {
|
|
|
2384
1954
|
AND COALESCE(json_extract(e.metadata, '$.confidence'), 1) >= ?`)
|
|
2385
1955
|
.all(minConfidence);
|
|
2386
1956
|
}
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
* per row, and a generated file with fifty thousand of them would ship
|
|
2398
|
-
* megabytes to say something a count already says. Rows come back in line
|
|
2399
|
-
* order, so a cap trims the END of the file, which is at least legible.
|
|
2400
|
-
*/
|
|
1957
|
+
getFileImportPairs() {
|
|
1958
|
+
return this.db
|
|
1959
|
+
.prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
|
|
1960
|
+
FROM edges e
|
|
1961
|
+
JOIN nodes sn ON sn.id = e.source
|
|
1962
|
+
JOIN nodes tn ON tn.id = e.target
|
|
1963
|
+
WHERE e.kind = 'imports'
|
|
1964
|
+
AND sn.file_path <> tn.file_path`)
|
|
1965
|
+
.all();
|
|
1966
|
+
}
|
|
2401
1967
|
getUnresolvedReferencesInFile(filePath, limit = 5000) {
|
|
2402
1968
|
if (!this.stmts.getUnresolvedInFile) {
|
|
2403
1969
|
this.stmts.getUnresolvedInFile = this.db.prepare('SELECT * FROM unresolved_refs WHERE file_path = ? ORDER BY line, col LIMIT ?');
|
|
@@ -2415,15 +1981,59 @@ class QueryBuilder {
|
|
|
2415
1981
|
rowId: row.id,
|
|
2416
1982
|
}));
|
|
2417
1983
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
1984
|
+
getFailedReferencesByTail(tail, excludeKinds, limit) {
|
|
1985
|
+
if (!tail)
|
|
1986
|
+
return { refs: [], total: 0 };
|
|
1987
|
+
const kindFilter = excludeKinds.length > 0
|
|
1988
|
+
? ` AND reference_kind NOT IN (${excludeKinds.map(() => '?').join(',')})`
|
|
1989
|
+
: '';
|
|
1990
|
+
const where = `WHERE status = 'failed' AND name_tail = ?${kindFilter}`;
|
|
1991
|
+
const total = this.db
|
|
1992
|
+
.prepare(`SELECT COUNT(*) AS n FROM unresolved_refs ${where}`)
|
|
1993
|
+
.get(tail, ...excludeKinds).n;
|
|
1994
|
+
if (total === 0 || limit <= 0)
|
|
1995
|
+
return { refs: [], total };
|
|
1996
|
+
const rows = this.db
|
|
1997
|
+
.prepare(`SELECT * FROM unresolved_refs ${where} ORDER BY file_path, line, col LIMIT ?`)
|
|
1998
|
+
.all(tail, ...excludeKinds, limit);
|
|
1999
|
+
return {
|
|
2000
|
+
total,
|
|
2001
|
+
refs: rows.map((row) => ({
|
|
2002
|
+
fromNodeId: row.from_node_id,
|
|
2003
|
+
referenceName: row.reference_name,
|
|
2004
|
+
referenceKind: row.reference_kind,
|
|
2005
|
+
line: row.line,
|
|
2006
|
+
column: row.col,
|
|
2007
|
+
filePath: row.file_path,
|
|
2008
|
+
language: row.language,
|
|
2009
|
+
rowId: row.id,
|
|
2010
|
+
})),
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
getFailedReferencesByNames(names, limit) {
|
|
2014
|
+
const unique = [...new Set(names)].filter((n) => n.length > 0);
|
|
2015
|
+
if (unique.length === 0 || limit <= 0)
|
|
2016
|
+
return [];
|
|
2017
|
+
const rows = [];
|
|
2018
|
+
for (let i = 0; i < unique.length && rows.length < limit; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2019
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2020
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2021
|
+
rows.push(...this.db
|
|
2022
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE reference_name IN (${placeholders}) AND status = 'failed'
|
|
2023
|
+
ORDER BY file_path, line, col LIMIT ?`)
|
|
2024
|
+
.all(...chunk, limit - rows.length));
|
|
2025
|
+
}
|
|
2026
|
+
return rows.map((row) => ({
|
|
2027
|
+
fromNodeId: row.from_node_id,
|
|
2028
|
+
referenceName: row.reference_name,
|
|
2029
|
+
referenceKind: row.reference_kind,
|
|
2030
|
+
line: row.line,
|
|
2031
|
+
column: row.col,
|
|
2032
|
+
filePath: row.file_path,
|
|
2033
|
+
language: row.language,
|
|
2034
|
+
rowId: row.id,
|
|
2035
|
+
}));
|
|
2036
|
+
}
|
|
2427
2037
|
getUnresolvedReferencesFrom(fromNodeId) {
|
|
2428
2038
|
if (!this.stmts.getUnresolvedFromNode) {
|
|
2429
2039
|
this.stmts.getUnresolvedFromNode = this.db.prepare('SELECT * FROM unresolved_refs WHERE from_node_id = ?');
|
|
@@ -2441,10 +2051,35 @@ class QueryBuilder {
|
|
|
2441
2051
|
rowId: row.id,
|
|
2442
2052
|
}));
|
|
2443
2053
|
}
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2054
|
+
getUnresolvedReferencesFromNodes(nodeIds, kinds) {
|
|
2055
|
+
const unique = [...new Set(nodeIds)];
|
|
2056
|
+
const found = [];
|
|
2057
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
2058
|
+
return found;
|
|
2059
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
2060
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2061
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2062
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2063
|
+
const rows = this.db
|
|
2064
|
+
.prepare(`SELECT * FROM unresolved_refs
|
|
2065
|
+
WHERE from_node_id IN (${placeholders})
|
|
2066
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
2067
|
+
.all(...chunk, ...kinds);
|
|
2068
|
+
for (const row of rows) {
|
|
2069
|
+
found.push({
|
|
2070
|
+
fromNodeId: row.from_node_id,
|
|
2071
|
+
referenceName: row.reference_name,
|
|
2072
|
+
referenceKind: row.reference_kind,
|
|
2073
|
+
line: row.line,
|
|
2074
|
+
column: row.col,
|
|
2075
|
+
filePath: row.file_path,
|
|
2076
|
+
language: row.language,
|
|
2077
|
+
rowId: row.id,
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
return found;
|
|
2082
|
+
}
|
|
2448
2083
|
findEdgesBetweenNodes(nodeIds, kinds) {
|
|
2449
2084
|
if (nodeIds.length === 0)
|
|
2450
2085
|
return [];
|
|
@@ -2458,39 +2093,18 @@ class QueryBuilder {
|
|
|
2458
2093
|
const rows = this.db.prepare(sql).all(...params);
|
|
2459
2094
|
return rows.map(rowToEdge);
|
|
2460
2095
|
}
|
|
2461
|
-
|
|
2462
|
-
* Distinct file paths that DEPEND ON `filePath`: every file containing a
|
|
2463
|
-
* symbol with a cross-file edge (any kind except `contains`) into a symbol
|
|
2464
|
-
* of this file. This is the file-level projection of the symbol dependency
|
|
2465
|
-
* graph and the basis for blast-radius / `affected` test selection.
|
|
2466
|
-
*
|
|
2467
|
-
* It deliberately does NOT restrict to `imports` edges. In this graph an
|
|
2468
|
-
* `imports` edge connects a file to its own local import declarations
|
|
2469
|
-
* (it is always same-file), so an imports-only lookup returns zero
|
|
2470
|
-
* cross-file dependents for every file. The real cross-file dependency
|
|
2471
|
-
* signal is the resolved call/reference graph — calls, references,
|
|
2472
|
-
* instantiates, extends, implements, overrides, type_of, returns,
|
|
2473
|
-
* decorates — exactly what {@link GraphTraverser.getImpactRadius} traverses.
|
|
2474
|
-
* `contains` is excluded: a parent containing a symbol does not *depend* on
|
|
2475
|
-
* it. One indexed query (idx_nodes_file_path + idx_edges_target_kind).
|
|
2476
|
-
*/
|
|
2477
|
-
getDependentFilePaths(filePath) {
|
|
2096
|
+
getDependentFilePaths(filePath, opts = {}) {
|
|
2478
2097
|
const sql = `SELECT DISTINCT src.file_path AS fp
|
|
2479
2098
|
FROM edges e
|
|
2480
2099
|
JOIN nodes tgt ON tgt.id = e.target
|
|
2481
2100
|
JOIN nodes src ON src.id = e.source
|
|
2482
2101
|
WHERE tgt.file_path = ?
|
|
2483
2102
|
AND e.kind != 'contains'
|
|
2484
|
-
AND src.file_path !=
|
|
2103
|
+
AND src.file_path != ?${opts.skipTiers ? `
|
|
2104
|
+
AND (e.metadata IS NULL OR json_extract(e.metadata, '$.tier') IS NULL)` : ''}`;
|
|
2485
2105
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2486
2106
|
return rows.map((r) => r.fp);
|
|
2487
2107
|
}
|
|
2488
|
-
/**
|
|
2489
|
-
* Distinct file paths that `filePath` DEPENDS ON — the inverse of
|
|
2490
|
-
* {@link getDependentFilePaths}: every file containing a symbol that a
|
|
2491
|
-
* symbol of this file has a cross-file edge into. Same edge-kind rules
|
|
2492
|
-
* (all kinds except `contains`); same reason imports-only is insufficient.
|
|
2493
|
-
*/
|
|
2494
2108
|
getDependencyFilePaths(filePath) {
|
|
2495
2109
|
const sql = `SELECT DISTINCT tgt.file_path AS fp
|
|
2496
2110
|
FROM edges e
|
|
@@ -2502,17 +2116,6 @@ class QueryBuilder {
|
|
|
2502
2116
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2503
2117
|
return rows.map((r) => r.fp);
|
|
2504
2118
|
}
|
|
2505
|
-
/**
|
|
2506
|
-
* Cross-file edges whose TARGET is a node in `filePath` and whose SOURCE is a
|
|
2507
|
-
* node in a *different* file, paired with the target node's (name, kind).
|
|
2508
|
-
* Node IDs are `sha256(filePath:kind:name:line)`, so any line shift in the
|
|
2509
|
-
* callee file changes target IDs and a naive re-insert by old ID silently
|
|
2510
|
-
* drops them; `storeExtractionResult` instead follows each old target to the
|
|
2511
|
-
* re-indexed node that replaces it (see {@link getNodeIdentitiesByFile}) to
|
|
2512
|
-
* preserve incoming edges across a file re-index (issue #899). Same
|
|
2513
|
-
* edge-kind rules as {@link getDependentFilePaths}: all kinds except
|
|
2514
|
-
* `contains`.
|
|
2515
|
-
*/
|
|
2516
2119
|
getCrossFileIncomingEdgesWithTarget(filePath) {
|
|
2517
2120
|
const sql = `SELECT e.*, tgt.name AS target_name, tgt.kind AS target_kind,
|
|
2518
2121
|
src.file_path AS source_file_path, src.language AS source_language
|
|
@@ -2525,154 +2128,277 @@ class QueryBuilder {
|
|
|
2525
2128
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2526
2129
|
return rows.map(row => ({
|
|
2527
2130
|
...rowToEdge(row),
|
|
2131
|
+
edgeId: row.id,
|
|
2528
2132
|
targetName: row.target_name,
|
|
2529
2133
|
targetKind: row.target_kind,
|
|
2530
2134
|
sourceFilePath: row.source_file_path,
|
|
2531
2135
|
sourceLanguage: row.source_language,
|
|
2532
2136
|
}));
|
|
2533
2137
|
}
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
`);
|
|
2555
|
-
}
|
|
2556
|
-
this.stmts.upsertFile.run({
|
|
2557
|
-
path: file.path,
|
|
2558
|
-
contentHash: file.contentHash,
|
|
2559
|
-
language: file.language,
|
|
2560
|
-
size: file.size,
|
|
2561
|
-
modifiedAt: file.modifiedAt,
|
|
2562
|
-
indexedAt: file.indexedAt,
|
|
2563
|
-
nodeCount: file.nodeCount,
|
|
2564
|
-
errors: file.errors ? JSON.stringify(file.errors) : null,
|
|
2565
|
-
// The upsert always REWRITES the flag: a file that loses its banner in an
|
|
2566
|
-
// edit must lose the flag on the next sync, not keep a stale 1.
|
|
2567
|
-
generated: file.generated ? 1 : 0,
|
|
2568
|
-
});
|
|
2138
|
+
getResolutionEdgesThrough(filePath, names) {
|
|
2139
|
+
const rows = this.db
|
|
2140
|
+
.prepare(`SELECT * FROM (
|
|
2141
|
+
SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path,
|
|
2142
|
+
CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
|
|
2143
|
+
FROM nodes src
|
|
2144
|
+
JOIN edges e ON e.source = src.id
|
|
2145
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2146
|
+
WHERE src.file_path = ?
|
|
2147
|
+
AND e.kind != 'contains'
|
|
2148
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2149
|
+
) WHERE ${THROUGH_NAMES('ref_name')}`)
|
|
2150
|
+
.all(filePath, JSON.stringify(names), JSON.stringify(names));
|
|
2151
|
+
return rows.map((row) => ({
|
|
2152
|
+
...rowToEdge(row),
|
|
2153
|
+
edgeId: row.id,
|
|
2154
|
+
sourceFilePath: row.source_file_path,
|
|
2155
|
+
sourceLanguage: row.source_language,
|
|
2156
|
+
targetFilePath: row.target_file_path,
|
|
2157
|
+
}));
|
|
2569
2158
|
}
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
* Bounded-lookup by design: every consumer already holds a short candidate
|
|
2574
|
-
* list (a ranked file group, an FTS result page, a LIMIT-20 aggregate), so
|
|
2575
|
-
* this stays a partial-index probe over a handful of paths — no whole-repo
|
|
2576
|
-
* set to materialize, and no cache to invalidate, which means a ranking call
|
|
2577
|
-
* can never serve a verdict the last sync already replaced.
|
|
2578
|
-
*
|
|
2579
|
-
* Returns ONLY the content/index signal; callers union it with
|
|
2580
|
-
* {@link isGeneratedFile} so pre-v9 databases (column present, all zeros
|
|
2581
|
-
* until a re-index) keep the path-only behavior rather than regressing.
|
|
2582
|
-
*/
|
|
2583
|
-
getGeneratedPathsAmong(filePaths) {
|
|
2584
|
-
const unique = [...new Set(filePaths)];
|
|
2585
|
-
const found = new Set();
|
|
2586
|
-
if (unique.length === 0)
|
|
2587
|
-
return found;
|
|
2159
|
+
getImportBindingsResolvedElsewhere(filePaths) {
|
|
2160
|
+
const out = [];
|
|
2161
|
+
const unique = [...new Set(filePaths)].map((filePath) => `file:${filePath}`);
|
|
2588
2162
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2589
2163
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2590
2164
|
const placeholders = chunk.map(() => '?').join(',');
|
|
2591
2165
|
const rows = this.db
|
|
2592
|
-
.prepare(`SELECT
|
|
2166
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
|
|
2167
|
+
FROM edges e
|
|
2168
|
+
JOIN nodes src ON src.id = e.source
|
|
2169
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2170
|
+
WHERE e.source IN (${placeholders})
|
|
2171
|
+
AND e.kind = 'imports'
|
|
2172
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2173
|
+
AND json_valid(e.metadata)
|
|
2174
|
+
AND json_extract(e.metadata, '$.resolvedBy') != 'import'`)
|
|
2593
2175
|
.all(...chunk);
|
|
2594
|
-
for (const row of rows)
|
|
2595
|
-
|
|
2176
|
+
for (const row of rows) {
|
|
2177
|
+
out.push({
|
|
2178
|
+
...rowToEdge(row),
|
|
2179
|
+
edgeId: row.id,
|
|
2180
|
+
sourceFilePath: row.source_file_path,
|
|
2181
|
+
sourceLanguage: row.source_language,
|
|
2182
|
+
targetFilePath: row.target_file_path,
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2596
2185
|
}
|
|
2597
|
-
return
|
|
2598
|
-
}
|
|
2599
|
-
/**
|
|
2600
|
-
* A reusable `(path) => boolean` over a bounded candidate list, unioning the
|
|
2601
|
-
* indexed flag with the path convention. This is the shape every ranking
|
|
2602
|
-
* comparator wants: one query up front, then O(1) per comparison.
|
|
2603
|
-
*/
|
|
2604
|
-
generatedPredicateFor(filePaths) {
|
|
2605
|
-
const flagged = this.getGeneratedPathsAmong(filePaths);
|
|
2606
|
-
return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
2186
|
+
return out;
|
|
2607
2187
|
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
* ambient `.d.ts` of global shims, a vendored typings file, module
|
|
2612
|
-
* augmentation: reachable only by name, structurally attached to nothing.
|
|
2613
|
-
*
|
|
2614
|
-
* Structural, not extension-based, so a hand-written `types.ts` and a `.d.ts`
|
|
2615
|
-
* are judged by the same rule and a `.d.ts` that does declare a class or a
|
|
2616
|
-
* const is (correctly) not caught. Four conditions, all required:
|
|
2617
|
-
*
|
|
2618
|
-
* 1. it declares at least one symbol — an empty or unparsed file is not a
|
|
2619
|
-
* declaration file, it is a file we know nothing about;
|
|
2620
|
-
* 2. EVERY declared symbol is a type-level kind (interface / type alias /
|
|
2621
|
-
* enum / namespace). The narrowness is deliberate and measured: a rule
|
|
2622
|
-
* of "no callables" alone flags 1–18% of a repo, including Kotlin sealed
|
|
2623
|
-
* classes, Rust `mod.rs` re-exports and django's locale constant tables —
|
|
2624
|
-
* real source that must not be demoted. This rule flags 0–4%;
|
|
2625
|
-
* 3. no symbol in it originates a `calls`/`instantiates` edge — the direct
|
|
2626
|
-
* evidence that nothing here has a body;
|
|
2627
|
-
* 4. NOTHING ELSE IN THE INDEX points at it. This is the condition that
|
|
2628
|
-
* separates an ambient shim from a working type module, and it is why
|
|
2629
|
-
* the flag is narrow enough to be safe: `displacement-ts`'s pipeline
|
|
2630
|
-
* `types.ts` passes 1–3 identically but carries 13 inbound imports and
|
|
2631
|
-
* 21 references, so the files that answer a query about the pipeline are
|
|
2632
|
-
* typed BY it — it is part of that answer's structure. An ambient
|
|
2633
|
-
* `declare global` shim has zero. Deliberately index-wide rather than
|
|
2634
|
-
* restricted to the candidate list: the file that imports it is usually
|
|
2635
|
-
* not itself a candidate.
|
|
2636
|
-
*
|
|
2637
|
-
* ### Interface MEMBERS are transparent to all four conditions
|
|
2638
|
-
*
|
|
2639
|
-
* A `method_signature` / `property_signature` inside an interface enters the
|
|
2640
|
-
* graph as a `method` / `property` node (#1638). Read literally that would
|
|
2641
|
-
* break every condition here at once: condition 2 sees non-type kinds and
|
|
2642
|
-
* stops flagging, and — worse, because it is silent — condition 4 starts
|
|
2643
|
-
* seeing inbound `calls` edges the moment a call site through the shim's API
|
|
2644
|
-
* finally has a signature to land on. An ambient `.d.ts` would quietly lose
|
|
2645
|
-
* its damping precisely BECAUSE the platform API it declares is widely used.
|
|
2646
|
-
*
|
|
2647
|
-
* So an interface-owned member is treated the way `parameter` already is: it
|
|
2648
|
-
* neither qualifies, disqualifies, nor counts as inbound dependency. That is
|
|
2649
|
-
* not a new judgement call, it is what keeps the rule measuring what it was
|
|
2650
|
-
* measured on — before #1638 these nodes did not exist, so excluding them
|
|
2651
|
-
* reproduces the 0–4% flag rate the thresholds above were tuned against. It
|
|
2652
|
-
* is also the semantically right answer: a signature with no body is on the
|
|
2653
|
-
* same side of the line as the interface that owns it, and a call edge
|
|
2654
|
-
* landing on one is still not a file that can answer a flow question.
|
|
2655
|
-
*
|
|
2656
|
-
* The interface ITSELF is untouched: the `references` edges an importing
|
|
2657
|
-
* module aims at `UploadStorage` still disqualify the file under (4), which
|
|
2658
|
-
* is what keeps a depended-on `types.ts` out of the flag.
|
|
2659
|
-
*
|
|
2660
|
-
* Bounded-lookup like {@link getGeneratedPathsAmong}: callers hold a ranked
|
|
2661
|
-
* candidate list, so this is a partial-index probe over a handful of paths.
|
|
2662
|
-
*/
|
|
2663
|
-
getAmbientDeclarationPathsAmong(filePaths) {
|
|
2664
|
-
const unique = [...new Set(filePaths)];
|
|
2665
|
-
const found = new Set();
|
|
2666
|
-
if (unique.length === 0)
|
|
2667
|
-
return found;
|
|
2188
|
+
getResolutionEdgesInto(targetIds) {
|
|
2189
|
+
const out = [];
|
|
2190
|
+
const unique = [...new Set(targetIds)];
|
|
2668
2191
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2669
2192
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2670
2193
|
const placeholders = chunk.map(() => '?').join(',');
|
|
2671
|
-
// `file`/`import`/`export`/`parameter` are structural bookkeeping, not
|
|
2672
|
-
// things the file declares, so they neither qualify nor disqualify.
|
|
2673
2194
|
const rows = this.db
|
|
2674
|
-
.prepare(`
|
|
2675
|
-
|
|
2195
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
|
|
2196
|
+
FROM edges e
|
|
2197
|
+
JOIN nodes src ON src.id = e.source
|
|
2198
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2199
|
+
WHERE e.target IN (${placeholders})
|
|
2200
|
+
AND e.kind != 'contains'
|
|
2201
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2202
|
+
.all(...chunk);
|
|
2203
|
+
for (const row of rows) {
|
|
2204
|
+
out.push({
|
|
2205
|
+
...rowToEdge(row),
|
|
2206
|
+
edgeId: row.id,
|
|
2207
|
+
sourceFilePath: row.source_file_path,
|
|
2208
|
+
sourceLanguage: row.source_language,
|
|
2209
|
+
targetFilePath: row.target_file_path,
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
return out;
|
|
2214
|
+
}
|
|
2215
|
+
getFailedReferencesThrough(filePath, modules, names) {
|
|
2216
|
+
return this.db
|
|
2217
|
+
.prepare(`SELECT id FROM unresolved_refs
|
|
2218
|
+
WHERE file_path = ? AND status = 'failed'
|
|
2219
|
+
AND ((reference_kind = 'imports' AND reference_name IN (SELECT value FROM json_each(?)))
|
|
2220
|
+
OR ${THROUGH_NAMES('reference_name')})`)
|
|
2221
|
+
.all(filePath, JSON.stringify(modules), JSON.stringify(names), JSON.stringify(names))
|
|
2222
|
+
.map((row) => row.id);
|
|
2223
|
+
}
|
|
2224
|
+
getImportTargetsFromFile(filePath) {
|
|
2225
|
+
return this.db
|
|
2226
|
+
.prepare(`SELECT DISTINCT e.target AS target
|
|
2227
|
+
FROM nodes src
|
|
2228
|
+
JOIN edges e ON e.source = src.id
|
|
2229
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2230
|
+
WHERE src.file_path = ?
|
|
2231
|
+
AND e.kind = 'imports'
|
|
2232
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2233
|
+
AND tgt.file_path != ?`)
|
|
2234
|
+
.all(filePath, filePath)
|
|
2235
|
+
.map((row) => row.target);
|
|
2236
|
+
}
|
|
2237
|
+
getImportsInto(targetId, exceptFile) {
|
|
2238
|
+
return this.db
|
|
2239
|
+
.prepare(`SELECT src.file_path AS file_path, src.language AS language,
|
|
2240
|
+
CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
|
|
2241
|
+
FROM edges e
|
|
2242
|
+
JOIN nodes src ON src.id = e.source
|
|
2243
|
+
WHERE e.target = ? AND e.kind = 'imports' AND src.file_path != ?`)
|
|
2244
|
+
.all(targetId, exceptFile)
|
|
2245
|
+
.map((row) => ({
|
|
2246
|
+
filePath: row.file_path,
|
|
2247
|
+
language: row.language,
|
|
2248
|
+
refName: typeof row.ref_name === 'string' ? row.ref_name : null,
|
|
2249
|
+
}));
|
|
2250
|
+
}
|
|
2251
|
+
getModuleImportsUnder(dir) {
|
|
2252
|
+
const rows = this.db
|
|
2253
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2254
|
+
FROM nodes tgt
|
|
2255
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2256
|
+
JOIN nodes src ON src.id = e.source
|
|
2257
|
+
WHERE tgt.kind = 'file' AND tgt.file_path >= ? AND tgt.file_path < ?`)
|
|
2258
|
+
.all(`${dir}/`, `${dir}0`);
|
|
2259
|
+
return rows.map((row) => ({
|
|
2260
|
+
...rowToEdge(row),
|
|
2261
|
+
edgeId: row.id,
|
|
2262
|
+
targetFilePath: row.target_file_path,
|
|
2263
|
+
sourceFilePath: row.source_file_path,
|
|
2264
|
+
sourceLanguage: row.source_language,
|
|
2265
|
+
}));
|
|
2266
|
+
}
|
|
2267
|
+
getModuleImportsIntoDeclarationFiles() {
|
|
2268
|
+
const rows = this.db
|
|
2269
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2270
|
+
FROM nodes tgt
|
|
2271
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2272
|
+
JOIN nodes src ON src.id = e.source
|
|
2273
|
+
WHERE tgt.kind = 'file'
|
|
2274
|
+
AND (tgt.file_path LIKE '%.d.ts' OR tgt.file_path LIKE '%.d.mts' OR tgt.file_path LIKE '%.d.cts')`)
|
|
2275
|
+
.all();
|
|
2276
|
+
return rows.map((row) => ({
|
|
2277
|
+
...rowToEdge(row),
|
|
2278
|
+
edgeId: row.id,
|
|
2279
|
+
targetFilePath: row.target_file_path,
|
|
2280
|
+
sourceFilePath: row.source_file_path,
|
|
2281
|
+
sourceLanguage: row.source_language,
|
|
2282
|
+
}));
|
|
2283
|
+
}
|
|
2284
|
+
getModuleImportsNamed(dir, name) {
|
|
2285
|
+
const base = dir ? `${dir}/${name}` : name;
|
|
2286
|
+
const rows = this.db
|
|
2287
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2288
|
+
FROM nodes tgt
|
|
2289
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2290
|
+
JOIN nodes src ON src.id = e.source
|
|
2291
|
+
WHERE tgt.kind = 'file'
|
|
2292
|
+
AND ((tgt.file_path >= ? AND tgt.file_path < ?) OR (tgt.file_path >= ? AND tgt.file_path < ?) OR tgt.file_path = ?)`)
|
|
2293
|
+
.all(`${base}.`, `${base}/`, `${base}/index.`, `${base}/index/`, `${base}/__init__.py`);
|
|
2294
|
+
return rows
|
|
2295
|
+
.filter((row) => {
|
|
2296
|
+
const file = row.target_file_path;
|
|
2297
|
+
if (file === `${base}/__init__.py`)
|
|
2298
|
+
return true;
|
|
2299
|
+
const index = `${base}/index.`;
|
|
2300
|
+
return !(file.startsWith(index) ? file.slice(index.length) : file.slice(base.length + 1)).includes('/');
|
|
2301
|
+
})
|
|
2302
|
+
.map((row) => ({
|
|
2303
|
+
...rowToEdge(row),
|
|
2304
|
+
edgeId: row.id,
|
|
2305
|
+
targetFilePath: row.target_file_path,
|
|
2306
|
+
sourceFilePath: row.source_file_path,
|
|
2307
|
+
sourceLanguage: row.source_language,
|
|
2308
|
+
}));
|
|
2309
|
+
}
|
|
2310
|
+
getFilesWithEdgesInto(targetIds) {
|
|
2311
|
+
const files = new Set();
|
|
2312
|
+
for (let i = 0; i < targetIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2313
|
+
const chunk = targetIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2314
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2315
|
+
const rows = this.db
|
|
2316
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
2317
|
+
FROM edges e
|
|
2318
|
+
JOIN nodes src ON src.id = e.source
|
|
2319
|
+
WHERE e.target IN (${placeholders})
|
|
2320
|
+
AND e.kind != 'contains'
|
|
2321
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2322
|
+
.all(...chunk);
|
|
2323
|
+
for (const row of rows)
|
|
2324
|
+
files.add(row.file_path);
|
|
2325
|
+
}
|
|
2326
|
+
return [...files];
|
|
2327
|
+
}
|
|
2328
|
+
getImportNodesByNames(names) {
|
|
2329
|
+
const out = [];
|
|
2330
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2331
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2332
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2333
|
+
const rows = this.db
|
|
2334
|
+
.prepare(`SELECT file_path, name, language FROM nodes WHERE name IN (${placeholders}) AND kind = 'import'`)
|
|
2335
|
+
.all(...chunk);
|
|
2336
|
+
for (const row of rows)
|
|
2337
|
+
out.push({ filePath: row.file_path, name: row.name, language: row.language });
|
|
2338
|
+
}
|
|
2339
|
+
return out;
|
|
2340
|
+
}
|
|
2341
|
+
upsertFile(file) {
|
|
2342
|
+
if (!this.stmts.upsertFile) {
|
|
2343
|
+
this.stmts.upsertFile = this.db.prepare(`
|
|
2344
|
+
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors, generated)
|
|
2345
|
+
VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors, @generated)
|
|
2346
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
2347
|
+
content_hash = @contentHash,
|
|
2348
|
+
language = @language,
|
|
2349
|
+
size = @size,
|
|
2350
|
+
modified_at = @modifiedAt,
|
|
2351
|
+
indexed_at = @indexedAt,
|
|
2352
|
+
node_count = @nodeCount,
|
|
2353
|
+
errors = @errors,
|
|
2354
|
+
generated = @generated
|
|
2355
|
+
`);
|
|
2356
|
+
}
|
|
2357
|
+
this.stmts.upsertFile.run({
|
|
2358
|
+
path: file.path,
|
|
2359
|
+
contentHash: file.contentHash,
|
|
2360
|
+
language: file.language,
|
|
2361
|
+
size: file.size,
|
|
2362
|
+
modifiedAt: file.modifiedAt,
|
|
2363
|
+
indexedAt: file.indexedAt,
|
|
2364
|
+
nodeCount: file.nodeCount,
|
|
2365
|
+
errors: file.errors ? JSON.stringify(file.errors) : null,
|
|
2366
|
+
generated: file.generated ? 1 : 0,
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
getGeneratedPathsAmong(filePaths) {
|
|
2370
|
+
const unique = [...new Set(filePaths)];
|
|
2371
|
+
const found = new Set();
|
|
2372
|
+
if (unique.length === 0)
|
|
2373
|
+
return found;
|
|
2374
|
+
if (!this.hasSchema('files', 'generated'))
|
|
2375
|
+
return found;
|
|
2376
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2377
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2378
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2379
|
+
const rows = this.db
|
|
2380
|
+
.prepare(`SELECT path FROM files WHERE generated = 1 AND path IN (${placeholders})`)
|
|
2381
|
+
.all(...chunk);
|
|
2382
|
+
for (const row of rows)
|
|
2383
|
+
found.add(row.path);
|
|
2384
|
+
}
|
|
2385
|
+
return found;
|
|
2386
|
+
}
|
|
2387
|
+
generatedPredicateFor(filePaths) {
|
|
2388
|
+
const flagged = this.getGeneratedPathsAmong(filePaths);
|
|
2389
|
+
return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
2390
|
+
}
|
|
2391
|
+
getAmbientDeclarationPathsAmong(filePaths) {
|
|
2392
|
+
const unique = [...new Set(filePaths)];
|
|
2393
|
+
const found = new Set();
|
|
2394
|
+
if (unique.length === 0)
|
|
2395
|
+
return found;
|
|
2396
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2397
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2398
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2399
|
+
const rows = this.db
|
|
2400
|
+
.prepare(`
|
|
2401
|
+
SELECT n.file_path AS file_path,
|
|
2676
2402
|
SUM(CASE WHEN n.kind NOT IN ('file','import','export','parameter')
|
|
2677
2403
|
AND NOT ${IS_INTERFACE_MEMBER('n')}
|
|
2678
2404
|
THEN 1 ELSE 0 END) AS declared,
|
|
@@ -2696,17 +2422,12 @@ class QueryBuilder {
|
|
|
2696
2422
|
.all(...candidates).map((r) => r.file_path));
|
|
2697
2423
|
candidates = candidates.filter((p) => !hit.has(p));
|
|
2698
2424
|
};
|
|
2699
|
-
// (3) originates behaviour — a signature has no body to originate from,
|
|
2700
|
-
// so an edge attributed to one is not evidence about this file.
|
|
2701
2425
|
disqualify(`
|
|
2702
2426
|
SELECT DISTINCT n.file_path AS file_path
|
|
2703
2427
|
FROM edges e JOIN nodes n ON n.id = e.source
|
|
2704
2428
|
WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
|
|
2705
2429
|
AND NOT ${IS_INTERFACE_MEMBER('n')}
|
|
2706
2430
|
`);
|
|
2707
|
-
// (4) something outside the file depends on it — but a call that lands on
|
|
2708
|
-
// an interface's own signature is a use of the API, not a dependency on
|
|
2709
|
-
// this file's structure. The edges aimed at the interface still count.
|
|
2710
2431
|
disqualify(`
|
|
2711
2432
|
SELECT DISTINCT t.file_path AS file_path
|
|
2712
2433
|
FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
|
|
@@ -2718,25 +2439,18 @@ class QueryBuilder {
|
|
|
2718
2439
|
}
|
|
2719
2440
|
return found;
|
|
2720
2441
|
}
|
|
2721
|
-
/**
|
|
2722
|
-
* A reusable `(path) => boolean` ambient-declaration test over a bounded
|
|
2723
|
-
* candidate list — the shape a ranking comparator wants: one query up front,
|
|
2724
|
-
* O(1) per comparison.
|
|
2725
|
-
*/
|
|
2726
2442
|
ambientDeclarationPredicateFor(filePaths) {
|
|
2727
2443
|
const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
|
|
2728
2444
|
return (filePath) => flagged.has(filePath);
|
|
2729
2445
|
}
|
|
2730
|
-
/** How many indexed files carry the generated flag. Surfaced by `status`. */
|
|
2731
2446
|
countGeneratedFiles() {
|
|
2447
|
+
if (!this.hasSchema('files', 'generated'))
|
|
2448
|
+
return 0;
|
|
2732
2449
|
const row = this.db
|
|
2733
2450
|
.prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
|
|
2734
2451
|
.get();
|
|
2735
2452
|
return row?.n ?? 0;
|
|
2736
2453
|
}
|
|
2737
|
-
/**
|
|
2738
|
-
* Delete a file record and its nodes
|
|
2739
|
-
*/
|
|
2740
2454
|
deleteFile(filePath) {
|
|
2741
2455
|
this.db.transaction(() => {
|
|
2742
2456
|
this.deleteNodesByFile(filePath);
|
|
@@ -2746,9 +2460,6 @@ class QueryBuilder {
|
|
|
2746
2460
|
this.stmts.deleteFile.run(filePath);
|
|
2747
2461
|
})();
|
|
2748
2462
|
}
|
|
2749
|
-
/**
|
|
2750
|
-
* Get a file record by path
|
|
2751
|
-
*/
|
|
2752
2463
|
getFileByPath(filePath) {
|
|
2753
2464
|
if (!this.stmts.getFileByPath) {
|
|
2754
2465
|
this.stmts.getFileByPath = this.db.prepare('SELECT * FROM files WHERE path = ?');
|
|
@@ -2756,20 +2467,12 @@ class QueryBuilder {
|
|
|
2756
2467
|
const row = this.stmts.getFileByPath.get(filePath);
|
|
2757
2468
|
return row ? rowToFileRecord(row) : null;
|
|
2758
2469
|
}
|
|
2759
|
-
/**
|
|
2760
|
-
* Whether any tracked file lives under the project-relative POSIX directory
|
|
2761
|
-
* `dir`. A range scan on the `path` primary key — `dir/` up to `dir0` ('0'
|
|
2762
|
-
* is the byte after '/') — so it costs one index probe at any repo size.
|
|
2763
|
-
*/
|
|
2764
2470
|
hasFilesUnder(dir) {
|
|
2765
2471
|
if (!this.stmts.hasFilesUnder) {
|
|
2766
2472
|
this.stmts.hasFilesUnder = this.db.prepare('SELECT 1 FROM files WHERE path >= ? AND path < ? LIMIT 1');
|
|
2767
2473
|
}
|
|
2768
2474
|
return this.stmts.hasFilesUnder.get(`${dir}/`, `${dir}0`) !== undefined;
|
|
2769
2475
|
}
|
|
2770
|
-
/**
|
|
2771
|
-
* Get all tracked files
|
|
2772
|
-
*/
|
|
2773
2476
|
getAllFiles() {
|
|
2774
2477
|
if (!this.stmts.getAllFiles) {
|
|
2775
2478
|
this.stmts.getAllFiles = this.db.prepare('SELECT * FROM files ORDER BY path');
|
|
@@ -2777,41 +2480,24 @@ class QueryBuilder {
|
|
|
2777
2480
|
const rows = this.stmts.getAllFiles.all();
|
|
2778
2481
|
return rows.map(rowToFileRecord);
|
|
2779
2482
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2483
|
+
getFilesWithoutNodesOrWithErrors() {
|
|
2484
|
+
const rows = this.db
|
|
2485
|
+
.prepare('SELECT * FROM files WHERE node_count = 0 OR errors IS NOT NULL ORDER BY path')
|
|
2486
|
+
.all();
|
|
2487
|
+
return rows.map(rowToFileRecord);
|
|
2488
|
+
}
|
|
2784
2489
|
getLastIndexedAt() {
|
|
2785
2490
|
const row = this.db
|
|
2786
2491
|
.prepare('SELECT MAX(indexed_at) AS last FROM files')
|
|
2787
2492
|
.get();
|
|
2788
2493
|
return row?.last ?? null;
|
|
2789
2494
|
}
|
|
2790
|
-
/**
|
|
2791
|
-
* The index's revision marker: how far the last sync got, and how many files
|
|
2792
|
-
* it left behind — one query, both numbers.
|
|
2793
|
-
*
|
|
2794
|
-
* This is the cheapest honest answer to "has the index moved since I last
|
|
2795
|
-
* looked". `MAX(indexed_at)` alone is not enough: a sync that only DELETES
|
|
2796
|
-
* files (a branch checkout that removed a directory) advances nothing, and
|
|
2797
|
-
* the graph the viewer is showing has still changed underneath it. The row
|
|
2798
|
-
* count catches exactly that case.
|
|
2799
|
-
*/
|
|
2800
2495
|
getIndexRevision() {
|
|
2801
2496
|
const row = this.db
|
|
2802
2497
|
.prepare('SELECT MAX(indexed_at) AS last, COUNT(*) AS files FROM files')
|
|
2803
2498
|
.get();
|
|
2804
2499
|
return { lastIndexedAt: row?.last ?? null, fileCount: row?.files ?? 0 };
|
|
2805
2500
|
}
|
|
2806
|
-
/**
|
|
2807
|
-
* Files re-indexed strictly after `since` (ms since epoch), newest first.
|
|
2808
|
-
*
|
|
2809
|
-
* `total` is the real count; `paths` is capped at `limit`. Used by the
|
|
2810
|
-
* viewer's live channel to name what a sync just picked up. A file the same
|
|
2811
|
-
* sync DELETED cannot appear here — it has no row left — which is why the
|
|
2812
|
-
* caller compares {@link getIndexRevision} as well rather than treating an
|
|
2813
|
-
* empty list as "nothing happened".
|
|
2814
|
-
*/
|
|
2815
2501
|
getFilesIndexedSince(since, limit) {
|
|
2816
2502
|
const count = this.db
|
|
2817
2503
|
.prepare('SELECT COUNT(*) AS n FROM files WHERE indexed_at > ?')
|
|
@@ -2821,9 +2507,6 @@ class QueryBuilder {
|
|
|
2821
2507
|
.all(since, Math.max(0, limit));
|
|
2822
2508
|
return { paths: rows.map((r) => r.path), total: count?.n ?? rows.length };
|
|
2823
2509
|
}
|
|
2824
|
-
/**
|
|
2825
|
-
* Get files that need re-indexing (hash changed)
|
|
2826
|
-
*/
|
|
2827
2510
|
getStaleFiles(currentHashes) {
|
|
2828
2511
|
const files = this.getAllFiles();
|
|
2829
2512
|
return files.filter((f) => {
|
|
@@ -2831,12 +2514,6 @@ class QueryBuilder {
|
|
|
2831
2514
|
return currentHash && currentHash !== f.contentHash;
|
|
2832
2515
|
});
|
|
2833
2516
|
}
|
|
2834
|
-
// ===========================================================================
|
|
2835
|
-
// Unresolved References
|
|
2836
|
-
// ===========================================================================
|
|
2837
|
-
/**
|
|
2838
|
-
* Insert an unresolved reference
|
|
2839
|
-
*/
|
|
2840
2517
|
insertUnresolvedRef(ref) {
|
|
2841
2518
|
if (!this.stmts.insertUnresolved) {
|
|
2842
2519
|
this.stmts.insertUnresolved = this.db.prepare(`
|
|
@@ -2855,9 +2532,6 @@ class QueryBuilder {
|
|
|
2855
2532
|
language: ref.language ?? 'unknown',
|
|
2856
2533
|
});
|
|
2857
2534
|
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Insert multiple unresolved references in a transaction
|
|
2860
|
-
*/
|
|
2861
2535
|
insertUnresolvedRefsBatch(refs) {
|
|
2862
2536
|
if (refs.length === 0)
|
|
2863
2537
|
return;
|
|
@@ -2879,18 +2553,12 @@ class QueryBuilder {
|
|
|
2879
2553
|
});
|
|
2880
2554
|
insert();
|
|
2881
2555
|
}
|
|
2882
|
-
/**
|
|
2883
|
-
* Delete unresolved references from a node
|
|
2884
|
-
*/
|
|
2885
2556
|
deleteUnresolvedByNode(nodeId) {
|
|
2886
2557
|
if (!this.stmts.deleteUnresolvedByNode) {
|
|
2887
2558
|
this.stmts.deleteUnresolvedByNode = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ?');
|
|
2888
2559
|
}
|
|
2889
2560
|
this.stmts.deleteUnresolvedByNode.run(nodeId);
|
|
2890
2561
|
}
|
|
2891
|
-
/**
|
|
2892
|
-
* Get unresolved references by name (for resolution)
|
|
2893
|
-
*/
|
|
2894
2562
|
getUnresolvedByName(name) {
|
|
2895
2563
|
if (!this.stmts.getUnresolvedByName) {
|
|
2896
2564
|
this.stmts.getUnresolvedByName = this.db.prepare('SELECT * FROM unresolved_refs WHERE reference_name = ?');
|
|
@@ -2908,9 +2576,6 @@ class QueryBuilder {
|
|
|
2908
2576
|
rowId: row.id,
|
|
2909
2577
|
}));
|
|
2910
2578
|
}
|
|
2911
|
-
/**
|
|
2912
|
-
* Get all unresolved references
|
|
2913
|
-
*/
|
|
2914
2579
|
getUnresolvedReferences() {
|
|
2915
2580
|
const rows = this.db.prepare('SELECT * FROM unresolved_refs').all();
|
|
2916
2581
|
return rows.map((row) => ({
|
|
@@ -2925,33 +2590,42 @@ class QueryBuilder {
|
|
|
2925
2590
|
rowId: row.id,
|
|
2926
2591
|
}));
|
|
2927
2592
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2593
|
+
getCppIncludeEdges() {
|
|
2594
|
+
return this.db.prepare(`SELECT s.file_path AS source, t.file_path AS target FROM edges e
|
|
2595
|
+
JOIN nodes s ON s.id = e.source JOIN nodes t ON t.id = e.target
|
|
2596
|
+
WHERE e.kind = 'imports' AND s.kind = 'file' AND t.kind = 'file' AND s.language IN ('c', 'cpp')`).all();
|
|
2597
|
+
}
|
|
2598
|
+
*iterateFailedCppTypeReferences(files) {
|
|
2599
|
+
const rows = this.db.prepare(`SELECT from_node_id, reference_name, reference_kind, line, col, file_path FROM unresolved_refs
|
|
2600
|
+
WHERE +status = 'failed' AND language = 'cpp' AND file_path IN (SELECT value FROM json_each(?))
|
|
2601
|
+
AND (reference_kind = 'instantiates'
|
|
2602
|
+
OR (reference_kind IN ('calls', 'function_ref') AND reference_name GLOB '*::*' AND reference_name NOT GLOB 'std::*')
|
|
2603
|
+
OR (reference_kind = 'calls' AND reference_name GLOB '*.*' AND reference_name NOT GLOB '*(*'))`).iterate(JSON.stringify(files));
|
|
2604
|
+
for (const row of rows) {
|
|
2605
|
+
yield {
|
|
2606
|
+
fromNodeId: row.from_node_id,
|
|
2607
|
+
referenceName: row.reference_name,
|
|
2608
|
+
referenceKind: row.reference_kind,
|
|
2609
|
+
line: row.line,
|
|
2610
|
+
column: row.col,
|
|
2611
|
+
filePath: row.file_path,
|
|
2612
|
+
language: 'cpp',
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
this.db.exec('PRAGMA shrink_memory');
|
|
2616
|
+
}
|
|
2935
2617
|
getUnresolvedReferencesCount() {
|
|
2936
2618
|
if (!this.stmts.getUnresolvedCount) {
|
|
2619
|
+
if (!this.hasSchema('unresolved_refs', 'status')) {
|
|
2620
|
+
return this.db.prepare('SELECT COUNT(*) as count FROM unresolved_refs').get().count;
|
|
2621
|
+
}
|
|
2937
2622
|
this.stmts.getUnresolvedCount = this.db.prepare("SELECT COUNT(*) as count FROM unresolved_refs WHERE status = 'pending'");
|
|
2938
2623
|
}
|
|
2939
2624
|
const row = this.stmts.getUnresolvedCount.get();
|
|
2940
2625
|
return row.count;
|
|
2941
2626
|
}
|
|
2942
|
-
/**
|
|
2943
|
-
* Get a batch of PENDING unresolved references using LIMIT/OFFSET
|
|
2944
|
-
* pagination. Used to process references in bounded memory chunks; failed
|
|
2945
|
-
* rows are excluded so the batched drain loop terminates once every row
|
|
2946
|
-
* has been attempted.
|
|
2947
|
-
*/
|
|
2948
2627
|
getUnresolvedReferencesBatch(offset, limit) {
|
|
2949
2628
|
if (!this.stmts.getUnresolvedBatch) {
|
|
2950
|
-
// ORDER BY rowid is load-bearing for the pipelined resolution loop: it
|
|
2951
|
-
// prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
|
|
2952
|
-
// still pending, which is only exact under a stable enumeration. (A plain
|
|
2953
|
-
// scan and the status index both return rowid order anyway — this pins
|
|
2954
|
-
// it.)
|
|
2955
2629
|
this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
|
|
2956
2630
|
}
|
|
2957
2631
|
const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
|
|
@@ -2967,19 +2641,7 @@ class QueryBuilder {
|
|
|
2967
2641
|
rowId: row.id,
|
|
2968
2642
|
}));
|
|
2969
2643
|
}
|
|
2970
|
-
/**
|
|
2971
|
-
* Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
|
|
2972
|
-
* resolution loop: seek past the last-seen row id instead of OFFSET-walking.
|
|
2973
|
-
* OFFSET reads re-scan the accumulated failed-row prefix on every batch —
|
|
2974
|
-
* O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
|
|
2975
|
-
* (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
|
|
2976
|
-
* the enumeration order is identical to the OFFSET reader's.
|
|
2977
|
-
*/
|
|
2978
2644
|
getUnresolvedReferencesBatchAfter(afterRowId, limit, prerequisites) {
|
|
2979
|
-
// Resolution prerequisites must be committed before dependent calls,
|
|
2980
|
-
// even when an interrupted sync queued their rows in a different order
|
|
2981
|
-
// from a clean index (#1577). Each phase still seeks by row id in bounded
|
|
2982
|
-
// memory; the default preserves the public reader's original enumeration.
|
|
2983
2645
|
const key = prerequisites === undefined ? 'getUnresolvedBatchAfter'
|
|
2984
2646
|
: prerequisites ? 'getUnresolvedPrerequisitesAfter' : 'getUnresolvedDependentsAfter';
|
|
2985
2647
|
if (!this.stmts[key]) {
|
|
@@ -3000,9 +2662,6 @@ class QueryBuilder {
|
|
|
3000
2662
|
rowId: row.id,
|
|
3001
2663
|
}));
|
|
3002
2664
|
}
|
|
3003
|
-
/**
|
|
3004
|
-
* Get all tracked file paths (lightweight — no full FileRecord objects)
|
|
3005
|
-
*/
|
|
3006
2665
|
getAllFilePaths() {
|
|
3007
2666
|
if (!this.stmts.getAllFilePaths) {
|
|
3008
2667
|
this.stmts.getAllFilePaths = this.db.prepare('SELECT path FROM files ORDER BY path');
|
|
@@ -3010,9 +2669,6 @@ class QueryBuilder {
|
|
|
3010
2669
|
const rows = this.stmts.getAllFilePaths.all();
|
|
3011
2670
|
return rows.map((r) => r.path);
|
|
3012
2671
|
}
|
|
3013
|
-
/**
|
|
3014
|
-
* Get all distinct node names (lightweight — just name strings for pre-filtering)
|
|
3015
|
-
*/
|
|
3016
2672
|
getAllNodeNames() {
|
|
3017
2673
|
if (!this.stmts.getAllNodeNames) {
|
|
3018
2674
|
this.stmts.getAllNodeNames = this.db.prepare('SELECT DISTINCT name FROM nodes');
|
|
@@ -3020,29 +2676,70 @@ class QueryBuilder {
|
|
|
3020
2676
|
const rows = this.stmts.getAllNodeNames.all();
|
|
3021
2677
|
return rows.map((r) => r.name);
|
|
3022
2678
|
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
2679
|
+
fuzzyNames() {
|
|
2680
|
+
const read = () => {
|
|
2681
|
+
const names = this.getAllNodeNames();
|
|
2682
|
+
const lowered = names.map((name) => name.toLowerCase());
|
|
2683
|
+
const starts = new Int32Array(names.length + 1);
|
|
2684
|
+
for (let i = 0; i < lowered.length; i++)
|
|
2685
|
+
starts[i + 1] = starts[i] + lowered[i].length + 1;
|
|
2686
|
+
return { names, lowered: lowered.join('\n') + '\n', starts };
|
|
2687
|
+
};
|
|
2688
|
+
return this.memoizedRead('fuzzyNames', read) ?? read();
|
|
2689
|
+
}
|
|
2690
|
+
loweredNodePaths() {
|
|
2691
|
+
const read = () => {
|
|
2692
|
+
const rows = this.db.prepare('SELECT DISTINCT file_path FROM nodes').all();
|
|
2693
|
+
return rows.map((row) => row.file_path.toLowerCase()).join('\n') + '\n';
|
|
2694
|
+
};
|
|
2695
|
+
return this.memoizedRead('loweredNodePaths', read) ?? read();
|
|
2696
|
+
}
|
|
2697
|
+
fieldFiltersCanMatch(filters) {
|
|
2698
|
+
if (filters.names.length > 0) {
|
|
2699
|
+
const names = this.fuzzyNames().lowered;
|
|
2700
|
+
if (!filters.names.some((n) => names.includes(n)))
|
|
2701
|
+
return false;
|
|
2702
|
+
}
|
|
2703
|
+
if (filters.paths.length > 0) {
|
|
2704
|
+
const paths = this.loweredNodePaths();
|
|
2705
|
+
if (!filters.paths.some((p) => paths.includes(p)))
|
|
2706
|
+
return false;
|
|
2707
|
+
}
|
|
2708
|
+
return true;
|
|
2709
|
+
}
|
|
2710
|
+
readQualifiedNameRuns() {
|
|
2711
|
+
const runs = new Set();
|
|
2712
|
+
const rows = this.db.prepare('SELECT DISTINCT qualified_name AS name FROM nodes').all();
|
|
2713
|
+
for (const row of rows) {
|
|
2714
|
+
for (const run of row.name.toLowerCase().split(/[^a-z0-9]+/)) {
|
|
2715
|
+
if (run)
|
|
2716
|
+
runs.add(run);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
return [...runs].join('\n');
|
|
2720
|
+
}
|
|
2721
|
+
getNodeNamesOfKinds(language, kinds) {
|
|
2722
|
+
const rows = this.db
|
|
2723
|
+
.prepare(`SELECT name FROM nodes WHERE kind IN (${kinds.map(() => '?').join(', ')}) AND +language = ?`)
|
|
2724
|
+
.all(...kinds, language);
|
|
2725
|
+
return rows.map((r) => r.name);
|
|
2726
|
+
}
|
|
2727
|
+
getCppIncludeNodes() {
|
|
2728
|
+
if (!this.stmts.getCppIncludeNodes) {
|
|
2729
|
+
this.stmts.getCppIncludeNodes = this.db.prepare(`SELECT id, name, file_path AS filePath, language, start_line AS startLine, start_column AS startColumn
|
|
2730
|
+
FROM nodes WHERE kind = 'import' AND language IN ('c', 'cpp')`);
|
|
2731
|
+
}
|
|
2732
|
+
return this.stmts.getCppIncludeNodes.all();
|
|
2733
|
+
}
|
|
3029
2734
|
*iterateNodeNames() {
|
|
3030
2735
|
const stmt = this.db.prepare('SELECT DISTINCT name FROM nodes');
|
|
3031
2736
|
for (const row of stmt.iterate()) {
|
|
3032
2737
|
yield row.name;
|
|
3033
2738
|
}
|
|
3034
2739
|
}
|
|
3035
|
-
/**
|
|
3036
|
-
* Get unresolved references scoped to specific file paths.
|
|
3037
|
-
* Uses the idx_unresolved_file_path index for efficient lookup.
|
|
3038
|
-
*/
|
|
3039
2740
|
getUnresolvedReferencesByFiles(filePaths) {
|
|
3040
2741
|
if (filePaths.length === 0)
|
|
3041
2742
|
return [];
|
|
3042
|
-
// Chunk under SQLite's parameter limit: the first sync of a very large repo
|
|
3043
|
-
// passes every changed file here, which an unbounded `IN (...)` would bind
|
|
3044
|
-
// as one parameter each — exceeding MAX_VARIABLE_NUMBER and aborting with
|
|
3045
|
-
// "too many SQL variables". (#540)
|
|
3046
2743
|
const rows = [];
|
|
3047
2744
|
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3048
2745
|
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
@@ -3050,11 +2747,6 @@ class QueryBuilder {
|
|
|
3050
2747
|
const chunkRows = this.db
|
|
3051
2748
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
|
|
3052
2749
|
.all(...chunk);
|
|
3053
|
-
// Append with a loop, never a spread: the INPUT chunk is bounded, but
|
|
3054
|
-
// the RESULT rows per chunk are not — a dense recovery sync (e.g. the
|
|
3055
|
-
// #1541 self-heal re-indexing hundreds of files) returns more rows than
|
|
3056
|
-
// V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum
|
|
3057
|
-
// call stack size exceeded", aborting resolution mid-sync (#1558).
|
|
3058
2750
|
for (const row of chunkRows)
|
|
3059
2751
|
rows.push(row);
|
|
3060
2752
|
}
|
|
@@ -3070,40 +2762,22 @@ class QueryBuilder {
|
|
|
3070
2762
|
rowId: row.id,
|
|
3071
2763
|
}));
|
|
3072
2764
|
}
|
|
3073
|
-
/**
|
|
3074
|
-
* Delete all unresolved references (after resolution)
|
|
3075
|
-
*/
|
|
3076
2765
|
clearUnresolvedReferences() {
|
|
3077
2766
|
this.db.exec('DELETE FROM unresolved_refs');
|
|
3078
2767
|
}
|
|
3079
|
-
/**
|
|
3080
|
-
* Delete resolved references by their IDs
|
|
3081
|
-
*/
|
|
3082
2768
|
deleteResolvedReferences(fromNodeIds) {
|
|
3083
2769
|
if (fromNodeIds.length === 0)
|
|
3084
2770
|
return;
|
|
3085
|
-
// Chunk under SQLite's parameter limit, matching every other IN-list in
|
|
3086
|
-
// this file. The internal resolution path uses deleteSpecificResolvedReferences
|
|
3087
|
-
// instead, but QueryBuilder is part of the public API, so a library consumer
|
|
3088
|
-
// passing more ids than SQLITE_MAX_VARIABLE_NUMBER (32766 on the bundled
|
|
3089
|
-
// node:sqlite) would otherwise hit "too many SQL variables". (#540, #1001)
|
|
3090
2771
|
for (let i = 0; i < fromNodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3091
2772
|
const chunk = fromNodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3092
2773
|
const placeholders = chunk.map(() => '?').join(',');
|
|
3093
2774
|
this.db.prepare(`DELETE FROM unresolved_refs WHERE from_node_id IN (${placeholders})`).run(...chunk);
|
|
3094
2775
|
}
|
|
3095
2776
|
}
|
|
3096
|
-
/**
|
|
3097
|
-
* Delete specific resolved references by (fromNodeId, referenceName, referenceKind) tuples.
|
|
3098
|
-
* More precise than deleteResolvedReferences — only removes refs that were actually resolved.
|
|
3099
|
-
*/
|
|
3100
2777
|
deleteSpecificResolvedReferences(refs) {
|
|
3101
2778
|
if (refs.length === 0)
|
|
3102
2779
|
return 0;
|
|
3103
2780
|
const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
|
|
3104
|
-
// Returns rows actually removed (SQLite `changes`, summed): the batched
|
|
3105
|
-
// resolution loop's non-progress guard keys on this — zero removals from
|
|
3106
|
-
// a batch that claimed work is the direct runaway signal (§7a.2).
|
|
3107
2781
|
let changed = 0;
|
|
3108
2782
|
const deleteMany = this.db.transaction((items) => {
|
|
3109
2783
|
for (const ref of items) {
|
|
@@ -3113,23 +2787,9 @@ class QueryBuilder {
|
|
|
3113
2787
|
deleteMany(refs);
|
|
3114
2788
|
return changed;
|
|
3115
2789
|
}
|
|
3116
|
-
/**
|
|
3117
|
-
* Delete unresolved-ref rows by row id — the precise cleanup for refs a
|
|
3118
|
-
* resolution pass actually processed. The key-tuple variant above also
|
|
3119
|
-
* deletes SIBLING rows (same caller calling the same callee at other lines)
|
|
3120
|
-
* that a later batch hasn't attempted yet, so when a batch boundary split a
|
|
3121
|
-
* caller's same-named call sites, the later sites' edges were silently never
|
|
3122
|
-
* created (#1269).
|
|
3123
|
-
*/
|
|
3124
2790
|
deleteReferencesByRowIds(rowIds) {
|
|
3125
2791
|
if (rowIds.length === 0)
|
|
3126
2792
|
return 0;
|
|
3127
|
-
// One transaction for all chunks (each chunk was previously its own
|
|
3128
|
-
// implicit transaction = its own WAL commit — measurable on 100k+-ref
|
|
3129
|
-
// resolution persists), and the full-size chunk statement is cached so
|
|
3130
|
-
// repeat calls skip the re-prepare; only the final partial chunk (if any)
|
|
3131
|
-
// prepares ad hoc. Returns rows actually removed (summed `changes`) for
|
|
3132
|
-
// the batched loop's non-progress guard (§7a.2).
|
|
3133
2793
|
let changed = 0;
|
|
3134
2794
|
this.db.transaction(() => {
|
|
3135
2795
|
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
@@ -3149,15 +2809,6 @@ class QueryBuilder {
|
|
|
3149
2809
|
})();
|
|
3150
2810
|
return changed;
|
|
3151
2811
|
}
|
|
3152
|
-
/**
|
|
3153
|
-
* Mark refs a completed resolution pass could not resolve as status='failed'
|
|
3154
|
-
* instead of deleting them (#1240). Failed rows are invisible to the pending
|
|
3155
|
-
* count/batch readers (so drain loops and the #1187 orphan sweep still
|
|
3156
|
-
* terminate) but stay queryable by name_tail so a later sync can retry them
|
|
3157
|
-
* when a changed file introduces a symbol that could satisfy them. name_tail
|
|
3158
|
-
* is (re)written here so rows inserted before the v8 migration get their
|
|
3159
|
-
* tail the first time they're attempted.
|
|
3160
|
-
*/
|
|
3161
2812
|
markReferencesFailed(refs) {
|
|
3162
2813
|
if (refs.length === 0)
|
|
3163
2814
|
return 0;
|
|
@@ -3165,20 +2816,12 @@ class QueryBuilder {
|
|
|
3165
2816
|
let changed = 0;
|
|
3166
2817
|
const markMany = this.db.transaction((items) => {
|
|
3167
2818
|
for (const ref of items) {
|
|
3168
|
-
changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
2819
|
+
changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
3169
2820
|
}
|
|
3170
2821
|
});
|
|
3171
2822
|
markMany(refs);
|
|
3172
2823
|
return changed;
|
|
3173
2824
|
}
|
|
3174
|
-
/**
|
|
3175
|
-
* Park refs as status='failed' by row id — the precise counterpart of
|
|
3176
|
-
* markReferencesFailed, for the same reason as deleteReferencesByRowIds:
|
|
3177
|
-
* the key-tuple variant also flips same-key sibling rows in later batches
|
|
3178
|
-
* to 'failed' before they were ever attempted (#1269). Resolution outcome
|
|
3179
|
-
* can differ per call site (receiver-type inference reads the ref's line),
|
|
3180
|
-
* so a sibling must not inherit this row's failure.
|
|
3181
|
-
*/
|
|
3182
2825
|
markReferencesFailedByRowIds(refs) {
|
|
3183
2826
|
if (refs.length === 0)
|
|
3184
2827
|
return 0;
|
|
@@ -3186,54 +2829,61 @@ class QueryBuilder {
|
|
|
3186
2829
|
let changed = 0;
|
|
3187
2830
|
const markMany = this.db.transaction((items) => {
|
|
3188
2831
|
for (const ref of items) {
|
|
3189
|
-
changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
|
|
2832
|
+
changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.rowId).changes;
|
|
3190
2833
|
}
|
|
3191
2834
|
});
|
|
3192
2835
|
markMany(refs);
|
|
3193
2836
|
return changed;
|
|
3194
2837
|
}
|
|
3195
|
-
|
|
3196
|
-
* Failed refs whose name tail matches one of the given symbol names — the
|
|
3197
|
-
* candidates a sync should retry after files carrying those names changed
|
|
3198
|
-
* (#1240). Names matching more than `perNameCeiling` failed refs are
|
|
3199
|
-
* skipped entirely: at that population a name is external/builtin noise
|
|
3200
|
-
* (`get`, `map`, …) that one new definition won't resolve — the same
|
|
3201
|
-
* rationale as resolution's AMBIGUOUS_NAME_CEILING (#999) — and retrying an
|
|
3202
|
-
* arbitrary subset would be both wasted work and incoherent coverage.
|
|
3203
|
-
*/
|
|
3204
|
-
getRetryableFailedReferences(names, perNameCeiling = 500) {
|
|
2838
|
+
getRetryableFailedReferences(names, perNameCeiling = 500, perModuleCeiling = 5000) {
|
|
3205
2839
|
if (names.length === 0)
|
|
3206
2840
|
return [];
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
2841
|
+
const lookups = [
|
|
2842
|
+
{ column: 'name_tail', where: "status = 'failed'" },
|
|
2843
|
+
{ column: 'reference_name', where: reference_tail_1.MODULE_PARKED_SQL },
|
|
2844
|
+
{ column: reference_tail_1.MEMBER_TAIL_SQL, where: `${reference_tail_1.MODULE_PARKED_SQL} AND instr(reference_name, '.') > 0` },
|
|
2845
|
+
];
|
|
2846
|
+
const counts = lookups.map(({ column, where }) => {
|
|
2847
|
+
const byKey = new Map();
|
|
2848
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2849
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2850
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2851
|
+
const found = this.db
|
|
2852
|
+
.prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
|
|
2853
|
+
.all(...chunk);
|
|
2854
|
+
for (const row of found)
|
|
2855
|
+
byKey.set(row.key, row.count);
|
|
2856
|
+
}
|
|
2857
|
+
return byKey;
|
|
2858
|
+
});
|
|
2859
|
+
const [byTail, , byMember] = counts;
|
|
2860
|
+
const population = (lookup, key, count) => lookup === 1 ? count : (byTail.get(key) ?? 0) + (byMember.get(key) ?? 0);
|
|
2861
|
+
const rows = new Map();
|
|
2862
|
+
for (const [lookup, { column, where }] of lookups.entries()) {
|
|
2863
|
+
const retryKeys = [...counts[lookup]]
|
|
2864
|
+
.filter(([key, count]) => (lookup === 0 && (0, reference_tail_1.isModuleKey)(key) ? count <= perModuleCeiling : population(lookup, key, count) <= perNameCeiling))
|
|
2865
|
+
.map(([key]) => key);
|
|
2866
|
+
for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2867
|
+
const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2868
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2869
|
+
const chunkRows = this.db
|
|
2870
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
|
|
2871
|
+
.all(...chunk);
|
|
2872
|
+
for (const row of chunkRows)
|
|
2873
|
+
rows.set(row.id, row);
|
|
3218
2874
|
}
|
|
3219
2875
|
}
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
const
|
|
3228
|
-
.
|
|
3229
|
-
.all(...chunk);
|
|
3230
|
-
// Loop, not spread — same V8 argument-limit hazard as
|
|
3231
|
-
// getUnresolvedReferencesByFiles (#1558): a large definition delta can
|
|
3232
|
-
// select an unbounded number of failed rows per chunk.
|
|
3233
|
-
for (const row of chunkRows)
|
|
3234
|
-
rows.push(row);
|
|
2876
|
+
const byReceiver = this.db.prepare(`SELECT * FROM unresolved_refs WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_name >= ? AND reference_name < ? LIMIT ?`);
|
|
2877
|
+
for (const name of names) {
|
|
2878
|
+
if (!RECEIVER_NAME.test(name))
|
|
2879
|
+
continue;
|
|
2880
|
+
const found = byReceiver.all(`${name}.`, `${name}/`, perNameCeiling + 1);
|
|
2881
|
+
if (found.length > perNameCeiling)
|
|
2882
|
+
continue;
|
|
2883
|
+
for (const row of found)
|
|
2884
|
+
rows.set(row.id, row);
|
|
3235
2885
|
}
|
|
3236
|
-
return rows.map((row) => ({
|
|
2886
|
+
return [...rows.values()].map((row) => ({
|
|
3237
2887
|
fromNodeId: row.from_node_id,
|
|
3238
2888
|
referenceName: row.reference_name,
|
|
3239
2889
|
referenceKind: row.reference_kind,
|
|
@@ -3245,35 +2895,153 @@ class QueryBuilder {
|
|
|
3245
2895
|
rowId: row.id,
|
|
3246
2896
|
}));
|
|
3247
2897
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
2898
|
+
getRetryableFailedImports(pathKeys, names = [], perNameCeiling = 500, resolvedModules = [], perModuleCeiling = 5000, couldName) {
|
|
2899
|
+
const failedImports = "status = 'failed' AND reference_kind = 'imports'";
|
|
2900
|
+
const lookups = [
|
|
2901
|
+
{ keys: pathKeys, column: 'name_tail', where: failedImports, ceiling: perNameCeiling, couldName },
|
|
2902
|
+
{ keys: pathKeys, column: 'reference_name', where: failedImports, ceiling: perNameCeiling, couldName },
|
|
2903
|
+
{ keys: names, column: 'reference_name', where: `${failedImports} AND name_tail != reference_name`, ceiling: perNameCeiling },
|
|
2904
|
+
{ keys: resolvedModules, column: 'reference_name', where: failedImports, ceiling: perModuleCeiling },
|
|
2905
|
+
];
|
|
2906
|
+
const toReference = (row) => ({
|
|
2907
|
+
fromNodeId: row.from_node_id,
|
|
2908
|
+
referenceName: row.reference_name,
|
|
2909
|
+
referenceKind: row.reference_kind,
|
|
2910
|
+
line: row.line,
|
|
2911
|
+
column: row.col,
|
|
2912
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2913
|
+
filePath: row.file_path,
|
|
2914
|
+
language: row.language,
|
|
2915
|
+
rowId: row.id,
|
|
2916
|
+
});
|
|
2917
|
+
const rows = new Map();
|
|
2918
|
+
for (const { keys, column, where, ceiling, couldName } of lookups) {
|
|
2919
|
+
const unique = [...new Set(keys)].filter((key) => key.length > 0);
|
|
2920
|
+
const retryKeys = [];
|
|
2921
|
+
const crowdedKeys = [];
|
|
2922
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2923
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2924
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2925
|
+
const counts = this.db
|
|
2926
|
+
.prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
|
|
2927
|
+
.all(...chunk);
|
|
2928
|
+
for (const row of counts) {
|
|
2929
|
+
if (row.count <= ceiling)
|
|
2930
|
+
retryKeys.push(row.key);
|
|
2931
|
+
else if (couldName)
|
|
2932
|
+
crowdedKeys.push(row.key);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2936
|
+
const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2937
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2938
|
+
const chunkRows = this.db
|
|
2939
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
|
|
2940
|
+
.all(...chunk);
|
|
2941
|
+
for (const row of chunkRows)
|
|
2942
|
+
rows.set(row.id, row);
|
|
2943
|
+
}
|
|
2944
|
+
for (const key of crowdedKeys) {
|
|
2945
|
+
const keyRows = this.db
|
|
2946
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (?)`)
|
|
2947
|
+
.all(key);
|
|
2948
|
+
const named = keyRows.filter((row) => couldName(toReference(row)));
|
|
2949
|
+
if (named.length > perModuleCeiling)
|
|
2950
|
+
continue;
|
|
2951
|
+
for (const row of named)
|
|
2952
|
+
rows.set(row.id, row);
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
return [...rows.values()].map(toReference);
|
|
2956
|
+
}
|
|
2957
|
+
getFailedScopedImports() {
|
|
2958
|
+
return this.db
|
|
2959
|
+
.prepare(`SELECT reference_name AS name, MIN(file_path) AS file_path, language
|
|
2960
|
+
FROM unresolved_refs
|
|
2961
|
+
WHERE status = 'failed' AND reference_kind = 'imports'
|
|
2962
|
+
AND reference_name GLOB '@?*/?*' AND reference_name NOT GLOB '@*/*/*'
|
|
2963
|
+
GROUP BY reference_name`)
|
|
2964
|
+
.all()
|
|
2965
|
+
.map((row) => ({ name: row.name, filePath: row.file_path, language: row.language }));
|
|
2966
|
+
}
|
|
2967
|
+
getFailedFolderImports() {
|
|
2968
|
+
const placeholders = FOLDER_SPECIFIERS.map(() => '?').join(',');
|
|
2969
|
+
return this.db
|
|
2970
|
+
.prepare(`SELECT * FROM unresolved_refs
|
|
2971
|
+
WHERE status = 'failed' AND reference_kind = 'imports' AND reference_name IN (${placeholders})`)
|
|
2972
|
+
.all(...FOLDER_SPECIFIERS)
|
|
2973
|
+
.map((row) => ({
|
|
2974
|
+
fromNodeId: row.from_node_id,
|
|
2975
|
+
referenceName: row.reference_name,
|
|
2976
|
+
referenceKind: row.reference_kind,
|
|
2977
|
+
line: row.line,
|
|
2978
|
+
column: row.col,
|
|
2979
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2980
|
+
filePath: row.file_path,
|
|
2981
|
+
language: row.language,
|
|
2982
|
+
rowId: row.id,
|
|
2983
|
+
}));
|
|
2984
|
+
}
|
|
2985
|
+
getFailedCallsByTail(tails) {
|
|
2986
|
+
const out = [];
|
|
2987
|
+
const unique = [...new Set(tails)];
|
|
2988
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2989
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2990
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2991
|
+
const rows = this.db
|
|
2992
|
+
.prepare(`SELECT id, reference_name, file_path FROM unresolved_refs
|
|
2993
|
+
WHERE status = 'failed' AND reference_kind = 'calls' AND name_tail IN (${placeholders})
|
|
2994
|
+
UNION ALL
|
|
2995
|
+
SELECT id, reference_name, file_path FROM unresolved_refs
|
|
2996
|
+
WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_kind = 'calls' AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
|
|
2997
|
+
.all(...chunk, ...chunk);
|
|
2998
|
+
for (const row of rows)
|
|
2999
|
+
out.push({ rowId: row.id, referenceName: row.reference_name, filePath: row.file_path });
|
|
3000
|
+
}
|
|
3001
|
+
return out;
|
|
3002
|
+
}
|
|
3003
|
+
getResolvedNavigations() {
|
|
3004
|
+
const rows = this.db
|
|
3005
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3006
|
+
FROM edges e
|
|
3007
|
+
JOIN nodes src ON src.id = e.source
|
|
3008
|
+
WHERE e.kind = 'navigates' AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3009
|
+
.all();
|
|
3010
|
+
return rows.map((row) => ({
|
|
3011
|
+
...rowToEdge(row),
|
|
3012
|
+
edgeId: row.id,
|
|
3013
|
+
sourceFilePath: row.source_file_path,
|
|
3014
|
+
sourceLanguage: row.source_language,
|
|
3015
|
+
}));
|
|
3016
|
+
}
|
|
3017
|
+
getFailedModuleKeys() {
|
|
3018
|
+
return this.db
|
|
3019
|
+
.prepare(`SELECT DISTINCT name_tail AS key FROM unresolved_refs WHERE status = 'failed' AND name_tail GLOB 'module:*'`)
|
|
3020
|
+
.all().map((row) => row.key);
|
|
3021
|
+
}
|
|
3022
|
+
reopenFailedReferences(rowIds) {
|
|
3023
|
+
if (rowIds.length === 0)
|
|
3024
|
+
return 0;
|
|
3025
|
+
let changed = 0;
|
|
3026
|
+
this.db.transaction(() => {
|
|
3027
|
+
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3028
|
+
const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3029
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3030
|
+
changed += this.db
|
|
3031
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND id IN (${placeholders})`)
|
|
3032
|
+
.run(...chunk).changes;
|
|
3033
|
+
}
|
|
3034
|
+
})();
|
|
3035
|
+
return changed;
|
|
3036
|
+
}
|
|
3037
|
+
getMaxEdgeId() {
|
|
3038
|
+
return this.db.prepare('SELECT COALESCE(MAX(id), 0) AS id FROM edges').get().id;
|
|
3039
|
+
}
|
|
3040
|
+
getResolutionEdgesByTargetName(names, perNameCeiling = 500, countedUpToEdgeId) {
|
|
3273
3041
|
if (names.length === 0)
|
|
3274
3042
|
return [];
|
|
3275
|
-
// Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
|
|
3276
3043
|
const keep = [];
|
|
3044
|
+
const counted = countedUpToEdgeId === undefined ? '' : 'AND e.id <= ?';
|
|
3277
3045
|
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3278
3046
|
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3279
3047
|
const placeholders = chunk.map(() => '?').join(',');
|
|
@@ -3283,8 +3051,9 @@ class QueryBuilder {
|
|
|
3283
3051
|
JOIN nodes tgt ON tgt.id = e.target
|
|
3284
3052
|
WHERE tgt.name IN (${placeholders})
|
|
3285
3053
|
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
3054
|
+
${counted}
|
|
3286
3055
|
GROUP BY tgt.name`)
|
|
3287
|
-
.all(...chunk);
|
|
3056
|
+
.all(...chunk, ...(countedUpToEdgeId === undefined ? [] : [countedUpToEdgeId]));
|
|
3288
3057
|
for (const row of counts) {
|
|
3289
3058
|
if (row.count <= perNameCeiling)
|
|
3290
3059
|
keep.push(row.name);
|
|
@@ -3292,8 +3061,6 @@ class QueryBuilder {
|
|
|
3292
3061
|
}
|
|
3293
3062
|
if (keep.length === 0)
|
|
3294
3063
|
return [];
|
|
3295
|
-
// Pass 2: load the surviving edges with the source file context a
|
|
3296
|
-
// resurrection needs.
|
|
3297
3064
|
const out = [];
|
|
3298
3065
|
for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3299
3066
|
const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
@@ -3317,7 +3084,166 @@ class QueryBuilder {
|
|
|
3317
3084
|
}
|
|
3318
3085
|
return out;
|
|
3319
3086
|
}
|
|
3320
|
-
|
|
3087
|
+
getRouteEdgesMovedBy(filePaths) {
|
|
3088
|
+
if (filePaths.length === 0)
|
|
3089
|
+
return [];
|
|
3090
|
+
const files = JSON.stringify(filePaths);
|
|
3091
|
+
const rows = this.db
|
|
3092
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3093
|
+
FROM nodes src
|
|
3094
|
+
JOIN edges e ON e.source = src.id
|
|
3095
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3096
|
+
WHERE src.kind = 'route'
|
|
3097
|
+
AND e.kind != 'contains'
|
|
3098
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
3099
|
+
AND src.file_path NOT IN (SELECT value FROM json_each(?))
|
|
3100
|
+
AND (tgt.file_path IN (SELECT value FROM json_each(?))
|
|
3101
|
+
OR (tgt.file_path = src.file_path AND tgt.kind IN ('constant', 'variable')))
|
|
3102
|
+
ORDER BY e.id`)
|
|
3103
|
+
.all(files, files);
|
|
3104
|
+
return rows.map((row) => ({
|
|
3105
|
+
...rowToEdge(row),
|
|
3106
|
+
edgeId: row.id,
|
|
3107
|
+
sourceFilePath: row.source_file_path,
|
|
3108
|
+
sourceLanguage: row.source_language,
|
|
3109
|
+
}));
|
|
3110
|
+
}
|
|
3111
|
+
getResolutionEdgesBySourceLanguage(language) {
|
|
3112
|
+
const rows = this.db
|
|
3113
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3114
|
+
FROM edges e
|
|
3115
|
+
JOIN nodes src ON src.id = e.source
|
|
3116
|
+
WHERE src.language = ?
|
|
3117
|
+
AND e.kind != 'contains'
|
|
3118
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3119
|
+
.all(language);
|
|
3120
|
+
return rows.map((row) => ({
|
|
3121
|
+
...rowToEdge(row),
|
|
3122
|
+
edgeId: row.id,
|
|
3123
|
+
sourceFilePath: row.source_file_path,
|
|
3124
|
+
sourceLanguage: row.source_language,
|
|
3125
|
+
}));
|
|
3126
|
+
}
|
|
3127
|
+
getResolutionEdgesTouchingFiles(language, targetFiles, sourceDirs, importNodeSegments = []) {
|
|
3128
|
+
const candidates = new Set();
|
|
3129
|
+
const idsWhere = (column, nodeIds) => {
|
|
3130
|
+
for (let i = 0; i < nodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3131
|
+
const chunk = nodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3132
|
+
const rows = this.db
|
|
3133
|
+
.prepare(`SELECT id FROM edges WHERE ${column} IN (${chunk.map(() => '?').join(',')})`)
|
|
3134
|
+
.all(...chunk);
|
|
3135
|
+
for (const r of rows)
|
|
3136
|
+
candidates.add(r.id);
|
|
3137
|
+
}
|
|
3138
|
+
};
|
|
3139
|
+
for (let i = 0; i < targetFiles.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3140
|
+
const chunk = targetFiles.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3141
|
+
const nodes = this.db
|
|
3142
|
+
.prepare(`SELECT id FROM nodes WHERE file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3143
|
+
.all(...chunk);
|
|
3144
|
+
idsWhere('target', nodes.map((n) => n.id));
|
|
3145
|
+
}
|
|
3146
|
+
for (const dir of sourceDirs) {
|
|
3147
|
+
const nodes = (dir === ''
|
|
3148
|
+
? this.db.prepare('SELECT id FROM nodes WHERE language = ?').all(language)
|
|
3149
|
+
: this.db
|
|
3150
|
+
.prepare('SELECT id FROM nodes WHERE file_path >= ? AND file_path < ?')
|
|
3151
|
+
.all(`${dir}/`, `${dir}0`));
|
|
3152
|
+
idsWhere('source', nodes.map((n) => n.id));
|
|
3153
|
+
}
|
|
3154
|
+
if (importNodeSegments.length > 0) {
|
|
3155
|
+
const wanted = new Set(importNodeSegments);
|
|
3156
|
+
const nodes = this.db
|
|
3157
|
+
.prepare("SELECT id, name FROM nodes WHERE kind = 'import' AND language = ?")
|
|
3158
|
+
.all(language);
|
|
3159
|
+
idsWhere('target', nodes.filter((n) => n.name.split('.').some((seg) => wanted.has(seg))).map((n) => n.id));
|
|
3160
|
+
}
|
|
3161
|
+
return this.loadResolutionEdges(language, [...candidates]);
|
|
3162
|
+
}
|
|
3163
|
+
getResolutionEdgesFromFiles(language, files) {
|
|
3164
|
+
const ids = [];
|
|
3165
|
+
for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3166
|
+
const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3167
|
+
const rows = this.db
|
|
3168
|
+
.prepare(`SELECT e.id AS id FROM nodes n CROSS JOIN edges e ON e.source = n.id
|
|
3169
|
+
WHERE n.file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3170
|
+
.all(...chunk);
|
|
3171
|
+
for (const r of rows)
|
|
3172
|
+
ids.push(r.id);
|
|
3173
|
+
}
|
|
3174
|
+
return this.loadResolutionEdges(language, ids);
|
|
3175
|
+
}
|
|
3176
|
+
loadResolutionEdges(language, ids) {
|
|
3177
|
+
const out = [];
|
|
3178
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3179
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3180
|
+
const rows = this.db
|
|
3181
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3182
|
+
FROM edges e
|
|
3183
|
+
CROSS JOIN nodes src ON src.id = e.source
|
|
3184
|
+
CROSS JOIN nodes tgt ON tgt.id = e.target
|
|
3185
|
+
WHERE e.id IN (${chunk.map(() => '?').join(',')})
|
|
3186
|
+
AND src.language = ?
|
|
3187
|
+
AND e.kind != 'contains'
|
|
3188
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3189
|
+
.all(...chunk, language);
|
|
3190
|
+
for (const row of rows) {
|
|
3191
|
+
out.push({ ...rowToEdge(row), edgeId: row.id, sourceFilePath: row.source_file_path, sourceLanguage: row.source_language });
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
return out;
|
|
3195
|
+
}
|
|
3196
|
+
requeueFailedReferencesBinding(language, names) {
|
|
3197
|
+
const files = [...names.keys()];
|
|
3198
|
+
const ids = [];
|
|
3199
|
+
for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3200
|
+
const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3201
|
+
const rows = this.db
|
|
3202
|
+
.prepare(`SELECT id, file_path, reference_name FROM unresolved_refs
|
|
3203
|
+
WHERE status = 'failed' AND language = ? AND file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3204
|
+
.all(language, ...chunk);
|
|
3205
|
+
for (const r of rows) {
|
|
3206
|
+
if (names.get(r.file_path)?.has(r.reference_name.split('.')[0]))
|
|
3207
|
+
ids.push(r.id);
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
let changed = 0;
|
|
3211
|
+
this.db.transaction(() => {
|
|
3212
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3213
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3214
|
+
changed += this.db
|
|
3215
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
3216
|
+
.run(...chunk).changes;
|
|
3217
|
+
}
|
|
3218
|
+
})();
|
|
3219
|
+
return changed;
|
|
3220
|
+
}
|
|
3221
|
+
requeueFailedReferencesByLanguage(language, segments, files) {
|
|
3222
|
+
const sql = "UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND language = ?";
|
|
3223
|
+
if (!segments)
|
|
3224
|
+
return this.db.prepare(sql).run(language).changes;
|
|
3225
|
+
if (segments.length === 0)
|
|
3226
|
+
return 0;
|
|
3227
|
+
const wanted = new Set(segments);
|
|
3228
|
+
const ids = this.db
|
|
3229
|
+
.prepare("SELECT id, reference_name, file_path FROM unresolved_refs WHERE status = 'failed' AND language = ?")
|
|
3230
|
+
.all(language)
|
|
3231
|
+
.filter((r) => r.reference_name.split('.').some((seg) => wanted.has(seg)))
|
|
3232
|
+
.map((r) => {
|
|
3233
|
+
files?.add(r.file_path);
|
|
3234
|
+
return r.id;
|
|
3235
|
+
});
|
|
3236
|
+
let changed = 0;
|
|
3237
|
+
this.db.transaction(() => {
|
|
3238
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3239
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3240
|
+
changed += this.db
|
|
3241
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
3242
|
+
.run(...chunk).changes;
|
|
3243
|
+
}
|
|
3244
|
+
})();
|
|
3245
|
+
return changed;
|
|
3246
|
+
}
|
|
3321
3247
|
deleteEdgesByIds(edgeIds) {
|
|
3322
3248
|
if (edgeIds.length === 0)
|
|
3323
3249
|
return 0;
|
|
@@ -3331,10 +3257,96 @@ class QueryBuilder {
|
|
|
3331
3257
|
})();
|
|
3332
3258
|
return changed;
|
|
3333
3259
|
}
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3260
|
+
getEdgesWithTypeFrom() {
|
|
3261
|
+
const rows = this.db
|
|
3262
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3263
|
+
FROM edges e
|
|
3264
|
+
JOIN nodes src ON src.id = e.source
|
|
3265
|
+
WHERE e.metadata LIKE '%"typeFrom"%'`)
|
|
3266
|
+
.all();
|
|
3267
|
+
return rows.map((row) => ({
|
|
3268
|
+
...rowToEdge(row),
|
|
3269
|
+
edgeId: row.id,
|
|
3270
|
+
sourceFilePath: row.source_file_path,
|
|
3271
|
+
sourceLanguage: row.source_language,
|
|
3272
|
+
}));
|
|
3273
|
+
}
|
|
3274
|
+
get parameterFlows() {
|
|
3275
|
+
return (this.flowQueries ??= new parameter_flow_queries_1.ParameterFlowQueries(this.db, this));
|
|
3276
|
+
}
|
|
3277
|
+
getPythonImporterClosure(filePaths, depth = 6) {
|
|
3278
|
+
const closure = new Set(filePaths);
|
|
3279
|
+
let frontier = [...filePaths];
|
|
3280
|
+
for (let hop = 0; hop < depth && frontier.length > 0; hop++) {
|
|
3281
|
+
const next = [];
|
|
3282
|
+
for (let i = 0; i < frontier.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3283
|
+
const chunk = frontier.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3284
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3285
|
+
const rows = this.db
|
|
3286
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
3287
|
+
FROM edges e
|
|
3288
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3289
|
+
JOIN nodes src ON src.id = e.source
|
|
3290
|
+
WHERE e.kind = 'imports' AND tgt.file_path IN (${placeholders}) AND src.language = 'python'`)
|
|
3291
|
+
.all(...chunk);
|
|
3292
|
+
for (const row of rows) {
|
|
3293
|
+
if (!closure.has(row.file_path)) {
|
|
3294
|
+
closure.add(row.file_path);
|
|
3295
|
+
next.push(row.file_path);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
frontier = next;
|
|
3300
|
+
}
|
|
3301
|
+
return [...closure];
|
|
3302
|
+
}
|
|
3303
|
+
getFailedPythonAttrRefKeys(filePaths) {
|
|
3304
|
+
const wanted = new Set(filePaths);
|
|
3305
|
+
const rows = this.db
|
|
3306
|
+
.prepare(`SELECT id, from_node_id, reference_name, file_path FROM unresolved_refs WHERE ${FAILED_PY_ATTR_REF}`)
|
|
3307
|
+
.all();
|
|
3308
|
+
const out = [];
|
|
3309
|
+
for (const r of rows) {
|
|
3310
|
+
if (wanted.has(r.file_path))
|
|
3311
|
+
out.push({ id: r.id, fromNodeId: r.from_node_id, referenceName: r.reference_name, filePath: r.file_path });
|
|
3312
|
+
}
|
|
3313
|
+
return out;
|
|
3314
|
+
}
|
|
3315
|
+
getUnresolvedReferencesByIds(ids) {
|
|
3316
|
+
const rows = [];
|
|
3317
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3318
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3319
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3320
|
+
const chunkRows = this.db
|
|
3321
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE id IN (${placeholders})`)
|
|
3322
|
+
.all(...chunk);
|
|
3323
|
+
for (const row of chunkRows)
|
|
3324
|
+
rows.push(row);
|
|
3325
|
+
}
|
|
3326
|
+
return rows.map((row) => ({
|
|
3327
|
+
fromNodeId: row.from_node_id,
|
|
3328
|
+
referenceName: row.reference_name,
|
|
3329
|
+
referenceKind: row.reference_kind,
|
|
3330
|
+
line: row.line,
|
|
3331
|
+
column: row.col,
|
|
3332
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
3333
|
+
filePath: row.file_path,
|
|
3334
|
+
language: row.language,
|
|
3335
|
+
rowId: row.id,
|
|
3336
|
+
}));
|
|
3337
|
+
}
|
|
3338
|
+
getPythonFilesWithEdgesInto(filePath, kinds, targetKinds) {
|
|
3339
|
+
const kp = kinds.map(() => '?').join(',');
|
|
3340
|
+
const tp = targetKinds.map(() => '?').join(',');
|
|
3341
|
+
return this.db
|
|
3342
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
3343
|
+
FROM edges e
|
|
3344
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3345
|
+
JOIN nodes src ON src.id = e.source
|
|
3346
|
+
WHERE tgt.file_path = ? AND e.kind IN (${kp}) AND tgt.kind IN (${tp})
|
|
3347
|
+
AND src.language = 'python' AND src.file_path != ?`)
|
|
3348
|
+
.all(filePath, ...kinds, ...targetKinds, filePath).map((r) => r.file_path);
|
|
3349
|
+
}
|
|
3338
3350
|
replaceResolutionEdgesWithUnresolvedRefs(edgeIds, refs) {
|
|
3339
3351
|
return this.db.transaction(() => {
|
|
3340
3352
|
const changed = this.deleteEdgesByIds(edgeIds);
|
|
@@ -3342,37 +3354,22 @@ class QueryBuilder {
|
|
|
3342
3354
|
return changed;
|
|
3343
3355
|
})();
|
|
3344
3356
|
}
|
|
3345
|
-
|
|
3346
|
-
* Distinct node names present in the given files — the symbol names a sync
|
|
3347
|
-
* pass uses to look up retryable failed refs after those files changed.
|
|
3348
|
-
*/
|
|
3349
|
-
getNodeNamesByFiles(filePaths) {
|
|
3357
|
+
getNodeNamesByFiles(filePaths, kinds) {
|
|
3350
3358
|
if (filePaths.length === 0)
|
|
3351
3359
|
return [];
|
|
3360
|
+
const kindFilter = kinds ? ` AND kind IN (${kinds.map(() => '?').join(',')})` : '';
|
|
3352
3361
|
const names = new Set();
|
|
3353
3362
|
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3354
3363
|
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3355
3364
|
const placeholders = chunk.map(() => '?').join(',');
|
|
3356
3365
|
const rows = this.db
|
|
3357
|
-
.prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})`)
|
|
3358
|
-
.all(...chunk);
|
|
3366
|
+
.prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})${kindFilter}`)
|
|
3367
|
+
.all(...chunk, ...(kinds ?? []));
|
|
3359
3368
|
for (const row of rows)
|
|
3360
3369
|
names.add(row.name);
|
|
3361
3370
|
}
|
|
3362
3371
|
return [...names];
|
|
3363
3372
|
}
|
|
3364
|
-
/**
|
|
3365
|
-
* Distinct `file\0name` pairs defined by the given files — the shape sync's
|
|
3366
|
-
* definition delta needs (CG-33).
|
|
3367
|
-
*
|
|
3368
|
-
* Deliberately NOT `getNodeNamesByFiles`: a bare name set is taken over the
|
|
3369
|
-
* WHOLE changed batch, so a name that moves between two files in one commit
|
|
3370
|
-
* (or exists in one changed file and is newly added to another) appears on
|
|
3371
|
-
* both sides and cancels out of the symmetric difference — even though a
|
|
3372
|
-
* definition genuinely appeared or vanished and every reference to that name
|
|
3373
|
-
* repo-wide may now bind elsewhere. Keying by file makes each definition its
|
|
3374
|
-
* own fact, so the move is seen as one removal plus one addition.
|
|
3375
|
-
*/
|
|
3376
3373
|
getNodeNamePairsByFiles(filePaths) {
|
|
3377
3374
|
const pairs = new Set();
|
|
3378
3375
|
if (filePaths.length === 0)
|
|
@@ -3381,34 +3378,53 @@ class QueryBuilder {
|
|
|
3381
3378
|
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3382
3379
|
const placeholders = chunk.map(() => '?').join(',');
|
|
3383
3380
|
const rows = this.db
|
|
3384
|
-
.prepare(`SELECT
|
|
3381
|
+
.prepare(`SELECT file_path, name, SUM(language = 'python' AND kind IN ('function', 'method')) AS python_defs
|
|
3382
|
+
FROM nodes WHERE file_path IN (${placeholders}) GROUP BY file_path, name`)
|
|
3383
|
+
.all(...chunk);
|
|
3384
|
+
for (const row of rows) {
|
|
3385
|
+
const file = row.python_defs > 1 ? `${row.file_path}\u0001${row.python_defs}` : row.file_path;
|
|
3386
|
+
pairs.add(`${file}\0${row.name}`);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
return pairs;
|
|
3390
|
+
}
|
|
3391
|
+
getReExportStatementsByFiles(filePaths) {
|
|
3392
|
+
const pairs = new Set();
|
|
3393
|
+
if (filePaths.length === 0)
|
|
3394
|
+
return pairs;
|
|
3395
|
+
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3396
|
+
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3397
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3398
|
+
const rows = this.db
|
|
3399
|
+
.prepare(`SELECT DISTINCT file_path, signature FROM nodes
|
|
3400
|
+
WHERE kind = 'import' AND file_path IN (${placeholders}) AND signature LIKE 'export%'`)
|
|
3385
3401
|
.all(...chunk);
|
|
3386
|
-
// NUL-joined: a path or a symbol name can contain a space, never a NUL.
|
|
3387
3402
|
for (const row of rows)
|
|
3388
|
-
pairs.add(`${row.file_path}\0${row.
|
|
3403
|
+
pairs.add(`${row.file_path}\0${row.signature}`);
|
|
3389
3404
|
}
|
|
3390
3405
|
return pairs;
|
|
3391
3406
|
}
|
|
3392
|
-
// ===========================================================================
|
|
3393
|
-
// Statistics
|
|
3394
|
-
// ===========================================================================
|
|
3395
|
-
/**
|
|
3396
|
-
* Lightweight (nodes, edges) count snapshot. Used around an index/sync
|
|
3397
|
-
* run to compute true additions across extraction + resolution +
|
|
3398
|
-
* synthesis — the per-phase counter in the orchestrator only sees
|
|
3399
|
-
* extraction's contribution, which is why the CLI summary under-reported
|
|
3400
|
-
* the edge count (resolution + synthesizer edges were invisible).
|
|
3401
|
-
*/
|
|
3402
3407
|
getNodeAndEdgeCount() {
|
|
3403
3408
|
return this.db
|
|
3404
3409
|
.prepare('SELECT (SELECT COUNT(*) FROM nodes) AS nodes, (SELECT COUNT(*) FROM edges) AS edges')
|
|
3405
3410
|
.get();
|
|
3406
3411
|
}
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3412
|
+
getParsedFileCounts() {
|
|
3413
|
+
return this.db
|
|
3414
|
+
.prepare(`
|
|
3415
|
+
SELECT f.language AS language, COUNT(*) AS files,
|
|
3416
|
+
SUM(CASE
|
|
3417
|
+
WHEN f.node_count > 1 THEN 1
|
|
3418
|
+
WHEN EXISTS (SELECT 1 FROM nodes n WHERE n.file_path = f.path AND n.kind <> 'file') THEN 1
|
|
3419
|
+
ELSE 0
|
|
3420
|
+
END) AS parsed
|
|
3421
|
+
FROM files f
|
|
3422
|
+
GROUP BY f.language
|
|
3423
|
+
ORDER BY f.language
|
|
3424
|
+
`)
|
|
3425
|
+
.all();
|
|
3426
|
+
}
|
|
3410
3427
|
getStats() {
|
|
3411
|
-
// Single query for all three aggregate counts
|
|
3412
3428
|
const counts = this.db.prepare(`
|
|
3413
3429
|
SELECT
|
|
3414
3430
|
(SELECT COUNT(*) FROM nodes) AS node_count,
|
|
@@ -3443,30 +3459,18 @@ class QueryBuilder {
|
|
|
3443
3459
|
nodesByKind,
|
|
3444
3460
|
edgesByKind,
|
|
3445
3461
|
filesByLanguage,
|
|
3446
|
-
dbSizeBytes: 0,
|
|
3447
|
-
walSizeBytes: 0,
|
|
3462
|
+
dbSizeBytes: 0,
|
|
3463
|
+
walSizeBytes: 0,
|
|
3448
3464
|
lastUpdated: Date.now(),
|
|
3449
3465
|
};
|
|
3450
3466
|
}
|
|
3451
|
-
// ===========================================================================
|
|
3452
|
-
// Project Metadata
|
|
3453
|
-
// ===========================================================================
|
|
3454
|
-
/**
|
|
3455
|
-
* Get a metadata value by key
|
|
3456
|
-
*/
|
|
3457
3467
|
getMetadata(key) {
|
|
3458
3468
|
const row = this.db.prepare('SELECT value FROM project_metadata WHERE key = ?').get(key);
|
|
3459
3469
|
return row?.value ?? null;
|
|
3460
3470
|
}
|
|
3461
|
-
/**
|
|
3462
|
-
* Set a metadata key-value pair (upsert)
|
|
3463
|
-
*/
|
|
3464
3471
|
setMetadata(key, value) {
|
|
3465
3472
|
this.db.prepare('INSERT INTO project_metadata (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at').run(key, value, Date.now());
|
|
3466
3473
|
}
|
|
3467
|
-
/**
|
|
3468
|
-
* Get all metadata as a key-value record
|
|
3469
|
-
*/
|
|
3470
3474
|
getAllMetadata() {
|
|
3471
3475
|
const rows = this.db.prepare('SELECT key, value FROM project_metadata').all();
|
|
3472
3476
|
const result = {};
|
|
@@ -3475,9 +3479,6 @@ class QueryBuilder {
|
|
|
3475
3479
|
}
|
|
3476
3480
|
return result;
|
|
3477
3481
|
}
|
|
3478
|
-
/**
|
|
3479
|
-
* Clear all data from the database
|
|
3480
|
-
*/
|
|
3481
3482
|
clear() {
|
|
3482
3483
|
this.nodeCache.clear();
|
|
3483
3484
|
this.db.transaction(() => {
|
|
@@ -3490,8 +3491,6 @@ class QueryBuilder {
|
|
|
3490
3491
|
}
|
|
3491
3492
|
exports.QueryBuilder = QueryBuilder;
|
|
3492
3493
|
function foldModuleRows(rows, options) {
|
|
3493
|
-
// A module id is a path and may contain anything printable, so the key
|
|
3494
|
-
// separator has to be something a path cannot hold.
|
|
3495
3494
|
const SEP = '\u0000';
|
|
3496
3495
|
const links = new Map();
|
|
3497
3496
|
const pairKinds = new Set(options.pairKinds);
|
|
@@ -3515,9 +3514,6 @@ function foldModuleRows(rows, options) {
|
|
|
3515
3514
|
uncertain: row.uncertain,
|
|
3516
3515
|
});
|
|
3517
3516
|
}
|
|
3518
|
-
// Only the confident half of a row can be named: an uncertain edge is a
|
|
3519
|
-
// guess, and printing "a to b, 12" for twelve guesses is the map claiming
|
|
3520
|
-
// something it does not know.
|
|
3521
3517
|
if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind))
|
|
3522
3518
|
continue;
|
|
3523
3519
|
const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;
|