@colbymchenry/codegraph-win32-arm64 1.6.2 → 1.6.3
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 +425 -688
- 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 +610 -33
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +1345 -1419
- 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 +34 -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 +66 -204
- 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 +145 -206
- 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 +45 -4
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +53 -430
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +197 -7
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +554 -1382
- 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 +25 -133
- 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.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 +84 -0
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +329 -161
- 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 +35 -184
- 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.js +5 -42
- 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.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.js +0 -13
- package/lib/dist/extraction/parse-budget.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +29 -5
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +42 -174
- 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 +447 -9
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +1908 -2544
- 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-vbnet.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +6 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +1 -88
- 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/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 +2 -2
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -135
- 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/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 +21 -0
- package/lib/dist/graph/test-code.d.ts.map +1 -0
- package/lib/dist/graph/test-code.js +50 -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 +98 -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 +190 -25
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +694 -1109
- 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 +9 -5
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +25 -159
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/instructions-template.d.ts +1 -1
- package/lib/dist/installer/instructions-template.js +0 -37
- 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.js +0 -102
- 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 +81 -11
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +183 -129
- 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.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +2 -85
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +40 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +174 -137
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +23 -0
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +89 -373
- 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 +8 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +33 -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.js +0 -116
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -1
- 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/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 +19 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +118 -293
- 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/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.map +1 -1
- package/lib/dist/mcp/project-lifecycle.js +50 -17
- package/lib/dist/mcp/project-lifecycle.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts +17 -6
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +74 -248
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +43 -3
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +109 -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.js +0 -31
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +27 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +29 -130
- 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 +127 -18
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +661 -3590
- 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.js +1 -138
- 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 +15 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +1355 -1270
- 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/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/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 +5 -68
- 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/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.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +182 -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 +13 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +12 -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.js +2 -125
- 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 +276 -29
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +1670 -1380
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +415 -6
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +1323 -1037
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/js-builtins.d.ts +14 -0
- package/lib/dist/resolution/js-builtins.d.ts.map +1 -1
- package/lib/dist/resolution/js-builtins.js +14 -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 +185 -0
- package/lib/dist/resolution/module-importers.d.ts.map +1 -0
- package/lib/dist/resolution/module-importers.js +588 -0
- package/lib/dist/resolution/module-importers.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +858 -7
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +21030 -5110
- 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/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/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 +2 -101
- 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.js +4 -170
- 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 +183 -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 +570 -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,6 @@ class QueryBuilder {
|
|
|
1162
922
|
const rows = this.stmts.getNodesByNamePrefix.all(prefix, prefix + '', limit);
|
|
1163
923
|
return rows.map(rowToNode);
|
|
1164
924
|
}
|
|
1165
|
-
/** File nodes whose basename starts with `prefix`, without a result cap. */
|
|
1166
925
|
getFileNodesByNamePrefix(prefix) {
|
|
1167
926
|
if (!this.stmts.getFileNodesByNamePrefix) {
|
|
1168
927
|
this.stmts.getFileNodesByNamePrefix = this.db.prepare("SELECT * FROM nodes WHERE kind = 'file' AND name >= ? AND name < ? ORDER BY name");
|
|
@@ -1170,51 +929,42 @@ class QueryBuilder {
|
|
|
1170
929
|
const rows = this.stmts.getFileNodesByNamePrefix.all(prefix, prefix + '');
|
|
1171
930
|
return rows.map(rowToNode);
|
|
1172
931
|
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
|
|
1175
|
-
*/
|
|
1176
932
|
getNodesByQualifiedNameExact(qualifiedName) {
|
|
1177
933
|
if (!this.stmts.getNodesByQualifiedNameExact) {
|
|
1178
|
-
this.stmts.getNodesByQualifiedNameExact = this.db
|
|
934
|
+
this.stmts.getNodesByQualifiedNameExact = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE qualified_name = ? ORDER BY file_path, start_line, id');
|
|
1179
935
|
}
|
|
1180
|
-
|
|
1181
|
-
return rows.map(rowToNode);
|
|
936
|
+
return this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
|
|
1182
937
|
}
|
|
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
938
|
getNodesByLowerName(name) {
|
|
1198
939
|
if (!this.stmts.getNodesByLowerName) {
|
|
1199
|
-
this.stmts.getNodesByLowerName = this.db
|
|
940
|
+
this.stmts.getNodesByLowerName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE lower(name) = lower(?)');
|
|
1200
941
|
}
|
|
1201
|
-
|
|
942
|
+
return this.stmts.getNodesByLowerName.all(name);
|
|
943
|
+
}
|
|
944
|
+
hasFilesOfLanguage(language) {
|
|
945
|
+
if (!this.stmts.hasFilesOfLanguage) {
|
|
946
|
+
this.stmts.hasFilesOfLanguage = this.db.prepare('SELECT 1 FROM files WHERE language = ? LIMIT 1');
|
|
947
|
+
}
|
|
948
|
+
return this.stmts.hasFilesOfLanguage.get(language) !== undefined;
|
|
949
|
+
}
|
|
950
|
+
getCobolIncludesByMember(member, limit) {
|
|
951
|
+
if (!this.stmts.getCobolIncludesByMember) {
|
|
952
|
+
this.stmts.getCobolIncludesByMember = this.db.prepare("SELECT * FROM nodes WHERE lower(name) = lower(?) AND +kind = 'import' AND +language = 'cobol'"
|
|
953
|
+
+ ' ORDER BY file_path, start_line, id LIMIT ?');
|
|
954
|
+
}
|
|
955
|
+
const rows = this.stmts.getCobolIncludesByMember.all(member, limit);
|
|
956
|
+
return rows.map(rowToNode);
|
|
957
|
+
}
|
|
958
|
+
getCobolFilesByStem(member) {
|
|
959
|
+
if (!this.stmts.getCobolFilesByStem) {
|
|
960
|
+
this.stmts.getCobolFilesByStem = this.db.prepare("SELECT * FROM nodes WHERE lower(name) >= lower(?) || '.' AND lower(name) < lower(?) || '/'"
|
|
961
|
+
+ " AND +kind = 'file' AND +language = 'cobol' ORDER BY file_path");
|
|
962
|
+
}
|
|
963
|
+
const rows = this.stmts.getCobolFilesByStem.all(member, member);
|
|
1202
964
|
return rows.map(rowToNode);
|
|
1203
965
|
}
|
|
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
966
|
searchNodes(query, options = {}) {
|
|
1213
967
|
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
968
|
const parsed = (0, query_parser_1.parseQuery)(query);
|
|
1219
969
|
const mergedKinds = parsed.kinds.length > 0
|
|
1220
970
|
? Array.from(new Set([...(options.kinds ?? []), ...parsed.kinds]))
|
|
@@ -1222,53 +972,21 @@ class QueryBuilder {
|
|
|
1222
972
|
const mergedLanguages = parsed.languages.length > 0
|
|
1223
973
|
? Array.from(new Set([...(options.languages ?? []), ...parsed.languages]))
|
|
1224
974
|
: 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.
|
|
975
|
+
const filters = fieldFiltersOf(parsed);
|
|
976
|
+
if (filters && !this.fieldFiltersCanMatch(filters))
|
|
977
|
+
return [];
|
|
1231
978
|
const text = parsed.text;
|
|
1232
979
|
const kinds = mergedKinds;
|
|
1233
980
|
const languages = mergedLanguages;
|
|
1234
|
-
// First try FTS5 with prefix matching (skip if FTS5 not available, #1532)
|
|
1235
981
|
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
|
|
982
|
+
? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }, filters) : [])
|
|
983
|
+
: this.searchAllByFilters({ kinds, languages, limit: limit * 5, offset }, filters);
|
|
1243
984
|
if (results.length === 0 && text.length >= 2) {
|
|
1244
|
-
results = this.searchNodesLike(text, { kinds, languages, limit, offset });
|
|
985
|
+
results = this.searchNodesLike(text, { kinds, languages, limit, offset }, filters);
|
|
1245
986
|
}
|
|
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
987
|
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.
|
|
988
|
+
results = this.searchNodesFuzzy(text, { kinds, languages, limit }, filters);
|
|
989
|
+
}
|
|
1272
990
|
if (results.length > 0 && query) {
|
|
1273
991
|
const existingIds = new Set(results.map(r => r.node.id));
|
|
1274
992
|
const maxFtsScore = Math.max(...results.map(r => r.score));
|
|
@@ -1284,8 +1002,11 @@ class QueryBuilder {
|
|
|
1284
1002
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1285
1003
|
params.push(...languages);
|
|
1286
1004
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1005
|
+
if (filters)
|
|
1006
|
+
sql += fieldFilterSql(filters, params);
|
|
1007
|
+
const rows = filters
|
|
1008
|
+
? this.readFilteredPage(sql, params, filters, 20, 0)
|
|
1009
|
+
: this.db.prepare(`${sql} LIMIT 20`).all(...params);
|
|
1289
1010
|
for (const row of rows) {
|
|
1290
1011
|
if (!existingIds.has(row.id)) {
|
|
1291
1012
|
results.push({ node: rowToNode(row), score: maxFtsScore });
|
|
@@ -1294,18 +1015,14 @@ class QueryBuilder {
|
|
|
1294
1015
|
}
|
|
1295
1016
|
}
|
|
1296
1017
|
}
|
|
1297
|
-
|
|
1018
|
+
if (filters) {
|
|
1019
|
+
results = results.filter((r) => passesFieldFilters(r.node.name, r.node.filePath, filters));
|
|
1020
|
+
}
|
|
1298
1021
|
if (results.length > 0 && (text || query)) {
|
|
1299
1022
|
const scoringQuery = text || query;
|
|
1023
|
+
const isDeprioritizedPath = this.getDeprioritizedPathSnapshot();
|
|
1300
1024
|
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;
|
|
1025
|
+
const deprioritized = isDeprioritizedPath?.(r.node.filePath) ?? false;
|
|
1309
1026
|
const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
|
|
1310
1027
|
return {
|
|
1311
1028
|
...r,
|
|
@@ -1316,39 +1033,32 @@ class QueryBuilder {
|
|
|
1316
1033
|
};
|
|
1317
1034
|
});
|
|
1318
1035
|
results.sort((a, b) => b.score - a.score);
|
|
1319
|
-
// Trim to requested limit after rescoring
|
|
1320
1036
|
if (results.length > limit) {
|
|
1321
1037
|
results = results.slice(0, limit);
|
|
1322
1038
|
}
|
|
1323
1039
|
}
|
|
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
1040
|
return results;
|
|
1343
1041
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1042
|
+
readFilteredPage(sql, params, filters, limit, offset) {
|
|
1043
|
+
const page = [];
|
|
1044
|
+
if (limit === 0)
|
|
1045
|
+
return page;
|
|
1046
|
+
let skipped = 0;
|
|
1047
|
+
for (const row of this.db.prepare(sql).iterate(...params)) {
|
|
1048
|
+
if (!passesFieldFilters(row.name, row.file_path, filters))
|
|
1049
|
+
continue;
|
|
1050
|
+
if (skipped < offset) {
|
|
1051
|
+
skipped++;
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
page.push(row);
|
|
1055
|
+
if (page.length === limit)
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
1058
|
+
return page;
|
|
1059
|
+
}
|
|
1060
|
+
searchAllByFilters(options, filters) {
|
|
1061
|
+
const { kinds, languages, limit, offset } = options;
|
|
1352
1062
|
let sql = 'SELECT * FROM nodes WHERE 1=1';
|
|
1353
1063
|
const params = [];
|
|
1354
1064
|
if (kinds && kinds.length > 0) {
|
|
@@ -1359,47 +1069,38 @@ class QueryBuilder {
|
|
|
1359
1069
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1360
1070
|
params.push(...languages);
|
|
1361
1071
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1072
|
+
if (filters)
|
|
1073
|
+
sql += fieldFilterSql(filters, params);
|
|
1074
|
+
sql += ' ORDER BY name';
|
|
1075
|
+
const rows = filters
|
|
1076
|
+
? this.readFilteredPage(sql, params, filters, limit, offset)
|
|
1077
|
+
: this.db.prepare(`${sql} LIMIT ? OFFSET ?`).all(...params, limit, offset);
|
|
1365
1078
|
return rows.map((row) => ({ node: rowToNode(row), score: 1 }));
|
|
1366
1079
|
}
|
|
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) {
|
|
1080
|
+
searchNodesFuzzy(text, options, filters) {
|
|
1376
1081
|
const { kinds, languages, limit } = options;
|
|
1377
1082
|
const lowered = text.toLowerCase();
|
|
1378
1083
|
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();
|
|
1084
|
+
const { names, lowered: loweredNames, starts } = this.fuzzyNames();
|
|
1384
1085
|
const candidates = [];
|
|
1385
|
-
for (
|
|
1386
|
-
const
|
|
1086
|
+
for (let i = 0; i < names.length; i++) {
|
|
1087
|
+
const end = starts[i + 1] - 1;
|
|
1088
|
+
if (Math.abs(end - starts[i] - lowered.length) > maxDist)
|
|
1089
|
+
continue;
|
|
1090
|
+
const dist = (0, query_parser_1.boundedEditDistance)(loweredNames.slice(starts[i], end), lowered, maxDist);
|
|
1387
1091
|
if (dist <= maxDist)
|
|
1388
|
-
candidates.push({ name, dist });
|
|
1092
|
+
candidates.push({ name: names[i], dist });
|
|
1389
1093
|
}
|
|
1390
1094
|
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
1095
|
const FUZZY_FOLLOWUP_CAP = Math.max(limit * 2, 50);
|
|
1397
|
-
const cappedCandidates = candidates.slice(0, FUZZY_FOLLOWUP_CAP);
|
|
1096
|
+
const cappedCandidates = filters ? candidates : candidates.slice(0, FUZZY_FOLLOWUP_CAP);
|
|
1398
1097
|
const results = [];
|
|
1399
1098
|
const seen = new Set();
|
|
1400
1099
|
for (const c of cappedCandidates) {
|
|
1401
1100
|
if (results.length >= limit)
|
|
1402
1101
|
break;
|
|
1102
|
+
if (filters && !passesNameFilters(c.name, filters))
|
|
1103
|
+
continue;
|
|
1403
1104
|
let sql = 'SELECT * FROM nodes WHERE name = ?';
|
|
1404
1105
|
const params = [c.name];
|
|
1405
1106
|
if (kinds && kinds.length > 0) {
|
|
@@ -1410,14 +1111,15 @@ class QueryBuilder {
|
|
|
1410
1111
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1411
1112
|
params.push(...languages);
|
|
1412
1113
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1114
|
+
if (filters)
|
|
1115
|
+
sql += fieldFilterSql(filters, params);
|
|
1116
|
+
const rows = filters
|
|
1117
|
+
? this.readFilteredPage(sql, params, filters, 5, 0)
|
|
1118
|
+
: this.db.prepare(`${sql} LIMIT 5`).all(...params);
|
|
1415
1119
|
for (const row of rows) {
|
|
1416
1120
|
if (seen.has(row.id))
|
|
1417
1121
|
continue;
|
|
1418
1122
|
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
1123
|
results.push({ node: rowToNode(row), score: 1 / (1 + c.dist) });
|
|
1422
1124
|
if (results.length >= limit)
|
|
1423
1125
|
break;
|
|
@@ -1425,39 +1127,37 @@ class QueryBuilder {
|
|
|
1425
1127
|
}
|
|
1426
1128
|
return results;
|
|
1427
1129
|
}
|
|
1428
|
-
/** Bounded miss diagnostics, independent of relevance filters and ranking. */
|
|
1429
1130
|
getExploreMissDiagnostics(query) {
|
|
1430
1131
|
const words = [...new Set((query.match(/[\p{L}\p{N}]+/gu) ?? []).map(w => w.toLowerCase()))];
|
|
1431
1132
|
const checked = words.filter(w => w.length <= 64).slice(0, 16);
|
|
1432
1133
|
const limited = checked.length !== words.length;
|
|
1433
1134
|
if (checked.length === 0)
|
|
1434
1135
|
return { matched: [], unmatched: [], candidates: [], limited };
|
|
1435
|
-
|
|
1436
|
-
// Vocab rows can outlive deleted definitions, so verify them against nodes.
|
|
1136
|
+
const vocab = this.hasSchema('name_segment_vocab');
|
|
1437
1137
|
const rows = this.db.prepare(`
|
|
1438
1138
|
WITH words(word, pattern) AS (VALUES ${checked.map(() => '(?, ?)').join(', ')})
|
|
1439
1139
|
SELECT word, (
|
|
1440
|
-
EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)
|
|
1140
|
+
EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)${vocab ? `
|
|
1441
1141
|
OR EXISTS (
|
|
1442
1142
|
SELECT 1 FROM name_segment_vocab v WHERE v.segment = word
|
|
1443
1143
|
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1444
|
-
)
|
|
1144
|
+
)` : ''}
|
|
1445
1145
|
) AS matched FROM words
|
|
1446
1146
|
`).all(...checked.flatMap(w => [w, `{name qualified_name signature docstring} : "${w}"*`]));
|
|
1447
|
-
const names = this.db.prepare(`
|
|
1147
|
+
const names = this.db.prepare(`${vocab ? `
|
|
1448
1148
|
SELECT name FROM (
|
|
1449
1149
|
SELECT v.name FROM name_segment_vocab v
|
|
1450
1150
|
WHERE v.segment IN (${checked.map(() => '?').join(', ')})
|
|
1451
1151
|
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1452
1152
|
LIMIT 12
|
|
1453
1153
|
)
|
|
1454
|
-
UNION ALL
|
|
1154
|
+
UNION ALL` : ''}
|
|
1455
1155
|
SELECT name FROM (
|
|
1456
1156
|
SELECT n.name FROM nodes_fts JOIN nodes n ON n.rowid = nodes_fts.rowid
|
|
1457
1157
|
WHERE nodes_fts MATCH ? AND n.kind NOT IN ('file', 'import')
|
|
1458
1158
|
LIMIT 12
|
|
1459
1159
|
)
|
|
1460
|
-
`).all(...checked, `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
|
|
1160
|
+
`).all(...(vocab ? checked : []), `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
|
|
1461
1161
|
return {
|
|
1462
1162
|
matched: rows.filter(r => r.matched).map(r => r.word),
|
|
1463
1163
|
unmatched: rows.filter(r => !r.matched).map(r => r.word),
|
|
@@ -1465,40 +1165,44 @@ class QueryBuilder {
|
|
|
1465
1165
|
limited,
|
|
1466
1166
|
};
|
|
1467
1167
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1168
|
+
getUnseenNames(names) {
|
|
1169
|
+
const checked = [...new Set(names)].filter((n) => n.length > 0 && n.length <= 128).slice(0, 16);
|
|
1170
|
+
if (checked.length === 0)
|
|
1171
|
+
return [];
|
|
1172
|
+
if (!this.stmts.unseenName) {
|
|
1173
|
+
this.stmts.unseenName = this.db.prepare(`
|
|
1174
|
+
SELECT EXISTS (SELECT 1 FROM nodes WHERE lower(name) = lower(?))
|
|
1175
|
+
OR EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH ?) AS seen
|
|
1176
|
+
`);
|
|
1177
|
+
}
|
|
1178
|
+
const stmt = this.stmts.unseenName;
|
|
1179
|
+
return checked.filter((name) => {
|
|
1180
|
+
const member = name.split(/::|\./).pop();
|
|
1181
|
+
const phrase = member.replace(/"/g, '');
|
|
1182
|
+
if (phrase.length === 0)
|
|
1183
|
+
return false;
|
|
1184
|
+
const row = stmt.get(member, `{name qualified_name signature docstring} : "${phrase}"*`);
|
|
1185
|
+
return !row.seen;
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
searchNodesFTS(query, options, filters) {
|
|
1472
1189
|
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
1190
|
const ftsQuery = query
|
|
1481
|
-
.replace(/::/g, ' ')
|
|
1482
|
-
.replace(/['"*():^]/g, '')
|
|
1191
|
+
.replace(/::/g, ' ')
|
|
1192
|
+
.replace(/['"*():^]/g, ' ')
|
|
1483
1193
|
.split(/\s+/)
|
|
1484
1194
|
.filter(term => term.length > 0)
|
|
1485
|
-
// Strip FTS5 boolean operators to prevent query manipulation
|
|
1486
1195
|
.filter(term => !/^(AND|OR|NOT|NEAR)$/i.test(term))
|
|
1487
|
-
.map(term => `"${term}"*`)
|
|
1196
|
+
.map(term => `"${term}"*`)
|
|
1488
1197
|
.join(' OR ');
|
|
1489
1198
|
if (!ftsQuery) {
|
|
1490
1199
|
return [];
|
|
1491
1200
|
}
|
|
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
1201
|
const ftsLimit = Math.max(limit * 5, 100);
|
|
1498
1202
|
let sql = `
|
|
1499
1203
|
SELECT nodes.*, bm25(nodes_fts, 0, 20, 5, 1, 2) as score
|
|
1500
1204
|
FROM nodes_fts
|
|
1501
|
-
JOIN nodes ON
|
|
1205
|
+
CROSS JOIN nodes ON nodes.rowid = nodes_fts.rowid
|
|
1502
1206
|
WHERE nodes_fts MATCH ?
|
|
1503
1207
|
`;
|
|
1504
1208
|
const params = [ftsQuery];
|
|
@@ -1510,26 +1214,38 @@ class QueryBuilder {
|
|
|
1510
1214
|
sql += ` AND nodes.language IN (${languages.map(() => '?').join(',')})`;
|
|
1511
1215
|
params.push(...languages);
|
|
1512
1216
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1217
|
+
if (filters)
|
|
1218
|
+
sql += fieldFilterSql(filters, params);
|
|
1219
|
+
sql += ' ORDER BY score';
|
|
1515
1220
|
try {
|
|
1516
|
-
|
|
1221
|
+
let rows;
|
|
1222
|
+
if (filters) {
|
|
1223
|
+
rows = this.readFilteredPage(sql, params, filters, ftsLimit, offset);
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
sql += ' LIMIT ? OFFSET ?';
|
|
1227
|
+
params.push(ftsLimit, offset);
|
|
1228
|
+
rows = this.db.prepare(sql).all(...params);
|
|
1229
|
+
}
|
|
1517
1230
|
return rows.map((row) => ({
|
|
1518
1231
|
node: rowToNode(row),
|
|
1519
|
-
score: Math.abs(row.score),
|
|
1232
|
+
score: Math.abs(row.score),
|
|
1520
1233
|
}));
|
|
1521
1234
|
}
|
|
1522
1235
|
catch {
|
|
1523
|
-
// FTS query failed, return empty
|
|
1524
1236
|
return [];
|
|
1525
1237
|
}
|
|
1526
1238
|
}
|
|
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) {
|
|
1239
|
+
searchNodesLike(query, options, filters) {
|
|
1532
1240
|
const { kinds, languages, limit = 100, offset = 0 } = options;
|
|
1241
|
+
if (/^[A-Za-z0-9]+$/.test(query)) {
|
|
1242
|
+
const runs = this.memoizedRead('qualifiedNameRuns', () => this.readQualifiedNameRuns());
|
|
1243
|
+
if (runs !== null) {
|
|
1244
|
+
const word = query.toLowerCase();
|
|
1245
|
+
if (!this.fuzzyNames().lowered.includes(word) && !runs.includes(word))
|
|
1246
|
+
return [];
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1533
1249
|
let sql = `
|
|
1534
1250
|
SELECT nodes.*,
|
|
1535
1251
|
CASE
|
|
@@ -1546,18 +1262,17 @@ class QueryBuilder {
|
|
|
1546
1262
|
name LIKE ?
|
|
1547
1263
|
)
|
|
1548
1264
|
`;
|
|
1549
|
-
// Pattern variants for better matching
|
|
1550
1265
|
const exactMatch = query;
|
|
1551
1266
|
const startsWith = `${query}%`;
|
|
1552
1267
|
const contains = `%${query}%`;
|
|
1553
1268
|
const params = [
|
|
1554
|
-
exactMatch,
|
|
1555
|
-
startsWith,
|
|
1556
|
-
contains,
|
|
1557
|
-
contains,
|
|
1558
|
-
contains,
|
|
1559
|
-
contains,
|
|
1560
|
-
startsWith,
|
|
1269
|
+
exactMatch,
|
|
1270
|
+
startsWith,
|
|
1271
|
+
contains,
|
|
1272
|
+
contains,
|
|
1273
|
+
contains,
|
|
1274
|
+
contains,
|
|
1275
|
+
startsWith,
|
|
1561
1276
|
];
|
|
1562
1277
|
if (kinds && kinds.length > 0) {
|
|
1563
1278
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1567,39 +1282,27 @@ class QueryBuilder {
|
|
|
1567
1282
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1568
1283
|
params.push(...languages);
|
|
1569
1284
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1285
|
+
if (filters)
|
|
1286
|
+
sql += fieldFilterSql(filters, params);
|
|
1287
|
+
sql += ' ORDER BY score DESC, length(name) ASC';
|
|
1288
|
+
let rows;
|
|
1289
|
+
if (filters) {
|
|
1290
|
+
rows = this.readFilteredPage(sql, params, filters, limit, offset);
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
sql += ' LIMIT ? OFFSET ?';
|
|
1294
|
+
params.push(limit, offset);
|
|
1295
|
+
rows = this.db.prepare(sql).all(...params);
|
|
1296
|
+
}
|
|
1573
1297
|
return rows.map((row) => ({
|
|
1574
1298
|
node: rowToNode(row),
|
|
1575
1299
|
score: row.score,
|
|
1576
1300
|
}));
|
|
1577
1301
|
}
|
|
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
1302
|
findNodesByExactName(names, options = {}) {
|
|
1589
1303
|
if (names.length === 0)
|
|
1590
1304
|
return [];
|
|
1591
1305
|
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
1306
|
const nameToFiles = new Map();
|
|
1604
1307
|
for (const name of names) {
|
|
1605
1308
|
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
|
|
@@ -1612,7 +1315,6 @@ class QueryBuilder {
|
|
|
1612
1315
|
const rows = this.db.prepare(sql).all(...params);
|
|
1613
1316
|
nameToFiles.set(name.toLowerCase(), new Set(rows.map(r => r.file_path)));
|
|
1614
1317
|
}
|
|
1615
|
-
// Distinctive names are those with fewer than 10 file matches (e.g., "scrapeLoop" = 1 file)
|
|
1616
1318
|
const distinctiveFiles = new Set();
|
|
1617
1319
|
for (const [, files] of nameToFiles) {
|
|
1618
1320
|
if (files.size > 0 && files.size < 10) {
|
|
@@ -1620,7 +1322,6 @@ class QueryBuilder {
|
|
|
1620
1322
|
distinctiveFiles.add(f);
|
|
1621
1323
|
}
|
|
1622
1324
|
}
|
|
1623
|
-
// Pass 2: Query each name with per-name limit, scoring by co-location
|
|
1624
1325
|
const perNameLimit = Math.max(8, Math.ceil(limit / names.length));
|
|
1625
1326
|
const allResults = [];
|
|
1626
1327
|
const seenIds = new Set();
|
|
@@ -1639,7 +1340,6 @@ class QueryBuilder {
|
|
|
1639
1340
|
sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
|
|
1640
1341
|
params.push(...languages);
|
|
1641
1342
|
}
|
|
1642
|
-
// Fetch enough to find co-located results among common names
|
|
1643
1343
|
sql += ' LIMIT ?';
|
|
1644
1344
|
params.push(Math.max(perNameLimit * 3, 50));
|
|
1645
1345
|
const rows = this.db.prepare(sql).all(...params);
|
|
@@ -1648,28 +1348,18 @@ class QueryBuilder {
|
|
|
1648
1348
|
const node = rowToNode(row);
|
|
1649
1349
|
if (seenIds.has(node.id))
|
|
1650
1350
|
continue;
|
|
1651
|
-
// Boost results in files that also contain distinctive symbols
|
|
1652
1351
|
const coLocationBoost = distinctiveFiles.has(node.filePath) ? 20 : 0;
|
|
1653
1352
|
nameResults.push({ node, score: row.score + coLocationBoost });
|
|
1654
1353
|
}
|
|
1655
|
-
// Sort by score (co-located first), take per-name limit
|
|
1656
1354
|
nameResults.sort((a, b) => b.score - a.score);
|
|
1657
1355
|
for (const r of nameResults.slice(0, perNameLimit)) {
|
|
1658
1356
|
seenIds.add(r.node.id);
|
|
1659
1357
|
allResults.push(r);
|
|
1660
1358
|
}
|
|
1661
1359
|
}
|
|
1662
|
-
// Sort all results by score so co-located results bubble up
|
|
1663
1360
|
allResults.sort((a, b) => b.score - a.score);
|
|
1664
1361
|
return allResults.slice(0, limit);
|
|
1665
1362
|
}
|
|
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
1363
|
findNodesByNameSubstring(substring, options = {}) {
|
|
1674
1364
|
const { kinds, languages, limit = 30, excludePrefix } = options;
|
|
1675
1365
|
let sql = `
|
|
@@ -1678,7 +1368,6 @@ class QueryBuilder {
|
|
|
1678
1368
|
WHERE name LIKE ?
|
|
1679
1369
|
`;
|
|
1680
1370
|
const params = [`%${substring}%`];
|
|
1681
|
-
// Exclude prefix matches (handled by FTS-based prefix search in Step 2b)
|
|
1682
1371
|
if (excludePrefix) {
|
|
1683
1372
|
sql += ` AND name NOT LIKE ?`;
|
|
1684
1373
|
params.push(`${substring}%`);
|
|
@@ -1693,16 +1382,71 @@ class QueryBuilder {
|
|
|
1693
1382
|
}
|
|
1694
1383
|
sql += ' ORDER BY length(name) ASC LIMIT ?';
|
|
1695
1384
|
params.push(limit);
|
|
1385
|
+
if (kinds && kinds.length > 0 && !(languages && languages.length > 0)) {
|
|
1386
|
+
const index = this.memoizedRead('nameSubstringIndex', () => this.readNameSubstringIndex());
|
|
1387
|
+
const order = index ? this.substringScanOrder(index, sql, params, excludePrefix ? 2 : 1) : null;
|
|
1388
|
+
const rowids = order ? (0, name_substring_index_1.searchNameSubstring)(index.index, substring, kinds, excludePrefix === true, limit, order) : null;
|
|
1389
|
+
if (rowids) {
|
|
1390
|
+
return this.getNodeRowsByRowid(rowids).map((row) => ({ node: rowToNode(row), score: 1.0 }));
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1696
1393
|
const rows = this.db.prepare(sql).all(...params);
|
|
1697
1394
|
return rows.map((row) => ({
|
|
1698
1395
|
node: rowToNode(row),
|
|
1699
1396
|
score: row.score,
|
|
1700
1397
|
}));
|
|
1701
1398
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1399
|
+
substringScanOrder(memo, sql, params, patternCount) {
|
|
1400
|
+
const key = `${sql}\u0000${params.slice(patternCount).join('\u0000')}`;
|
|
1401
|
+
let order = memo.plans.get(key);
|
|
1402
|
+
if (order === undefined) {
|
|
1403
|
+
order = null;
|
|
1404
|
+
try {
|
|
1405
|
+
const details = this.db.prepare(`EXPLAIN QUERY PLAN ${sql}`).all(...params)
|
|
1406
|
+
.map((row) => row.detail)
|
|
1407
|
+
.filter((detail) => /^(SCAN|SEARCH) (TABLE )?nodes\b/.test(detail));
|
|
1408
|
+
if (details.length === 1) {
|
|
1409
|
+
if (/^SEARCH (TABLE )?nodes USING (COVERING )?INDEX idx_nodes_kind \(/.test(details[0]))
|
|
1410
|
+
order = 'index';
|
|
1411
|
+
else if (/^SCAN (TABLE )?nodes$/.test(details[0]))
|
|
1412
|
+
order = 'rowid';
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
catch {
|
|
1416
|
+
order = null;
|
|
1417
|
+
}
|
|
1418
|
+
memo.plans.set(key, order);
|
|
1419
|
+
}
|
|
1420
|
+
return order;
|
|
1421
|
+
}
|
|
1422
|
+
readNameSubstringIndex() {
|
|
1423
|
+
const rows = this.db
|
|
1424
|
+
.prepare(`SELECT rowid AS rowid, kind, name FROM nodes WHERE kind IN (${name_substring_index_1.NAME_SUBSTRING_KINDS.map(() => '?').join(',')})`
|
|
1425
|
+
+ ' ORDER BY kind, file_path, start_line, id')
|
|
1426
|
+
.all(...name_substring_index_1.NAME_SUBSTRING_KINDS);
|
|
1427
|
+
const index = (0, name_substring_index_1.buildNameSubstringIndex)(rows);
|
|
1428
|
+
return index ? { index, plans: new Map() } : null;
|
|
1429
|
+
}
|
|
1430
|
+
getNodeRowsByRowid(rowids) {
|
|
1431
|
+
if (rowids.length === 0)
|
|
1432
|
+
return [];
|
|
1433
|
+
const byRowid = new Map();
|
|
1434
|
+
for (let i = 0; i < rowids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1435
|
+
const chunk = rowids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1436
|
+
const rows = this.db
|
|
1437
|
+
.prepare(`SELECT rowid AS rowid_, nodes.* FROM nodes WHERE rowid IN (${chunk.map(() => '?').join(',')})`)
|
|
1438
|
+
.all(...chunk);
|
|
1439
|
+
for (const row of rows)
|
|
1440
|
+
byRowid.set(row.rowid_, row);
|
|
1441
|
+
}
|
|
1442
|
+
const out = [];
|
|
1443
|
+
for (const rowid of rowids) {
|
|
1444
|
+
const row = byRowid.get(rowid);
|
|
1445
|
+
if (row)
|
|
1446
|
+
out.push(row);
|
|
1447
|
+
}
|
|
1448
|
+
return out;
|
|
1449
|
+
}
|
|
1706
1450
|
hasSynthesizedEdgesTouchingFile(filePath) {
|
|
1707
1451
|
const owned = "CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.synthesizedBy') END IS NOT NULL";
|
|
1708
1452
|
for (const endpoint of ['source', 'target']) {
|
|
@@ -1710,7 +1454,6 @@ class QueryBuilder {
|
|
|
1710
1454
|
WHERE n.file_path = ? AND ${owned} LIMIT 1`).get(filePath))
|
|
1711
1455
|
return true;
|
|
1712
1456
|
}
|
|
1713
|
-
// Wiring often lives in a third file, with neither endpoint in it.
|
|
1714
1457
|
return !!this.db.prepare(`SELECT 1 FROM edges e WHERE ${owned}
|
|
1715
1458
|
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END >= ?
|
|
1716
1459
|
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END < ? LIMIT 1`).get(`${filePath}:`, `${filePath};`);
|
|
@@ -1721,14 +1464,11 @@ class QueryBuilder {
|
|
|
1721
1464
|
replaceSynthesisInputs(files) {
|
|
1722
1465
|
this.db.transaction(() => {
|
|
1723
1466
|
this.db.exec('DELETE FROM synthesis_inputs');
|
|
1724
|
-
const insert = this.db.prepare('INSERT INTO synthesis_inputs(file_path)
|
|
1467
|
+
const insert = this.db.prepare('INSERT OR IGNORE INTO synthesis_inputs(file_path) SELECT path FROM files WHERE path = ?');
|
|
1725
1468
|
for (const file of files)
|
|
1726
1469
|
insert.run(file);
|
|
1727
1470
|
})();
|
|
1728
1471
|
}
|
|
1729
|
-
/**
|
|
1730
|
-
* Insert a new edge
|
|
1731
|
-
*/
|
|
1732
1472
|
insertEdge(edge) {
|
|
1733
1473
|
if (!this.stmts.insertEdge) {
|
|
1734
1474
|
this.stmts.insertEdge = this.db.prepare(`
|
|
@@ -1746,9 +1486,6 @@ class QueryBuilder {
|
|
|
1746
1486
|
provenance: edge.provenance ?? null,
|
|
1747
1487
|
});
|
|
1748
1488
|
}
|
|
1749
|
-
/**
|
|
1750
|
-
* Insert multiple edges in a transaction
|
|
1751
|
-
*/
|
|
1752
1489
|
insertEdges(edges) {
|
|
1753
1490
|
if (edges.length === 0)
|
|
1754
1491
|
return;
|
|
@@ -1777,21 +1514,14 @@ class QueryBuilder {
|
|
|
1777
1514
|
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
1778
1515
|
})();
|
|
1779
1516
|
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Delete all edges from a source node
|
|
1782
|
-
*/
|
|
1783
1517
|
deleteEdgesBySource(sourceId) {
|
|
1784
1518
|
if (!this.stmts.deleteEdgesBySource) {
|
|
1785
1519
|
this.stmts.deleteEdgesBySource = this.db.prepare('DELETE FROM edges WHERE source = ?');
|
|
1786
1520
|
}
|
|
1787
1521
|
this.stmts.deleteEdgesBySource.run(sourceId);
|
|
1788
1522
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
* (calls before imports/references), then break ties deterministically.
|
|
1792
|
-
*/
|
|
1793
|
-
getOutgoingEdges(sourceId, kinds, provenance) {
|
|
1794
|
-
if ((kinds && kinds.length > 0) || provenance) {
|
|
1523
|
+
getOutgoingEdges(sourceId, kinds, provenance, limit) {
|
|
1524
|
+
if ((kinds && kinds.length > 0) || provenance || limit !== undefined) {
|
|
1795
1525
|
let sql = 'SELECT * FROM edges WHERE source = ?';
|
|
1796
1526
|
const params = [sourceId];
|
|
1797
1527
|
if (kinds && kinds.length > 0) {
|
|
@@ -1803,6 +1533,10 @@ class QueryBuilder {
|
|
|
1803
1533
|
params.push(provenance);
|
|
1804
1534
|
}
|
|
1805
1535
|
sql += ' ORDER BY kind, target, line, col';
|
|
1536
|
+
if (limit !== undefined) {
|
|
1537
|
+
sql += ' LIMIT ?';
|
|
1538
|
+
params.push(Math.max(0, Math.floor(limit)));
|
|
1539
|
+
}
|
|
1806
1540
|
const rows = this.edgeKindStmt(sql).all(...params);
|
|
1807
1541
|
return rows.map(rowToEdge);
|
|
1808
1542
|
}
|
|
@@ -1812,16 +1546,20 @@ class QueryBuilder {
|
|
|
1812
1546
|
const rows = this.stmts.getEdgesBySource.all(sourceId);
|
|
1813
1547
|
return rows.map(rowToEdge);
|
|
1814
1548
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1549
|
+
getIncomingEdges(targetId, kinds, limit) {
|
|
1550
|
+
if ((kinds && kinds.length > 0) || limit !== undefined) {
|
|
1551
|
+
let sql = 'SELECT * FROM edges WHERE target = ?';
|
|
1552
|
+
const params = [targetId];
|
|
1553
|
+
if (kinds && kinds.length > 0) {
|
|
1554
|
+
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
1555
|
+
params.push(...kinds);
|
|
1556
|
+
}
|
|
1557
|
+
sql += ' ORDER BY kind, source, line, col';
|
|
1558
|
+
if (limit !== undefined) {
|
|
1559
|
+
sql += ' LIMIT ?';
|
|
1560
|
+
params.push(Math.max(0, Math.floor(limit)));
|
|
1561
|
+
}
|
|
1562
|
+
const rows = this.edgeKindStmt(sql).all(...params);
|
|
1825
1563
|
return rows.map(rowToEdge);
|
|
1826
1564
|
}
|
|
1827
1565
|
if (!this.stmts.getEdgesByTarget) {
|
|
@@ -1830,13 +1568,6 @@ class QueryBuilder {
|
|
|
1830
1568
|
const rows = this.stmts.getEdgesByTarget.all(targetId);
|
|
1831
1569
|
return rows.map(rowToEdge);
|
|
1832
1570
|
}
|
|
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
1571
|
getOutgoingEdgesFrom(sourceIds, kinds) {
|
|
1841
1572
|
if (sourceIds.length === 0)
|
|
1842
1573
|
return [];
|
|
@@ -1857,15 +1588,6 @@ class QueryBuilder {
|
|
|
1857
1588
|
}
|
|
1858
1589
|
return out;
|
|
1859
1590
|
}
|
|
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
1591
|
countIncomingEdges(ids) {
|
|
1870
1592
|
const out = new Map();
|
|
1871
1593
|
if (ids.length === 0)
|
|
@@ -1875,11 +1597,7 @@ class QueryBuilder {
|
|
|
1875
1597
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1876
1598
|
const placeholders = chunk.map(() => '?').join(',');
|
|
1877
1599
|
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})
|
|
1600
|
+
.prepare(`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders})
|
|
1883
1601
|
AND (metadata IS NULL OR metadata NOT LIKE '%"synthesizedBy":"test-request"%') GROUP BY target`)
|
|
1884
1602
|
.all(...chunk);
|
|
1885
1603
|
for (const row of rows)
|
|
@@ -1887,11 +1605,6 @@ class QueryBuilder {
|
|
|
1887
1605
|
}
|
|
1888
1606
|
return out;
|
|
1889
1607
|
}
|
|
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
1608
|
getIncomingEdgesTo(targetIds, kinds) {
|
|
1896
1609
|
if (targetIds.length === 0)
|
|
1897
1610
|
return [];
|
|
@@ -1912,11 +1625,6 @@ class QueryBuilder {
|
|
|
1912
1625
|
}
|
|
1913
1626
|
return out;
|
|
1914
1627
|
}
|
|
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
1628
|
countOutgoingEdges(ids) {
|
|
1921
1629
|
const out = new Map();
|
|
1922
1630
|
if (ids.length === 0)
|
|
@@ -1933,32 +1641,13 @@ class QueryBuilder {
|
|
|
1933
1641
|
}
|
|
1934
1642
|
return out;
|
|
1935
1643
|
}
|
|
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
1644
|
getUnreferencedNodes(kinds, limit) {
|
|
1957
1645
|
if (kinds.length === 0 || limit <= 0)
|
|
1958
1646
|
return [];
|
|
1959
1647
|
const placeholders = kinds.map(() => '?').join(',');
|
|
1648
|
+
const generated = this.hasSchema('files', 'generated') ? 'COALESCE(f.generated, 0)' : '0';
|
|
1960
1649
|
const rows = this.db
|
|
1961
|
-
.prepare(`SELECT n.*,
|
|
1650
|
+
.prepare(`SELECT n.*, ${generated} AS file_generated
|
|
1962
1651
|
FROM nodes n
|
|
1963
1652
|
LEFT JOIN files f ON f.path = n.file_path
|
|
1964
1653
|
WHERE n.kind IN (${placeholders})
|
|
@@ -1973,84 +1662,84 @@ class QueryBuilder {
|
|
|
1973
1662
|
.all(...kinds, limit);
|
|
1974
1663
|
return rows.map((row) => ({ node: rowToNode(row), generated: row.file_generated === 1 }));
|
|
1975
1664
|
}
|
|
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
1665
|
getUnresolvedNamesAmong(names) {
|
|
1992
1666
|
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
1993
1667
|
const found = new Set();
|
|
1994
1668
|
if (unique.length === 0)
|
|
1995
1669
|
return found;
|
|
1670
|
+
const parked = this.hasSchema('unresolved_refs', 'status');
|
|
1996
1671
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1997
1672
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1998
1673
|
const placeholders = chunk.map(() => '?').join(',');
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
1674
|
+
const byName = `SELECT DISTINCT reference_name AS name FROM unresolved_refs
|
|
1675
|
+
WHERE reference_name IN (${placeholders})`;
|
|
1676
|
+
const rows = (parked
|
|
1677
|
+
? this.db
|
|
1678
|
+
.prepare(`${byName}
|
|
2002
1679
|
UNION
|
|
2003
1680
|
SELECT DISTINCT name_tail AS name FROM unresolved_refs
|
|
2004
|
-
WHERE name_tail IN (${placeholders})
|
|
2005
|
-
|
|
1681
|
+
WHERE name_tail IN (${placeholders})
|
|
1682
|
+
UNION
|
|
1683
|
+
SELECT DISTINCT ${reference_tail_1.MEMBER_TAIL_SQL} AS name FROM unresolved_refs
|
|
1684
|
+
WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
|
|
1685
|
+
.all(...chunk, ...chunk, ...chunk)
|
|
1686
|
+
: this.db.prepare(byName).all(...chunk));
|
|
2006
1687
|
for (const row of rows)
|
|
2007
1688
|
found.add(row.name);
|
|
2008
1689
|
}
|
|
2009
1690
|
return found;
|
|
2010
1691
|
}
|
|
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
1692
|
getUnresolvedSupertypeSourcesAmong(nodeIds) {
|
|
1693
|
+
return new Set(this.getUnresolvedReferenceNamesFrom(nodeIds, ['extends', 'implements']).keys());
|
|
1694
|
+
}
|
|
1695
|
+
getUnresolvedReferenceNamesFrom(nodeIds, kinds) {
|
|
2019
1696
|
const unique = [...new Set(nodeIds)];
|
|
2020
|
-
const found = new
|
|
1697
|
+
const found = new Map();
|
|
1698
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
1699
|
+
return found;
|
|
1700
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
2021
1701
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2022
1702
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2023
1703
|
const placeholders = chunk.map(() => '?').join(',');
|
|
2024
1704
|
const rows = this.db
|
|
2025
|
-
.prepare(`SELECT DISTINCT from_node_id AS id FROM unresolved_refs
|
|
1705
|
+
.prepare(`SELECT DISTINCT from_node_id AS id, reference_name AS name FROM unresolved_refs
|
|
2026
1706
|
WHERE from_node_id IN (${placeholders})
|
|
2027
|
-
AND reference_kind IN (
|
|
2028
|
-
.all(...chunk);
|
|
2029
|
-
for (const row of rows)
|
|
2030
|
-
found.
|
|
1707
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
1708
|
+
.all(...chunk, ...kinds);
|
|
1709
|
+
for (const row of rows) {
|
|
1710
|
+
const names = found.get(row.id);
|
|
1711
|
+
if (names)
|
|
1712
|
+
names.push(row.name);
|
|
1713
|
+
else
|
|
1714
|
+
found.set(row.id, [row.name]);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
return found;
|
|
1718
|
+
}
|
|
1719
|
+
getUnresolvedReferenceSourcesNamed(names, kinds) {
|
|
1720
|
+
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
1721
|
+
const found = new Map();
|
|
1722
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
1723
|
+
return found;
|
|
1724
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
1725
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1726
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1727
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1728
|
+
const rows = this.db
|
|
1729
|
+
.prepare(`SELECT DISTINCT reference_name AS name, from_node_id AS id FROM unresolved_refs
|
|
1730
|
+
WHERE reference_name IN (${placeholders})
|
|
1731
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
1732
|
+
.all(...chunk, ...kinds);
|
|
1733
|
+
for (const row of rows) {
|
|
1734
|
+
const ids = found.get(row.name);
|
|
1735
|
+
if (ids)
|
|
1736
|
+
ids.add(row.id);
|
|
1737
|
+
else
|
|
1738
|
+
found.set(row.name, new Set([row.id]));
|
|
1739
|
+
}
|
|
2031
1740
|
}
|
|
2032
1741
|
return found;
|
|
2033
1742
|
}
|
|
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
1743
|
getAmbiguousReferencedNames(names) {
|
|
2055
1744
|
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
2056
1745
|
const found = new Set();
|
|
@@ -2077,22 +1766,6 @@ class QueryBuilder {
|
|
|
2077
1766
|
}
|
|
2078
1767
|
return found;
|
|
2079
1768
|
}
|
|
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
1769
|
getLanguagesWithExports(languages) {
|
|
2097
1770
|
const unique = [...new Set(languages)].filter((language) => language.length > 0);
|
|
2098
1771
|
const found = new Set();
|
|
@@ -2113,17 +1786,6 @@ class QueryBuilder {
|
|
|
2113
1786
|
}
|
|
2114
1787
|
return found;
|
|
2115
1788
|
}
|
|
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
1789
|
getTopDependedOn(limit) {
|
|
2128
1790
|
if (limit <= 0)
|
|
2129
1791
|
return [];
|
|
@@ -2137,30 +1799,6 @@ class QueryBuilder {
|
|
|
2137
1799
|
.all(limit);
|
|
2138
1800
|
return rows;
|
|
2139
1801
|
}
|
|
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
1802
|
getTopCallingFiles(limit) {
|
|
2165
1803
|
if (limit <= 0)
|
|
2166
1804
|
return [];
|
|
@@ -2209,15 +1847,6 @@ class QueryBuilder {
|
|
|
2209
1847
|
LIMIT ?`)
|
|
2210
1848
|
.all(limit);
|
|
2211
1849
|
}
|
|
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
1850
|
getFileDependentCounts(filePaths) {
|
|
2222
1851
|
if (filePaths.length === 0)
|
|
2223
1852
|
return [];
|
|
@@ -2232,17 +1861,6 @@ class QueryBuilder {
|
|
|
2232
1861
|
GROUP BY tn.file_path`)
|
|
2233
1862
|
.all(JSON.stringify(filePaths));
|
|
2234
1863
|
}
|
|
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
1864
|
getFileReachCounts(filePaths) {
|
|
2247
1865
|
if (filePaths.length === 0)
|
|
2248
1866
|
return [];
|
|
@@ -2259,13 +1877,6 @@ class QueryBuilder {
|
|
|
2259
1877
|
GROUP BY sn.file_path`)
|
|
2260
1878
|
.all(JSON.stringify(filePaths));
|
|
2261
1879
|
}
|
|
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
1880
|
getFileNodes(filePaths) {
|
|
2270
1881
|
if (filePaths.length === 0)
|
|
2271
1882
|
return [];
|
|
@@ -2276,39 +1887,6 @@ class QueryBuilder {
|
|
|
2276
1887
|
.all(JSON.stringify(filePaths));
|
|
2277
1888
|
return rows.map(rowToNode);
|
|
2278
1889
|
}
|
|
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
1890
|
aggregateModuleGraph(assignments, options) {
|
|
2313
1891
|
if (assignments.length === 0 || options.kinds.length === 0)
|
|
2314
1892
|
return { links: [], pairs: [] };
|
|
@@ -2331,13 +1909,6 @@ class QueryBuilder {
|
|
|
2331
1909
|
this.db.exec('ROLLBACK');
|
|
2332
1910
|
throw err;
|
|
2333
1911
|
}
|
|
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
1912
|
const rows = this.db
|
|
2342
1913
|
.prepare(`SELECT ms.mod AS source, mt.mod AS target, e.kind AS kind,
|
|
2343
1914
|
sn.name AS "from", tn.name AS "to",
|
|
@@ -2359,20 +1930,6 @@ class QueryBuilder {
|
|
|
2359
1930
|
this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
|
|
2360
1931
|
}
|
|
2361
1932
|
}
|
|
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
1933
|
getCrossFileDependencyPairs(minConfidence) {
|
|
2377
1934
|
return this.db
|
|
2378
1935
|
.prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
|
|
@@ -2384,20 +1941,16 @@ class QueryBuilder {
|
|
|
2384
1941
|
AND COALESCE(json_extract(e.metadata, '$.confidence'), 1) >= ?`)
|
|
2385
1942
|
.all(minConfidence);
|
|
2386
1943
|
}
|
|
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
|
-
*/
|
|
1944
|
+
getFileImportPairs() {
|
|
1945
|
+
return this.db
|
|
1946
|
+
.prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
|
|
1947
|
+
FROM edges e
|
|
1948
|
+
JOIN nodes sn ON sn.id = e.source
|
|
1949
|
+
JOIN nodes tn ON tn.id = e.target
|
|
1950
|
+
WHERE e.kind = 'imports'
|
|
1951
|
+
AND sn.file_path <> tn.file_path`)
|
|
1952
|
+
.all();
|
|
1953
|
+
}
|
|
2401
1954
|
getUnresolvedReferencesInFile(filePath, limit = 5000) {
|
|
2402
1955
|
if (!this.stmts.getUnresolvedInFile) {
|
|
2403
1956
|
this.stmts.getUnresolvedInFile = this.db.prepare('SELECT * FROM unresolved_refs WHERE file_path = ? ORDER BY line, col LIMIT ?');
|
|
@@ -2415,15 +1968,6 @@ class QueryBuilder {
|
|
|
2415
1968
|
rowId: row.id,
|
|
2416
1969
|
}));
|
|
2417
1970
|
}
|
|
2418
|
-
/**
|
|
2419
|
-
* References recorded against a symbol that never resolved to a node — the
|
|
2420
|
-
* calls and type mentions that leave the index (a third-party package, a
|
|
2421
|
-
* runtime builtin, a language construct extraction doesn't model).
|
|
2422
|
-
*
|
|
2423
|
-
* Read-only. It exists so a reader can say "N calls into symbols outside the
|
|
2424
|
-
* index" instead of silently showing a callee list shorter than the body's
|
|
2425
|
-
* call sites, which reads as "nothing else happens here".
|
|
2426
|
-
*/
|
|
2427
1971
|
getUnresolvedReferencesFrom(fromNodeId) {
|
|
2428
1972
|
if (!this.stmts.getUnresolvedFromNode) {
|
|
2429
1973
|
this.stmts.getUnresolvedFromNode = this.db.prepare('SELECT * FROM unresolved_refs WHERE from_node_id = ?');
|
|
@@ -2441,10 +1985,35 @@ class QueryBuilder {
|
|
|
2441
1985
|
rowId: row.id,
|
|
2442
1986
|
}));
|
|
2443
1987
|
}
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
1988
|
+
getUnresolvedReferencesFromNodes(nodeIds, kinds) {
|
|
1989
|
+
const unique = [...new Set(nodeIds)];
|
|
1990
|
+
const found = [];
|
|
1991
|
+
if (unique.length === 0 || kinds.length === 0)
|
|
1992
|
+
return found;
|
|
1993
|
+
const kindPlaceholders = kinds.map(() => '?').join(',');
|
|
1994
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1995
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1996
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1997
|
+
const rows = this.db
|
|
1998
|
+
.prepare(`SELECT * FROM unresolved_refs
|
|
1999
|
+
WHERE from_node_id IN (${placeholders})
|
|
2000
|
+
AND reference_kind IN (${kindPlaceholders})`)
|
|
2001
|
+
.all(...chunk, ...kinds);
|
|
2002
|
+
for (const row of rows) {
|
|
2003
|
+
found.push({
|
|
2004
|
+
fromNodeId: row.from_node_id,
|
|
2005
|
+
referenceName: row.reference_name,
|
|
2006
|
+
referenceKind: row.reference_kind,
|
|
2007
|
+
line: row.line,
|
|
2008
|
+
column: row.col,
|
|
2009
|
+
filePath: row.file_path,
|
|
2010
|
+
language: row.language,
|
|
2011
|
+
rowId: row.id,
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
return found;
|
|
2016
|
+
}
|
|
2448
2017
|
findEdgesBetweenNodes(nodeIds, kinds) {
|
|
2449
2018
|
if (nodeIds.length === 0)
|
|
2450
2019
|
return [];
|
|
@@ -2458,22 +2027,6 @@ class QueryBuilder {
|
|
|
2458
2027
|
const rows = this.db.prepare(sql).all(...params);
|
|
2459
2028
|
return rows.map(rowToEdge);
|
|
2460
2029
|
}
|
|
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
2030
|
getDependentFilePaths(filePath) {
|
|
2478
2031
|
const sql = `SELECT DISTINCT src.file_path AS fp
|
|
2479
2032
|
FROM edges e
|
|
@@ -2485,12 +2038,6 @@ class QueryBuilder {
|
|
|
2485
2038
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2486
2039
|
return rows.map((r) => r.fp);
|
|
2487
2040
|
}
|
|
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
2041
|
getDependencyFilePaths(filePath) {
|
|
2495
2042
|
const sql = `SELECT DISTINCT tgt.file_path AS fp
|
|
2496
2043
|
FROM edges e
|
|
@@ -2502,17 +2049,6 @@ class QueryBuilder {
|
|
|
2502
2049
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2503
2050
|
return rows.map((r) => r.fp);
|
|
2504
2051
|
}
|
|
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
2052
|
getCrossFileIncomingEdgesWithTarget(filePath) {
|
|
2517
2053
|
const sql = `SELECT e.*, tgt.name AS target_name, tgt.kind AS target_kind,
|
|
2518
2054
|
src.file_path AS source_file_path, src.language AS source_language
|
|
@@ -2525,18 +2061,216 @@ class QueryBuilder {
|
|
|
2525
2061
|
const rows = this.db.prepare(sql).all(filePath, filePath);
|
|
2526
2062
|
return rows.map(row => ({
|
|
2527
2063
|
...rowToEdge(row),
|
|
2064
|
+
edgeId: row.id,
|
|
2528
2065
|
targetName: row.target_name,
|
|
2529
2066
|
targetKind: row.target_kind,
|
|
2530
2067
|
sourceFilePath: row.source_file_path,
|
|
2531
2068
|
sourceLanguage: row.source_language,
|
|
2532
2069
|
}));
|
|
2533
2070
|
}
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2071
|
+
getResolutionEdgesThrough(filePath, names) {
|
|
2072
|
+
const rows = this.db
|
|
2073
|
+
.prepare(`SELECT * FROM (
|
|
2074
|
+
SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path,
|
|
2075
|
+
CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
|
|
2076
|
+
FROM nodes src
|
|
2077
|
+
JOIN edges e ON e.source = src.id
|
|
2078
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2079
|
+
WHERE src.file_path = ?
|
|
2080
|
+
AND e.kind != 'contains'
|
|
2081
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2082
|
+
) WHERE ${THROUGH_NAMES('ref_name')}`)
|
|
2083
|
+
.all(filePath, JSON.stringify(names), JSON.stringify(names));
|
|
2084
|
+
return rows.map((row) => ({
|
|
2085
|
+
...rowToEdge(row),
|
|
2086
|
+
edgeId: row.id,
|
|
2087
|
+
sourceFilePath: row.source_file_path,
|
|
2088
|
+
sourceLanguage: row.source_language,
|
|
2089
|
+
targetFilePath: row.target_file_path,
|
|
2090
|
+
}));
|
|
2091
|
+
}
|
|
2092
|
+
getImportBindingsResolvedElsewhere(filePaths) {
|
|
2093
|
+
const out = [];
|
|
2094
|
+
const unique = [...new Set(filePaths)].map((filePath) => `file:${filePath}`);
|
|
2095
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2096
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2097
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2098
|
+
const rows = this.db
|
|
2099
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
|
|
2100
|
+
FROM edges e
|
|
2101
|
+
JOIN nodes src ON src.id = e.source
|
|
2102
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2103
|
+
WHERE e.source IN (${placeholders})
|
|
2104
|
+
AND e.kind = 'imports'
|
|
2105
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2106
|
+
AND json_valid(e.metadata)
|
|
2107
|
+
AND json_extract(e.metadata, '$.resolvedBy') != 'import'`)
|
|
2108
|
+
.all(...chunk);
|
|
2109
|
+
for (const row of rows) {
|
|
2110
|
+
out.push({
|
|
2111
|
+
...rowToEdge(row),
|
|
2112
|
+
edgeId: row.id,
|
|
2113
|
+
sourceFilePath: row.source_file_path,
|
|
2114
|
+
sourceLanguage: row.source_language,
|
|
2115
|
+
targetFilePath: row.target_file_path,
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return out;
|
|
2120
|
+
}
|
|
2121
|
+
getResolutionEdgesInto(targetIds) {
|
|
2122
|
+
const out = [];
|
|
2123
|
+
const unique = [...new Set(targetIds)];
|
|
2124
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2125
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2126
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2127
|
+
const rows = this.db
|
|
2128
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
|
|
2129
|
+
FROM edges e
|
|
2130
|
+
JOIN nodes src ON src.id = e.source
|
|
2131
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2132
|
+
WHERE e.target IN (${placeholders})
|
|
2133
|
+
AND e.kind != 'contains'
|
|
2134
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2135
|
+
.all(...chunk);
|
|
2136
|
+
for (const row of rows) {
|
|
2137
|
+
out.push({
|
|
2138
|
+
...rowToEdge(row),
|
|
2139
|
+
edgeId: row.id,
|
|
2140
|
+
sourceFilePath: row.source_file_path,
|
|
2141
|
+
sourceLanguage: row.source_language,
|
|
2142
|
+
targetFilePath: row.target_file_path,
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
return out;
|
|
2147
|
+
}
|
|
2148
|
+
getFailedReferencesThrough(filePath, modules, names) {
|
|
2149
|
+
return this.db
|
|
2150
|
+
.prepare(`SELECT id FROM unresolved_refs
|
|
2151
|
+
WHERE file_path = ? AND status = 'failed'
|
|
2152
|
+
AND ((reference_kind = 'imports' AND reference_name IN (SELECT value FROM json_each(?)))
|
|
2153
|
+
OR ${THROUGH_NAMES('reference_name')})`)
|
|
2154
|
+
.all(filePath, JSON.stringify(modules), JSON.stringify(names), JSON.stringify(names))
|
|
2155
|
+
.map((row) => row.id);
|
|
2156
|
+
}
|
|
2157
|
+
getImportTargetsFromFile(filePath) {
|
|
2158
|
+
return this.db
|
|
2159
|
+
.prepare(`SELECT DISTINCT e.target AS target
|
|
2160
|
+
FROM nodes src
|
|
2161
|
+
JOIN edges e ON e.source = src.id
|
|
2162
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2163
|
+
WHERE src.file_path = ?
|
|
2164
|
+
AND e.kind = 'imports'
|
|
2165
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2166
|
+
AND tgt.file_path != ?`)
|
|
2167
|
+
.all(filePath, filePath)
|
|
2168
|
+
.map((row) => row.target);
|
|
2169
|
+
}
|
|
2170
|
+
getImportsInto(targetId, exceptFile) {
|
|
2171
|
+
return this.db
|
|
2172
|
+
.prepare(`SELECT src.file_path AS file_path, src.language AS language,
|
|
2173
|
+
CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
|
|
2174
|
+
FROM edges e
|
|
2175
|
+
JOIN nodes src ON src.id = e.source
|
|
2176
|
+
WHERE e.target = ? AND e.kind = 'imports' AND src.file_path != ?`)
|
|
2177
|
+
.all(targetId, exceptFile)
|
|
2178
|
+
.map((row) => ({
|
|
2179
|
+
filePath: row.file_path,
|
|
2180
|
+
language: row.language,
|
|
2181
|
+
refName: typeof row.ref_name === 'string' ? row.ref_name : null,
|
|
2182
|
+
}));
|
|
2183
|
+
}
|
|
2184
|
+
getModuleImportsUnder(dir) {
|
|
2185
|
+
const rows = this.db
|
|
2186
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2187
|
+
FROM nodes tgt
|
|
2188
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2189
|
+
JOIN nodes src ON src.id = e.source
|
|
2190
|
+
WHERE tgt.kind = 'file' AND tgt.file_path >= ? AND tgt.file_path < ?`)
|
|
2191
|
+
.all(`${dir}/`, `${dir}0`);
|
|
2192
|
+
return rows.map((row) => ({
|
|
2193
|
+
...rowToEdge(row),
|
|
2194
|
+
edgeId: row.id,
|
|
2195
|
+
targetFilePath: row.target_file_path,
|
|
2196
|
+
sourceFilePath: row.source_file_path,
|
|
2197
|
+
sourceLanguage: row.source_language,
|
|
2198
|
+
}));
|
|
2199
|
+
}
|
|
2200
|
+
getModuleImportsIntoDeclarationFiles() {
|
|
2201
|
+
const rows = this.db
|
|
2202
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2203
|
+
FROM nodes tgt
|
|
2204
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2205
|
+
JOIN nodes src ON src.id = e.source
|
|
2206
|
+
WHERE tgt.kind = 'file'
|
|
2207
|
+
AND (tgt.file_path LIKE '%.d.ts' OR tgt.file_path LIKE '%.d.mts' OR tgt.file_path LIKE '%.d.cts')`)
|
|
2208
|
+
.all();
|
|
2209
|
+
return rows.map((row) => ({
|
|
2210
|
+
...rowToEdge(row),
|
|
2211
|
+
edgeId: row.id,
|
|
2212
|
+
targetFilePath: row.target_file_path,
|
|
2213
|
+
sourceFilePath: row.source_file_path,
|
|
2214
|
+
sourceLanguage: row.source_language,
|
|
2215
|
+
}));
|
|
2216
|
+
}
|
|
2217
|
+
getModuleImportsNamed(dir, name) {
|
|
2218
|
+
const base = dir ? `${dir}/${name}` : name;
|
|
2219
|
+
const rows = this.db
|
|
2220
|
+
.prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
|
|
2221
|
+
FROM nodes tgt
|
|
2222
|
+
JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
|
|
2223
|
+
JOIN nodes src ON src.id = e.source
|
|
2224
|
+
WHERE tgt.kind = 'file'
|
|
2225
|
+
AND ((tgt.file_path >= ? AND tgt.file_path < ?) OR (tgt.file_path >= ? AND tgt.file_path < ?) OR tgt.file_path = ?)`)
|
|
2226
|
+
.all(`${base}.`, `${base}/`, `${base}/index.`, `${base}/index/`, `${base}/__init__.py`);
|
|
2227
|
+
return rows
|
|
2228
|
+
.filter((row) => {
|
|
2229
|
+
const file = row.target_file_path;
|
|
2230
|
+
if (file === `${base}/__init__.py`)
|
|
2231
|
+
return true;
|
|
2232
|
+
const index = `${base}/index.`;
|
|
2233
|
+
return !(file.startsWith(index) ? file.slice(index.length) : file.slice(base.length + 1)).includes('/');
|
|
2234
|
+
})
|
|
2235
|
+
.map((row) => ({
|
|
2236
|
+
...rowToEdge(row),
|
|
2237
|
+
edgeId: row.id,
|
|
2238
|
+
targetFilePath: row.target_file_path,
|
|
2239
|
+
sourceFilePath: row.source_file_path,
|
|
2240
|
+
sourceLanguage: row.source_language,
|
|
2241
|
+
}));
|
|
2242
|
+
}
|
|
2243
|
+
getFilesWithEdgesInto(targetIds) {
|
|
2244
|
+
const files = new Set();
|
|
2245
|
+
for (let i = 0; i < targetIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2246
|
+
const chunk = targetIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2247
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2248
|
+
const rows = this.db
|
|
2249
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
2250
|
+
FROM edges e
|
|
2251
|
+
JOIN nodes src ON src.id = e.source
|
|
2252
|
+
WHERE e.target IN (${placeholders})
|
|
2253
|
+
AND e.kind != 'contains'
|
|
2254
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2255
|
+
.all(...chunk);
|
|
2256
|
+
for (const row of rows)
|
|
2257
|
+
files.add(row.file_path);
|
|
2258
|
+
}
|
|
2259
|
+
return [...files];
|
|
2260
|
+
}
|
|
2261
|
+
getImportNodesByNames(names) {
|
|
2262
|
+
const out = [];
|
|
2263
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2264
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2265
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2266
|
+
const rows = this.db
|
|
2267
|
+
.prepare(`SELECT file_path, name, language FROM nodes WHERE name IN (${placeholders}) AND kind = 'import'`)
|
|
2268
|
+
.all(...chunk);
|
|
2269
|
+
for (const row of rows)
|
|
2270
|
+
out.push({ filePath: row.file_path, name: row.name, language: row.language });
|
|
2271
|
+
}
|
|
2272
|
+
return out;
|
|
2273
|
+
}
|
|
2540
2274
|
upsertFile(file) {
|
|
2541
2275
|
if (!this.stmts.upsertFile) {
|
|
2542
2276
|
this.stmts.upsertFile = this.db.prepare(`
|
|
@@ -2562,29 +2296,16 @@ class QueryBuilder {
|
|
|
2562
2296
|
indexedAt: file.indexedAt,
|
|
2563
2297
|
nodeCount: file.nodeCount,
|
|
2564
2298
|
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
2299
|
generated: file.generated ? 1 : 0,
|
|
2568
2300
|
});
|
|
2569
2301
|
}
|
|
2570
|
-
/**
|
|
2571
|
-
* Which of `filePaths` the index flagged as tool-generated (schema v9+).
|
|
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
2302
|
getGeneratedPathsAmong(filePaths) {
|
|
2584
2303
|
const unique = [...new Set(filePaths)];
|
|
2585
2304
|
const found = new Set();
|
|
2586
2305
|
if (unique.length === 0)
|
|
2587
2306
|
return found;
|
|
2307
|
+
if (!this.hasSchema('files', 'generated'))
|
|
2308
|
+
return found;
|
|
2588
2309
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2589
2310
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2590
2311
|
const placeholders = chunk.map(() => '?').join(',');
|
|
@@ -2596,70 +2317,10 @@ class QueryBuilder {
|
|
|
2596
2317
|
}
|
|
2597
2318
|
return found;
|
|
2598
2319
|
}
|
|
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
2320
|
generatedPredicateFor(filePaths) {
|
|
2605
2321
|
const flagged = this.getGeneratedPathsAmong(filePaths);
|
|
2606
2322
|
return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
2607
2323
|
}
|
|
2608
|
-
/**
|
|
2609
|
-
* Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing
|
|
2610
|
-
* but types, and nothing in the index depends on them (CG-28). A hand-written
|
|
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
2324
|
getAmbientDeclarationPathsAmong(filePaths) {
|
|
2664
2325
|
const unique = [...new Set(filePaths)];
|
|
2665
2326
|
const found = new Set();
|
|
@@ -2668,8 +2329,6 @@ class QueryBuilder {
|
|
|
2668
2329
|
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2669
2330
|
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2670
2331
|
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
2332
|
const rows = this.db
|
|
2674
2333
|
.prepare(`
|
|
2675
2334
|
SELECT n.file_path AS file_path,
|
|
@@ -2696,17 +2355,12 @@ class QueryBuilder {
|
|
|
2696
2355
|
.all(...candidates).map((r) => r.file_path));
|
|
2697
2356
|
candidates = candidates.filter((p) => !hit.has(p));
|
|
2698
2357
|
};
|
|
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
2358
|
disqualify(`
|
|
2702
2359
|
SELECT DISTINCT n.file_path AS file_path
|
|
2703
2360
|
FROM edges e JOIN nodes n ON n.id = e.source
|
|
2704
2361
|
WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
|
|
2705
2362
|
AND NOT ${IS_INTERFACE_MEMBER('n')}
|
|
2706
2363
|
`);
|
|
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
2364
|
disqualify(`
|
|
2711
2365
|
SELECT DISTINCT t.file_path AS file_path
|
|
2712
2366
|
FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
|
|
@@ -2718,25 +2372,18 @@ class QueryBuilder {
|
|
|
2718
2372
|
}
|
|
2719
2373
|
return found;
|
|
2720
2374
|
}
|
|
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
2375
|
ambientDeclarationPredicateFor(filePaths) {
|
|
2727
2376
|
const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
|
|
2728
2377
|
return (filePath) => flagged.has(filePath);
|
|
2729
2378
|
}
|
|
2730
|
-
/** How many indexed files carry the generated flag. Surfaced by `status`. */
|
|
2731
2379
|
countGeneratedFiles() {
|
|
2380
|
+
if (!this.hasSchema('files', 'generated'))
|
|
2381
|
+
return 0;
|
|
2732
2382
|
const row = this.db
|
|
2733
2383
|
.prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
|
|
2734
2384
|
.get();
|
|
2735
2385
|
return row?.n ?? 0;
|
|
2736
2386
|
}
|
|
2737
|
-
/**
|
|
2738
|
-
* Delete a file record and its nodes
|
|
2739
|
-
*/
|
|
2740
2387
|
deleteFile(filePath) {
|
|
2741
2388
|
this.db.transaction(() => {
|
|
2742
2389
|
this.deleteNodesByFile(filePath);
|
|
@@ -2746,9 +2393,6 @@ class QueryBuilder {
|
|
|
2746
2393
|
this.stmts.deleteFile.run(filePath);
|
|
2747
2394
|
})();
|
|
2748
2395
|
}
|
|
2749
|
-
/**
|
|
2750
|
-
* Get a file record by path
|
|
2751
|
-
*/
|
|
2752
2396
|
getFileByPath(filePath) {
|
|
2753
2397
|
if (!this.stmts.getFileByPath) {
|
|
2754
2398
|
this.stmts.getFileByPath = this.db.prepare('SELECT * FROM files WHERE path = ?');
|
|
@@ -2756,20 +2400,12 @@ class QueryBuilder {
|
|
|
2756
2400
|
const row = this.stmts.getFileByPath.get(filePath);
|
|
2757
2401
|
return row ? rowToFileRecord(row) : null;
|
|
2758
2402
|
}
|
|
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
2403
|
hasFilesUnder(dir) {
|
|
2765
2404
|
if (!this.stmts.hasFilesUnder) {
|
|
2766
2405
|
this.stmts.hasFilesUnder = this.db.prepare('SELECT 1 FROM files WHERE path >= ? AND path < ? LIMIT 1');
|
|
2767
2406
|
}
|
|
2768
2407
|
return this.stmts.hasFilesUnder.get(`${dir}/`, `${dir}0`) !== undefined;
|
|
2769
2408
|
}
|
|
2770
|
-
/**
|
|
2771
|
-
* Get all tracked files
|
|
2772
|
-
*/
|
|
2773
2409
|
getAllFiles() {
|
|
2774
2410
|
if (!this.stmts.getAllFiles) {
|
|
2775
2411
|
this.stmts.getAllFiles = this.db.prepare('SELECT * FROM files ORDER BY path');
|
|
@@ -2777,41 +2413,24 @@ class QueryBuilder {
|
|
|
2777
2413
|
const rows = this.stmts.getAllFiles.all();
|
|
2778
2414
|
return rows.map(rowToFileRecord);
|
|
2779
2415
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2416
|
+
getFilesWithoutNodesOrWithErrors() {
|
|
2417
|
+
const rows = this.db
|
|
2418
|
+
.prepare('SELECT * FROM files WHERE node_count = 0 OR errors IS NOT NULL ORDER BY path')
|
|
2419
|
+
.all();
|
|
2420
|
+
return rows.map(rowToFileRecord);
|
|
2421
|
+
}
|
|
2784
2422
|
getLastIndexedAt() {
|
|
2785
2423
|
const row = this.db
|
|
2786
2424
|
.prepare('SELECT MAX(indexed_at) AS last FROM files')
|
|
2787
2425
|
.get();
|
|
2788
2426
|
return row?.last ?? null;
|
|
2789
2427
|
}
|
|
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
2428
|
getIndexRevision() {
|
|
2801
2429
|
const row = this.db
|
|
2802
2430
|
.prepare('SELECT MAX(indexed_at) AS last, COUNT(*) AS files FROM files')
|
|
2803
2431
|
.get();
|
|
2804
2432
|
return { lastIndexedAt: row?.last ?? null, fileCount: row?.files ?? 0 };
|
|
2805
2433
|
}
|
|
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
2434
|
getFilesIndexedSince(since, limit) {
|
|
2816
2435
|
const count = this.db
|
|
2817
2436
|
.prepare('SELECT COUNT(*) AS n FROM files WHERE indexed_at > ?')
|
|
@@ -2821,9 +2440,6 @@ class QueryBuilder {
|
|
|
2821
2440
|
.all(since, Math.max(0, limit));
|
|
2822
2441
|
return { paths: rows.map((r) => r.path), total: count?.n ?? rows.length };
|
|
2823
2442
|
}
|
|
2824
|
-
/**
|
|
2825
|
-
* Get files that need re-indexing (hash changed)
|
|
2826
|
-
*/
|
|
2827
2443
|
getStaleFiles(currentHashes) {
|
|
2828
2444
|
const files = this.getAllFiles();
|
|
2829
2445
|
return files.filter((f) => {
|
|
@@ -2831,12 +2447,6 @@ class QueryBuilder {
|
|
|
2831
2447
|
return currentHash && currentHash !== f.contentHash;
|
|
2832
2448
|
});
|
|
2833
2449
|
}
|
|
2834
|
-
// ===========================================================================
|
|
2835
|
-
// Unresolved References
|
|
2836
|
-
// ===========================================================================
|
|
2837
|
-
/**
|
|
2838
|
-
* Insert an unresolved reference
|
|
2839
|
-
*/
|
|
2840
2450
|
insertUnresolvedRef(ref) {
|
|
2841
2451
|
if (!this.stmts.insertUnresolved) {
|
|
2842
2452
|
this.stmts.insertUnresolved = this.db.prepare(`
|
|
@@ -2855,9 +2465,6 @@ class QueryBuilder {
|
|
|
2855
2465
|
language: ref.language ?? 'unknown',
|
|
2856
2466
|
});
|
|
2857
2467
|
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Insert multiple unresolved references in a transaction
|
|
2860
|
-
*/
|
|
2861
2468
|
insertUnresolvedRefsBatch(refs) {
|
|
2862
2469
|
if (refs.length === 0)
|
|
2863
2470
|
return;
|
|
@@ -2879,18 +2486,12 @@ class QueryBuilder {
|
|
|
2879
2486
|
});
|
|
2880
2487
|
insert();
|
|
2881
2488
|
}
|
|
2882
|
-
/**
|
|
2883
|
-
* Delete unresolved references from a node
|
|
2884
|
-
*/
|
|
2885
2489
|
deleteUnresolvedByNode(nodeId) {
|
|
2886
2490
|
if (!this.stmts.deleteUnresolvedByNode) {
|
|
2887
2491
|
this.stmts.deleteUnresolvedByNode = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ?');
|
|
2888
2492
|
}
|
|
2889
2493
|
this.stmts.deleteUnresolvedByNode.run(nodeId);
|
|
2890
2494
|
}
|
|
2891
|
-
/**
|
|
2892
|
-
* Get unresolved references by name (for resolution)
|
|
2893
|
-
*/
|
|
2894
2495
|
getUnresolvedByName(name) {
|
|
2895
2496
|
if (!this.stmts.getUnresolvedByName) {
|
|
2896
2497
|
this.stmts.getUnresolvedByName = this.db.prepare('SELECT * FROM unresolved_refs WHERE reference_name = ?');
|
|
@@ -2908,9 +2509,6 @@ class QueryBuilder {
|
|
|
2908
2509
|
rowId: row.id,
|
|
2909
2510
|
}));
|
|
2910
2511
|
}
|
|
2911
|
-
/**
|
|
2912
|
-
* Get all unresolved references
|
|
2913
|
-
*/
|
|
2914
2512
|
getUnresolvedReferences() {
|
|
2915
2513
|
const rows = this.db.prepare('SELECT * FROM unresolved_refs').all();
|
|
2916
2514
|
return rows.map((row) => ({
|
|
@@ -2925,33 +2523,42 @@ class QueryBuilder {
|
|
|
2925
2523
|
rowId: row.id,
|
|
2926
2524
|
}));
|
|
2927
2525
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2526
|
+
getCppIncludeEdges() {
|
|
2527
|
+
return this.db.prepare(`SELECT s.file_path AS source, t.file_path AS target FROM edges e
|
|
2528
|
+
JOIN nodes s ON s.id = e.source JOIN nodes t ON t.id = e.target
|
|
2529
|
+
WHERE e.kind = 'imports' AND s.kind = 'file' AND t.kind = 'file' AND s.language IN ('c', 'cpp')`).all();
|
|
2530
|
+
}
|
|
2531
|
+
*iterateFailedCppTypeReferences(files) {
|
|
2532
|
+
const rows = this.db.prepare(`SELECT from_node_id, reference_name, reference_kind, line, col, file_path FROM unresolved_refs
|
|
2533
|
+
WHERE +status = 'failed' AND language = 'cpp' AND file_path IN (SELECT value FROM json_each(?))
|
|
2534
|
+
AND (reference_kind = 'instantiates'
|
|
2535
|
+
OR (reference_kind IN ('calls', 'function_ref') AND reference_name GLOB '*::*' AND reference_name NOT GLOB 'std::*')
|
|
2536
|
+
OR (reference_kind = 'calls' AND reference_name GLOB '*.*' AND reference_name NOT GLOB '*(*'))`).iterate(JSON.stringify(files));
|
|
2537
|
+
for (const row of rows) {
|
|
2538
|
+
yield {
|
|
2539
|
+
fromNodeId: row.from_node_id,
|
|
2540
|
+
referenceName: row.reference_name,
|
|
2541
|
+
referenceKind: row.reference_kind,
|
|
2542
|
+
line: row.line,
|
|
2543
|
+
column: row.col,
|
|
2544
|
+
filePath: row.file_path,
|
|
2545
|
+
language: 'cpp',
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
this.db.exec('PRAGMA shrink_memory');
|
|
2549
|
+
}
|
|
2935
2550
|
getUnresolvedReferencesCount() {
|
|
2936
2551
|
if (!this.stmts.getUnresolvedCount) {
|
|
2552
|
+
if (!this.hasSchema('unresolved_refs', 'status')) {
|
|
2553
|
+
return this.db.prepare('SELECT COUNT(*) as count FROM unresolved_refs').get().count;
|
|
2554
|
+
}
|
|
2937
2555
|
this.stmts.getUnresolvedCount = this.db.prepare("SELECT COUNT(*) as count FROM unresolved_refs WHERE status = 'pending'");
|
|
2938
2556
|
}
|
|
2939
2557
|
const row = this.stmts.getUnresolvedCount.get();
|
|
2940
2558
|
return row.count;
|
|
2941
2559
|
}
|
|
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
2560
|
getUnresolvedReferencesBatch(offset, limit) {
|
|
2949
2561
|
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
2562
|
this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
|
|
2956
2563
|
}
|
|
2957
2564
|
const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
|
|
@@ -2967,19 +2574,7 @@ class QueryBuilder {
|
|
|
2967
2574
|
rowId: row.id,
|
|
2968
2575
|
}));
|
|
2969
2576
|
}
|
|
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
2577
|
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
2578
|
const key = prerequisites === undefined ? 'getUnresolvedBatchAfter'
|
|
2984
2579
|
: prerequisites ? 'getUnresolvedPrerequisitesAfter' : 'getUnresolvedDependentsAfter';
|
|
2985
2580
|
if (!this.stmts[key]) {
|
|
@@ -3000,9 +2595,6 @@ class QueryBuilder {
|
|
|
3000
2595
|
rowId: row.id,
|
|
3001
2596
|
}));
|
|
3002
2597
|
}
|
|
3003
|
-
/**
|
|
3004
|
-
* Get all tracked file paths (lightweight — no full FileRecord objects)
|
|
3005
|
-
*/
|
|
3006
2598
|
getAllFilePaths() {
|
|
3007
2599
|
if (!this.stmts.getAllFilePaths) {
|
|
3008
2600
|
this.stmts.getAllFilePaths = this.db.prepare('SELECT path FROM files ORDER BY path');
|
|
@@ -3010,9 +2602,6 @@ class QueryBuilder {
|
|
|
3010
2602
|
const rows = this.stmts.getAllFilePaths.all();
|
|
3011
2603
|
return rows.map((r) => r.path);
|
|
3012
2604
|
}
|
|
3013
|
-
/**
|
|
3014
|
-
* Get all distinct node names (lightweight — just name strings for pre-filtering)
|
|
3015
|
-
*/
|
|
3016
2605
|
getAllNodeNames() {
|
|
3017
2606
|
if (!this.stmts.getAllNodeNames) {
|
|
3018
2607
|
this.stmts.getAllNodeNames = this.db.prepare('SELECT DISTINCT name FROM nodes');
|
|
@@ -3020,29 +2609,70 @@ class QueryBuilder {
|
|
|
3020
2609
|
const rows = this.stmts.getAllNodeNames.all();
|
|
3021
2610
|
return rows.map((r) => r.name);
|
|
3022
2611
|
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
2612
|
+
fuzzyNames() {
|
|
2613
|
+
const read = () => {
|
|
2614
|
+
const names = this.getAllNodeNames();
|
|
2615
|
+
const lowered = names.map((name) => name.toLowerCase());
|
|
2616
|
+
const starts = new Int32Array(names.length + 1);
|
|
2617
|
+
for (let i = 0; i < lowered.length; i++)
|
|
2618
|
+
starts[i + 1] = starts[i] + lowered[i].length + 1;
|
|
2619
|
+
return { names, lowered: lowered.join('\n') + '\n', starts };
|
|
2620
|
+
};
|
|
2621
|
+
return this.memoizedRead('fuzzyNames', read) ?? read();
|
|
2622
|
+
}
|
|
2623
|
+
loweredNodePaths() {
|
|
2624
|
+
const read = () => {
|
|
2625
|
+
const rows = this.db.prepare('SELECT DISTINCT file_path FROM nodes').all();
|
|
2626
|
+
return rows.map((row) => row.file_path.toLowerCase()).join('\n') + '\n';
|
|
2627
|
+
};
|
|
2628
|
+
return this.memoizedRead('loweredNodePaths', read) ?? read();
|
|
2629
|
+
}
|
|
2630
|
+
fieldFiltersCanMatch(filters) {
|
|
2631
|
+
if (filters.names.length > 0) {
|
|
2632
|
+
const names = this.fuzzyNames().lowered;
|
|
2633
|
+
if (!filters.names.some((n) => names.includes(n)))
|
|
2634
|
+
return false;
|
|
2635
|
+
}
|
|
2636
|
+
if (filters.paths.length > 0) {
|
|
2637
|
+
const paths = this.loweredNodePaths();
|
|
2638
|
+
if (!filters.paths.some((p) => paths.includes(p)))
|
|
2639
|
+
return false;
|
|
2640
|
+
}
|
|
2641
|
+
return true;
|
|
2642
|
+
}
|
|
2643
|
+
readQualifiedNameRuns() {
|
|
2644
|
+
const runs = new Set();
|
|
2645
|
+
const rows = this.db.prepare('SELECT DISTINCT qualified_name AS name FROM nodes').all();
|
|
2646
|
+
for (const row of rows) {
|
|
2647
|
+
for (const run of row.name.toLowerCase().split(/[^a-z0-9]+/)) {
|
|
2648
|
+
if (run)
|
|
2649
|
+
runs.add(run);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return [...runs].join('\n');
|
|
2653
|
+
}
|
|
2654
|
+
getNodeNamesOfKinds(language, kinds) {
|
|
2655
|
+
const rows = this.db
|
|
2656
|
+
.prepare(`SELECT name FROM nodes WHERE kind IN (${kinds.map(() => '?').join(', ')}) AND +language = ?`)
|
|
2657
|
+
.all(...kinds, language);
|
|
2658
|
+
return rows.map((r) => r.name);
|
|
2659
|
+
}
|
|
2660
|
+
getCppIncludeNodes() {
|
|
2661
|
+
if (!this.stmts.getCppIncludeNodes) {
|
|
2662
|
+
this.stmts.getCppIncludeNodes = this.db.prepare(`SELECT id, name, file_path AS filePath, language, start_line AS startLine, start_column AS startColumn
|
|
2663
|
+
FROM nodes WHERE kind = 'import' AND language IN ('c', 'cpp')`);
|
|
2664
|
+
}
|
|
2665
|
+
return this.stmts.getCppIncludeNodes.all();
|
|
2666
|
+
}
|
|
3029
2667
|
*iterateNodeNames() {
|
|
3030
2668
|
const stmt = this.db.prepare('SELECT DISTINCT name FROM nodes');
|
|
3031
2669
|
for (const row of stmt.iterate()) {
|
|
3032
2670
|
yield row.name;
|
|
3033
2671
|
}
|
|
3034
2672
|
}
|
|
3035
|
-
/**
|
|
3036
|
-
* Get unresolved references scoped to specific file paths.
|
|
3037
|
-
* Uses the idx_unresolved_file_path index for efficient lookup.
|
|
3038
|
-
*/
|
|
3039
2673
|
getUnresolvedReferencesByFiles(filePaths) {
|
|
3040
2674
|
if (filePaths.length === 0)
|
|
3041
2675
|
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
2676
|
const rows = [];
|
|
3047
2677
|
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3048
2678
|
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
@@ -3050,11 +2680,6 @@ class QueryBuilder {
|
|
|
3050
2680
|
const chunkRows = this.db
|
|
3051
2681
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
|
|
3052
2682
|
.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
2683
|
for (const row of chunkRows)
|
|
3059
2684
|
rows.push(row);
|
|
3060
2685
|
}
|
|
@@ -3070,40 +2695,22 @@ class QueryBuilder {
|
|
|
3070
2695
|
rowId: row.id,
|
|
3071
2696
|
}));
|
|
3072
2697
|
}
|
|
3073
|
-
/**
|
|
3074
|
-
* Delete all unresolved references (after resolution)
|
|
3075
|
-
*/
|
|
3076
2698
|
clearUnresolvedReferences() {
|
|
3077
2699
|
this.db.exec('DELETE FROM unresolved_refs');
|
|
3078
2700
|
}
|
|
3079
|
-
/**
|
|
3080
|
-
* Delete resolved references by their IDs
|
|
3081
|
-
*/
|
|
3082
2701
|
deleteResolvedReferences(fromNodeIds) {
|
|
3083
2702
|
if (fromNodeIds.length === 0)
|
|
3084
2703
|
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
2704
|
for (let i = 0; i < fromNodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3091
2705
|
const chunk = fromNodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3092
2706
|
const placeholders = chunk.map(() => '?').join(',');
|
|
3093
2707
|
this.db.prepare(`DELETE FROM unresolved_refs WHERE from_node_id IN (${placeholders})`).run(...chunk);
|
|
3094
2708
|
}
|
|
3095
2709
|
}
|
|
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
2710
|
deleteSpecificResolvedReferences(refs) {
|
|
3101
2711
|
if (refs.length === 0)
|
|
3102
2712
|
return 0;
|
|
3103
2713
|
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
2714
|
let changed = 0;
|
|
3108
2715
|
const deleteMany = this.db.transaction((items) => {
|
|
3109
2716
|
for (const ref of items) {
|
|
@@ -3113,23 +2720,9 @@ class QueryBuilder {
|
|
|
3113
2720
|
deleteMany(refs);
|
|
3114
2721
|
return changed;
|
|
3115
2722
|
}
|
|
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
2723
|
deleteReferencesByRowIds(rowIds) {
|
|
3125
2724
|
if (rowIds.length === 0)
|
|
3126
2725
|
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
2726
|
let changed = 0;
|
|
3134
2727
|
this.db.transaction(() => {
|
|
3135
2728
|
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
@@ -3149,15 +2742,6 @@ class QueryBuilder {
|
|
|
3149
2742
|
})();
|
|
3150
2743
|
return changed;
|
|
3151
2744
|
}
|
|
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
2745
|
markReferencesFailed(refs) {
|
|
3162
2746
|
if (refs.length === 0)
|
|
3163
2747
|
return 0;
|
|
@@ -3165,20 +2749,12 @@ class QueryBuilder {
|
|
|
3165
2749
|
let changed = 0;
|
|
3166
2750
|
const markMany = this.db.transaction((items) => {
|
|
3167
2751
|
for (const ref of items) {
|
|
3168
|
-
changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
2752
|
+
changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
3169
2753
|
}
|
|
3170
2754
|
});
|
|
3171
2755
|
markMany(refs);
|
|
3172
2756
|
return changed;
|
|
3173
2757
|
}
|
|
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
2758
|
markReferencesFailedByRowIds(refs) {
|
|
3183
2759
|
if (refs.length === 0)
|
|
3184
2760
|
return 0;
|
|
@@ -3186,54 +2762,61 @@ class QueryBuilder {
|
|
|
3186
2762
|
let changed = 0;
|
|
3187
2763
|
const markMany = this.db.transaction((items) => {
|
|
3188
2764
|
for (const ref of items) {
|
|
3189
|
-
changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
|
|
2765
|
+
changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.rowId).changes;
|
|
3190
2766
|
}
|
|
3191
2767
|
});
|
|
3192
2768
|
markMany(refs);
|
|
3193
2769
|
return changed;
|
|
3194
2770
|
}
|
|
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) {
|
|
2771
|
+
getRetryableFailedReferences(names, perNameCeiling = 500, perModuleCeiling = 5000) {
|
|
3205
2772
|
if (names.length === 0)
|
|
3206
2773
|
return [];
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
2774
|
+
const lookups = [
|
|
2775
|
+
{ column: 'name_tail', where: "status = 'failed'" },
|
|
2776
|
+
{ column: 'reference_name', where: reference_tail_1.MODULE_PARKED_SQL },
|
|
2777
|
+
{ column: reference_tail_1.MEMBER_TAIL_SQL, where: `${reference_tail_1.MODULE_PARKED_SQL} AND instr(reference_name, '.') > 0` },
|
|
2778
|
+
];
|
|
2779
|
+
const counts = lookups.map(({ column, where }) => {
|
|
2780
|
+
const byKey = new Map();
|
|
2781
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2782
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2783
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2784
|
+
const found = this.db
|
|
2785
|
+
.prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
|
|
2786
|
+
.all(...chunk);
|
|
2787
|
+
for (const row of found)
|
|
2788
|
+
byKey.set(row.key, row.count);
|
|
2789
|
+
}
|
|
2790
|
+
return byKey;
|
|
2791
|
+
});
|
|
2792
|
+
const [byTail, , byMember] = counts;
|
|
2793
|
+
const population = (lookup, key, count) => lookup === 1 ? count : (byTail.get(key) ?? 0) + (byMember.get(key) ?? 0);
|
|
2794
|
+
const rows = new Map();
|
|
2795
|
+
for (const [lookup, { column, where }] of lookups.entries()) {
|
|
2796
|
+
const retryKeys = [...counts[lookup]]
|
|
2797
|
+
.filter(([key, count]) => (lookup === 0 && (0, reference_tail_1.isModuleKey)(key) ? count <= perModuleCeiling : population(lookup, key, count) <= perNameCeiling))
|
|
2798
|
+
.map(([key]) => key);
|
|
2799
|
+
for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2800
|
+
const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2801
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2802
|
+
const chunkRows = this.db
|
|
2803
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
|
|
2804
|
+
.all(...chunk);
|
|
2805
|
+
for (const row of chunkRows)
|
|
2806
|
+
rows.set(row.id, row);
|
|
3218
2807
|
}
|
|
3219
2808
|
}
|
|
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);
|
|
2809
|
+
const byReceiver = this.db.prepare(`SELECT * FROM unresolved_refs WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_name >= ? AND reference_name < ? LIMIT ?`);
|
|
2810
|
+
for (const name of names) {
|
|
2811
|
+
if (!RECEIVER_NAME.test(name))
|
|
2812
|
+
continue;
|
|
2813
|
+
const found = byReceiver.all(`${name}.`, `${name}/`, perNameCeiling + 1);
|
|
2814
|
+
if (found.length > perNameCeiling)
|
|
2815
|
+
continue;
|
|
2816
|
+
for (const row of found)
|
|
2817
|
+
rows.set(row.id, row);
|
|
3235
2818
|
}
|
|
3236
|
-
return rows.map((row) => ({
|
|
2819
|
+
return [...rows.values()].map((row) => ({
|
|
3237
2820
|
fromNodeId: row.from_node_id,
|
|
3238
2821
|
referenceName: row.reference_name,
|
|
3239
2822
|
referenceKind: row.reference_kind,
|
|
@@ -3245,35 +2828,153 @@ class QueryBuilder {
|
|
|
3245
2828
|
rowId: row.id,
|
|
3246
2829
|
}));
|
|
3247
2830
|
}
|
|
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
|
-
|
|
2831
|
+
getRetryableFailedImports(pathKeys, names = [], perNameCeiling = 500, resolvedModules = [], perModuleCeiling = 5000, couldName) {
|
|
2832
|
+
const failedImports = "status = 'failed' AND reference_kind = 'imports'";
|
|
2833
|
+
const lookups = [
|
|
2834
|
+
{ keys: pathKeys, column: 'name_tail', where: failedImports, ceiling: perNameCeiling, couldName },
|
|
2835
|
+
{ keys: pathKeys, column: 'reference_name', where: failedImports, ceiling: perNameCeiling, couldName },
|
|
2836
|
+
{ keys: names, column: 'reference_name', where: `${failedImports} AND name_tail != reference_name`, ceiling: perNameCeiling },
|
|
2837
|
+
{ keys: resolvedModules, column: 'reference_name', where: failedImports, ceiling: perModuleCeiling },
|
|
2838
|
+
];
|
|
2839
|
+
const toReference = (row) => ({
|
|
2840
|
+
fromNodeId: row.from_node_id,
|
|
2841
|
+
referenceName: row.reference_name,
|
|
2842
|
+
referenceKind: row.reference_kind,
|
|
2843
|
+
line: row.line,
|
|
2844
|
+
column: row.col,
|
|
2845
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2846
|
+
filePath: row.file_path,
|
|
2847
|
+
language: row.language,
|
|
2848
|
+
rowId: row.id,
|
|
2849
|
+
});
|
|
2850
|
+
const rows = new Map();
|
|
2851
|
+
for (const { keys, column, where, ceiling, couldName } of lookups) {
|
|
2852
|
+
const unique = [...new Set(keys)].filter((key) => key.length > 0);
|
|
2853
|
+
const retryKeys = [];
|
|
2854
|
+
const crowdedKeys = [];
|
|
2855
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2856
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2857
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2858
|
+
const counts = this.db
|
|
2859
|
+
.prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
|
|
2860
|
+
.all(...chunk);
|
|
2861
|
+
for (const row of counts) {
|
|
2862
|
+
if (row.count <= ceiling)
|
|
2863
|
+
retryKeys.push(row.key);
|
|
2864
|
+
else if (couldName)
|
|
2865
|
+
crowdedKeys.push(row.key);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2869
|
+
const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2870
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2871
|
+
const chunkRows = this.db
|
|
2872
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
|
|
2873
|
+
.all(...chunk);
|
|
2874
|
+
for (const row of chunkRows)
|
|
2875
|
+
rows.set(row.id, row);
|
|
2876
|
+
}
|
|
2877
|
+
for (const key of crowdedKeys) {
|
|
2878
|
+
const keyRows = this.db
|
|
2879
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (?)`)
|
|
2880
|
+
.all(key);
|
|
2881
|
+
const named = keyRows.filter((row) => couldName(toReference(row)));
|
|
2882
|
+
if (named.length > perModuleCeiling)
|
|
2883
|
+
continue;
|
|
2884
|
+
for (const row of named)
|
|
2885
|
+
rows.set(row.id, row);
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
return [...rows.values()].map(toReference);
|
|
2889
|
+
}
|
|
2890
|
+
getFailedScopedImports() {
|
|
2891
|
+
return this.db
|
|
2892
|
+
.prepare(`SELECT reference_name AS name, MIN(file_path) AS file_path, language
|
|
2893
|
+
FROM unresolved_refs
|
|
2894
|
+
WHERE status = 'failed' AND reference_kind = 'imports'
|
|
2895
|
+
AND reference_name GLOB '@?*/?*' AND reference_name NOT GLOB '@*/*/*'
|
|
2896
|
+
GROUP BY reference_name`)
|
|
2897
|
+
.all()
|
|
2898
|
+
.map((row) => ({ name: row.name, filePath: row.file_path, language: row.language }));
|
|
2899
|
+
}
|
|
2900
|
+
getFailedFolderImports() {
|
|
2901
|
+
const placeholders = FOLDER_SPECIFIERS.map(() => '?').join(',');
|
|
2902
|
+
return this.db
|
|
2903
|
+
.prepare(`SELECT * FROM unresolved_refs
|
|
2904
|
+
WHERE status = 'failed' AND reference_kind = 'imports' AND reference_name IN (${placeholders})`)
|
|
2905
|
+
.all(...FOLDER_SPECIFIERS)
|
|
2906
|
+
.map((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
|
+
}
|
|
2918
|
+
getFailedCallsByTail(tails) {
|
|
2919
|
+
const out = [];
|
|
2920
|
+
const unique = [...new Set(tails)];
|
|
2921
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2922
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2923
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2924
|
+
const rows = this.db
|
|
2925
|
+
.prepare(`SELECT id, reference_name, file_path FROM unresolved_refs
|
|
2926
|
+
WHERE status = 'failed' AND reference_kind = 'calls' AND name_tail IN (${placeholders})
|
|
2927
|
+
UNION ALL
|
|
2928
|
+
SELECT id, reference_name, file_path FROM unresolved_refs
|
|
2929
|
+
WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_kind = 'calls' AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
|
|
2930
|
+
.all(...chunk, ...chunk);
|
|
2931
|
+
for (const row of rows)
|
|
2932
|
+
out.push({ rowId: row.id, referenceName: row.reference_name, filePath: row.file_path });
|
|
2933
|
+
}
|
|
2934
|
+
return out;
|
|
2935
|
+
}
|
|
2936
|
+
getResolvedNavigations() {
|
|
2937
|
+
const rows = this.db
|
|
2938
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
2939
|
+
FROM edges e
|
|
2940
|
+
JOIN nodes src ON src.id = e.source
|
|
2941
|
+
WHERE e.kind = 'navigates' AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2942
|
+
.all();
|
|
2943
|
+
return rows.map((row) => ({
|
|
2944
|
+
...rowToEdge(row),
|
|
2945
|
+
edgeId: row.id,
|
|
2946
|
+
sourceFilePath: row.source_file_path,
|
|
2947
|
+
sourceLanguage: row.source_language,
|
|
2948
|
+
}));
|
|
2949
|
+
}
|
|
2950
|
+
getFailedModuleKeys() {
|
|
2951
|
+
return this.db
|
|
2952
|
+
.prepare(`SELECT DISTINCT name_tail AS key FROM unresolved_refs WHERE status = 'failed' AND name_tail GLOB 'module:*'`)
|
|
2953
|
+
.all().map((row) => row.key);
|
|
2954
|
+
}
|
|
2955
|
+
reopenFailedReferences(rowIds) {
|
|
2956
|
+
if (rowIds.length === 0)
|
|
2957
|
+
return 0;
|
|
2958
|
+
let changed = 0;
|
|
2959
|
+
this.db.transaction(() => {
|
|
2960
|
+
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2961
|
+
const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2962
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2963
|
+
changed += this.db
|
|
2964
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND id IN (${placeholders})`)
|
|
2965
|
+
.run(...chunk).changes;
|
|
2966
|
+
}
|
|
2967
|
+
})();
|
|
2968
|
+
return changed;
|
|
2969
|
+
}
|
|
2970
|
+
getMaxEdgeId() {
|
|
2971
|
+
return this.db.prepare('SELECT COALESCE(MAX(id), 0) AS id FROM edges').get().id;
|
|
2972
|
+
}
|
|
2973
|
+
getResolutionEdgesByTargetName(names, perNameCeiling = 500, countedUpToEdgeId) {
|
|
3273
2974
|
if (names.length === 0)
|
|
3274
2975
|
return [];
|
|
3275
|
-
// Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
|
|
3276
2976
|
const keep = [];
|
|
2977
|
+
const counted = countedUpToEdgeId === undefined ? '' : 'AND e.id <= ?';
|
|
3277
2978
|
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3278
2979
|
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3279
2980
|
const placeholders = chunk.map(() => '?').join(',');
|
|
@@ -3283,8 +2984,9 @@ class QueryBuilder {
|
|
|
3283
2984
|
JOIN nodes tgt ON tgt.id = e.target
|
|
3284
2985
|
WHERE tgt.name IN (${placeholders})
|
|
3285
2986
|
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2987
|
+
${counted}
|
|
3286
2988
|
GROUP BY tgt.name`)
|
|
3287
|
-
.all(...chunk);
|
|
2989
|
+
.all(...chunk, ...(countedUpToEdgeId === undefined ? [] : [countedUpToEdgeId]));
|
|
3288
2990
|
for (const row of counts) {
|
|
3289
2991
|
if (row.count <= perNameCeiling)
|
|
3290
2992
|
keep.push(row.name);
|
|
@@ -3292,8 +2994,6 @@ class QueryBuilder {
|
|
|
3292
2994
|
}
|
|
3293
2995
|
if (keep.length === 0)
|
|
3294
2996
|
return [];
|
|
3295
|
-
// Pass 2: load the surviving edges with the source file context a
|
|
3296
|
-
// resurrection needs.
|
|
3297
2997
|
const out = [];
|
|
3298
2998
|
for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3299
2999
|
const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
@@ -3317,7 +3017,166 @@ class QueryBuilder {
|
|
|
3317
3017
|
}
|
|
3318
3018
|
return out;
|
|
3319
3019
|
}
|
|
3320
|
-
|
|
3020
|
+
getRouteEdgesMovedBy(filePaths) {
|
|
3021
|
+
if (filePaths.length === 0)
|
|
3022
|
+
return [];
|
|
3023
|
+
const files = JSON.stringify(filePaths);
|
|
3024
|
+
const rows = this.db
|
|
3025
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3026
|
+
FROM nodes src
|
|
3027
|
+
JOIN edges e ON e.source = src.id
|
|
3028
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3029
|
+
WHERE src.kind = 'route'
|
|
3030
|
+
AND e.kind != 'contains'
|
|
3031
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
3032
|
+
AND src.file_path NOT IN (SELECT value FROM json_each(?))
|
|
3033
|
+
AND (tgt.file_path IN (SELECT value FROM json_each(?))
|
|
3034
|
+
OR (tgt.file_path = src.file_path AND tgt.kind IN ('constant', 'variable')))
|
|
3035
|
+
ORDER BY e.id`)
|
|
3036
|
+
.all(files, files);
|
|
3037
|
+
return rows.map((row) => ({
|
|
3038
|
+
...rowToEdge(row),
|
|
3039
|
+
edgeId: row.id,
|
|
3040
|
+
sourceFilePath: row.source_file_path,
|
|
3041
|
+
sourceLanguage: row.source_language,
|
|
3042
|
+
}));
|
|
3043
|
+
}
|
|
3044
|
+
getResolutionEdgesBySourceLanguage(language) {
|
|
3045
|
+
const rows = this.db
|
|
3046
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3047
|
+
FROM edges e
|
|
3048
|
+
JOIN nodes src ON src.id = e.source
|
|
3049
|
+
WHERE src.language = ?
|
|
3050
|
+
AND e.kind != 'contains'
|
|
3051
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3052
|
+
.all(language);
|
|
3053
|
+
return rows.map((row) => ({
|
|
3054
|
+
...rowToEdge(row),
|
|
3055
|
+
edgeId: row.id,
|
|
3056
|
+
sourceFilePath: row.source_file_path,
|
|
3057
|
+
sourceLanguage: row.source_language,
|
|
3058
|
+
}));
|
|
3059
|
+
}
|
|
3060
|
+
getResolutionEdgesTouchingFiles(language, targetFiles, sourceDirs, importNodeSegments = []) {
|
|
3061
|
+
const candidates = new Set();
|
|
3062
|
+
const idsWhere = (column, nodeIds) => {
|
|
3063
|
+
for (let i = 0; i < nodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3064
|
+
const chunk = nodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3065
|
+
const rows = this.db
|
|
3066
|
+
.prepare(`SELECT id FROM edges WHERE ${column} IN (${chunk.map(() => '?').join(',')})`)
|
|
3067
|
+
.all(...chunk);
|
|
3068
|
+
for (const r of rows)
|
|
3069
|
+
candidates.add(r.id);
|
|
3070
|
+
}
|
|
3071
|
+
};
|
|
3072
|
+
for (let i = 0; i < targetFiles.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3073
|
+
const chunk = targetFiles.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3074
|
+
const nodes = this.db
|
|
3075
|
+
.prepare(`SELECT id FROM nodes WHERE file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3076
|
+
.all(...chunk);
|
|
3077
|
+
idsWhere('target', nodes.map((n) => n.id));
|
|
3078
|
+
}
|
|
3079
|
+
for (const dir of sourceDirs) {
|
|
3080
|
+
const nodes = (dir === ''
|
|
3081
|
+
? this.db.prepare('SELECT id FROM nodes WHERE language = ?').all(language)
|
|
3082
|
+
: this.db
|
|
3083
|
+
.prepare('SELECT id FROM nodes WHERE file_path >= ? AND file_path < ?')
|
|
3084
|
+
.all(`${dir}/`, `${dir}0`));
|
|
3085
|
+
idsWhere('source', nodes.map((n) => n.id));
|
|
3086
|
+
}
|
|
3087
|
+
if (importNodeSegments.length > 0) {
|
|
3088
|
+
const wanted = new Set(importNodeSegments);
|
|
3089
|
+
const nodes = this.db
|
|
3090
|
+
.prepare("SELECT id, name FROM nodes WHERE kind = 'import' AND language = ?")
|
|
3091
|
+
.all(language);
|
|
3092
|
+
idsWhere('target', nodes.filter((n) => n.name.split('.').some((seg) => wanted.has(seg))).map((n) => n.id));
|
|
3093
|
+
}
|
|
3094
|
+
return this.loadResolutionEdges(language, [...candidates]);
|
|
3095
|
+
}
|
|
3096
|
+
getResolutionEdgesFromFiles(language, files) {
|
|
3097
|
+
const ids = [];
|
|
3098
|
+
for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3099
|
+
const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3100
|
+
const rows = this.db
|
|
3101
|
+
.prepare(`SELECT e.id AS id FROM nodes n CROSS JOIN edges e ON e.source = n.id
|
|
3102
|
+
WHERE n.file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3103
|
+
.all(...chunk);
|
|
3104
|
+
for (const r of rows)
|
|
3105
|
+
ids.push(r.id);
|
|
3106
|
+
}
|
|
3107
|
+
return this.loadResolutionEdges(language, ids);
|
|
3108
|
+
}
|
|
3109
|
+
loadResolutionEdges(language, ids) {
|
|
3110
|
+
const out = [];
|
|
3111
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3112
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3113
|
+
const rows = this.db
|
|
3114
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3115
|
+
FROM edges e
|
|
3116
|
+
CROSS JOIN nodes src ON src.id = e.source
|
|
3117
|
+
CROSS JOIN nodes tgt ON tgt.id = e.target
|
|
3118
|
+
WHERE e.id IN (${chunk.map(() => '?').join(',')})
|
|
3119
|
+
AND src.language = ?
|
|
3120
|
+
AND e.kind != 'contains'
|
|
3121
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3122
|
+
.all(...chunk, language);
|
|
3123
|
+
for (const row of rows) {
|
|
3124
|
+
out.push({ ...rowToEdge(row), edgeId: row.id, sourceFilePath: row.source_file_path, sourceLanguage: row.source_language });
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
return out;
|
|
3128
|
+
}
|
|
3129
|
+
requeueFailedReferencesBinding(language, names) {
|
|
3130
|
+
const files = [...names.keys()];
|
|
3131
|
+
const ids = [];
|
|
3132
|
+
for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3133
|
+
const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3134
|
+
const rows = this.db
|
|
3135
|
+
.prepare(`SELECT id, file_path, reference_name FROM unresolved_refs
|
|
3136
|
+
WHERE status = 'failed' AND language = ? AND file_path IN (${chunk.map(() => '?').join(',')})`)
|
|
3137
|
+
.all(language, ...chunk);
|
|
3138
|
+
for (const r of rows) {
|
|
3139
|
+
if (names.get(r.file_path)?.has(r.reference_name.split('.')[0]))
|
|
3140
|
+
ids.push(r.id);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
let changed = 0;
|
|
3144
|
+
this.db.transaction(() => {
|
|
3145
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3146
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3147
|
+
changed += this.db
|
|
3148
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
3149
|
+
.run(...chunk).changes;
|
|
3150
|
+
}
|
|
3151
|
+
})();
|
|
3152
|
+
return changed;
|
|
3153
|
+
}
|
|
3154
|
+
requeueFailedReferencesByLanguage(language, segments, files) {
|
|
3155
|
+
const sql = "UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND language = ?";
|
|
3156
|
+
if (!segments)
|
|
3157
|
+
return this.db.prepare(sql).run(language).changes;
|
|
3158
|
+
if (segments.length === 0)
|
|
3159
|
+
return 0;
|
|
3160
|
+
const wanted = new Set(segments);
|
|
3161
|
+
const ids = this.db
|
|
3162
|
+
.prepare("SELECT id, reference_name, file_path FROM unresolved_refs WHERE status = 'failed' AND language = ?")
|
|
3163
|
+
.all(language)
|
|
3164
|
+
.filter((r) => r.reference_name.split('.').some((seg) => wanted.has(seg)))
|
|
3165
|
+
.map((r) => {
|
|
3166
|
+
files?.add(r.file_path);
|
|
3167
|
+
return r.id;
|
|
3168
|
+
});
|
|
3169
|
+
let changed = 0;
|
|
3170
|
+
this.db.transaction(() => {
|
|
3171
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3172
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3173
|
+
changed += this.db
|
|
3174
|
+
.prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
3175
|
+
.run(...chunk).changes;
|
|
3176
|
+
}
|
|
3177
|
+
})();
|
|
3178
|
+
return changed;
|
|
3179
|
+
}
|
|
3321
3180
|
deleteEdgesByIds(edgeIds) {
|
|
3322
3181
|
if (edgeIds.length === 0)
|
|
3323
3182
|
return 0;
|
|
@@ -3331,10 +3190,96 @@ class QueryBuilder {
|
|
|
3331
3190
|
})();
|
|
3332
3191
|
return changed;
|
|
3333
3192
|
}
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3193
|
+
getEdgesWithTypeFrom() {
|
|
3194
|
+
const rows = this.db
|
|
3195
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3196
|
+
FROM edges e
|
|
3197
|
+
JOIN nodes src ON src.id = e.source
|
|
3198
|
+
WHERE e.metadata LIKE '%"typeFrom"%'`)
|
|
3199
|
+
.all();
|
|
3200
|
+
return rows.map((row) => ({
|
|
3201
|
+
...rowToEdge(row),
|
|
3202
|
+
edgeId: row.id,
|
|
3203
|
+
sourceFilePath: row.source_file_path,
|
|
3204
|
+
sourceLanguage: row.source_language,
|
|
3205
|
+
}));
|
|
3206
|
+
}
|
|
3207
|
+
get parameterFlows() {
|
|
3208
|
+
return (this.flowQueries ??= new parameter_flow_queries_1.ParameterFlowQueries(this.db, this));
|
|
3209
|
+
}
|
|
3210
|
+
getPythonImporterClosure(filePaths, depth = 6) {
|
|
3211
|
+
const closure = new Set(filePaths);
|
|
3212
|
+
let frontier = [...filePaths];
|
|
3213
|
+
for (let hop = 0; hop < depth && frontier.length > 0; hop++) {
|
|
3214
|
+
const next = [];
|
|
3215
|
+
for (let i = 0; i < frontier.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3216
|
+
const chunk = frontier.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3217
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3218
|
+
const rows = this.db
|
|
3219
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
3220
|
+
FROM edges e
|
|
3221
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3222
|
+
JOIN nodes src ON src.id = e.source
|
|
3223
|
+
WHERE e.kind = 'imports' AND tgt.file_path IN (${placeholders}) AND src.language = 'python'`)
|
|
3224
|
+
.all(...chunk);
|
|
3225
|
+
for (const row of rows) {
|
|
3226
|
+
if (!closure.has(row.file_path)) {
|
|
3227
|
+
closure.add(row.file_path);
|
|
3228
|
+
next.push(row.file_path);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
frontier = next;
|
|
3233
|
+
}
|
|
3234
|
+
return [...closure];
|
|
3235
|
+
}
|
|
3236
|
+
getFailedPythonAttrRefKeys(filePaths) {
|
|
3237
|
+
const wanted = new Set(filePaths);
|
|
3238
|
+
const rows = this.db
|
|
3239
|
+
.prepare(`SELECT id, from_node_id, reference_name, file_path FROM unresolved_refs WHERE ${FAILED_PY_ATTR_REF}`)
|
|
3240
|
+
.all();
|
|
3241
|
+
const out = [];
|
|
3242
|
+
for (const r of rows) {
|
|
3243
|
+
if (wanted.has(r.file_path))
|
|
3244
|
+
out.push({ id: r.id, fromNodeId: r.from_node_id, referenceName: r.reference_name, filePath: r.file_path });
|
|
3245
|
+
}
|
|
3246
|
+
return out;
|
|
3247
|
+
}
|
|
3248
|
+
getUnresolvedReferencesByIds(ids) {
|
|
3249
|
+
const rows = [];
|
|
3250
|
+
for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3251
|
+
const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3252
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3253
|
+
const chunkRows = this.db
|
|
3254
|
+
.prepare(`SELECT * FROM unresolved_refs WHERE id IN (${placeholders})`)
|
|
3255
|
+
.all(...chunk);
|
|
3256
|
+
for (const row of chunkRows)
|
|
3257
|
+
rows.push(row);
|
|
3258
|
+
}
|
|
3259
|
+
return rows.map((row) => ({
|
|
3260
|
+
fromNodeId: row.from_node_id,
|
|
3261
|
+
referenceName: row.reference_name,
|
|
3262
|
+
referenceKind: row.reference_kind,
|
|
3263
|
+
line: row.line,
|
|
3264
|
+
column: row.col,
|
|
3265
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
3266
|
+
filePath: row.file_path,
|
|
3267
|
+
language: row.language,
|
|
3268
|
+
rowId: row.id,
|
|
3269
|
+
}));
|
|
3270
|
+
}
|
|
3271
|
+
getPythonFilesWithEdgesInto(filePath, kinds, targetKinds) {
|
|
3272
|
+
const kp = kinds.map(() => '?').join(',');
|
|
3273
|
+
const tp = targetKinds.map(() => '?').join(',');
|
|
3274
|
+
return this.db
|
|
3275
|
+
.prepare(`SELECT DISTINCT src.file_path AS file_path
|
|
3276
|
+
FROM edges e
|
|
3277
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3278
|
+
JOIN nodes src ON src.id = e.source
|
|
3279
|
+
WHERE tgt.file_path = ? AND e.kind IN (${kp}) AND tgt.kind IN (${tp})
|
|
3280
|
+
AND src.language = 'python' AND src.file_path != ?`)
|
|
3281
|
+
.all(filePath, ...kinds, ...targetKinds, filePath).map((r) => r.file_path);
|
|
3282
|
+
}
|
|
3338
3283
|
replaceResolutionEdgesWithUnresolvedRefs(edgeIds, refs) {
|
|
3339
3284
|
return this.db.transaction(() => {
|
|
3340
3285
|
const changed = this.deleteEdgesByIds(edgeIds);
|
|
@@ -3342,37 +3287,22 @@ class QueryBuilder {
|
|
|
3342
3287
|
return changed;
|
|
3343
3288
|
})();
|
|
3344
3289
|
}
|
|
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) {
|
|
3290
|
+
getNodeNamesByFiles(filePaths, kinds) {
|
|
3350
3291
|
if (filePaths.length === 0)
|
|
3351
3292
|
return [];
|
|
3293
|
+
const kindFilter = kinds ? ` AND kind IN (${kinds.map(() => '?').join(',')})` : '';
|
|
3352
3294
|
const names = new Set();
|
|
3353
3295
|
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3354
3296
|
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3355
3297
|
const placeholders = chunk.map(() => '?').join(',');
|
|
3356
3298
|
const rows = this.db
|
|
3357
|
-
.prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})`)
|
|
3358
|
-
.all(...chunk);
|
|
3299
|
+
.prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})${kindFilter}`)
|
|
3300
|
+
.all(...chunk, ...(kinds ?? []));
|
|
3359
3301
|
for (const row of rows)
|
|
3360
3302
|
names.add(row.name);
|
|
3361
3303
|
}
|
|
3362
3304
|
return [...names];
|
|
3363
3305
|
}
|
|
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
3306
|
getNodeNamePairsByFiles(filePaths) {
|
|
3377
3307
|
const pairs = new Set();
|
|
3378
3308
|
if (filePaths.length === 0)
|
|
@@ -3383,32 +3313,48 @@ class QueryBuilder {
|
|
|
3383
3313
|
const rows = this.db
|
|
3384
3314
|
.prepare(`SELECT DISTINCT file_path, name FROM nodes WHERE file_path IN (${placeholders})`)
|
|
3385
3315
|
.all(...chunk);
|
|
3386
|
-
// NUL-joined: a path or a symbol name can contain a space, never a NUL.
|
|
3387
3316
|
for (const row of rows)
|
|
3388
3317
|
pairs.add(`${row.file_path}\0${row.name}`);
|
|
3389
3318
|
}
|
|
3390
3319
|
return pairs;
|
|
3391
3320
|
}
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3321
|
+
getReExportStatementsByFiles(filePaths) {
|
|
3322
|
+
const pairs = new Set();
|
|
3323
|
+
if (filePaths.length === 0)
|
|
3324
|
+
return pairs;
|
|
3325
|
+
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3326
|
+
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3327
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3328
|
+
const rows = this.db
|
|
3329
|
+
.prepare(`SELECT DISTINCT file_path, signature FROM nodes
|
|
3330
|
+
WHERE kind = 'import' AND file_path IN (${placeholders}) AND signature LIKE 'export%'`)
|
|
3331
|
+
.all(...chunk);
|
|
3332
|
+
for (const row of rows)
|
|
3333
|
+
pairs.add(`${row.file_path}\0${row.signature}`);
|
|
3334
|
+
}
|
|
3335
|
+
return pairs;
|
|
3336
|
+
}
|
|
3402
3337
|
getNodeAndEdgeCount() {
|
|
3403
3338
|
return this.db
|
|
3404
3339
|
.prepare('SELECT (SELECT COUNT(*) FROM nodes) AS nodes, (SELECT COUNT(*) FROM edges) AS edges')
|
|
3405
3340
|
.get();
|
|
3406
3341
|
}
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3342
|
+
getParsedFileCounts() {
|
|
3343
|
+
return this.db
|
|
3344
|
+
.prepare(`
|
|
3345
|
+
SELECT f.language AS language, COUNT(*) AS files,
|
|
3346
|
+
SUM(CASE
|
|
3347
|
+
WHEN f.node_count > 1 THEN 1
|
|
3348
|
+
WHEN EXISTS (SELECT 1 FROM nodes n WHERE n.file_path = f.path AND n.kind <> 'file') THEN 1
|
|
3349
|
+
ELSE 0
|
|
3350
|
+
END) AS parsed
|
|
3351
|
+
FROM files f
|
|
3352
|
+
GROUP BY f.language
|
|
3353
|
+
ORDER BY f.language
|
|
3354
|
+
`)
|
|
3355
|
+
.all();
|
|
3356
|
+
}
|
|
3410
3357
|
getStats() {
|
|
3411
|
-
// Single query for all three aggregate counts
|
|
3412
3358
|
const counts = this.db.prepare(`
|
|
3413
3359
|
SELECT
|
|
3414
3360
|
(SELECT COUNT(*) FROM nodes) AS node_count,
|
|
@@ -3443,30 +3389,18 @@ class QueryBuilder {
|
|
|
3443
3389
|
nodesByKind,
|
|
3444
3390
|
edgesByKind,
|
|
3445
3391
|
filesByLanguage,
|
|
3446
|
-
dbSizeBytes: 0,
|
|
3447
|
-
walSizeBytes: 0,
|
|
3392
|
+
dbSizeBytes: 0,
|
|
3393
|
+
walSizeBytes: 0,
|
|
3448
3394
|
lastUpdated: Date.now(),
|
|
3449
3395
|
};
|
|
3450
3396
|
}
|
|
3451
|
-
// ===========================================================================
|
|
3452
|
-
// Project Metadata
|
|
3453
|
-
// ===========================================================================
|
|
3454
|
-
/**
|
|
3455
|
-
* Get a metadata value by key
|
|
3456
|
-
*/
|
|
3457
3397
|
getMetadata(key) {
|
|
3458
3398
|
const row = this.db.prepare('SELECT value FROM project_metadata WHERE key = ?').get(key);
|
|
3459
3399
|
return row?.value ?? null;
|
|
3460
3400
|
}
|
|
3461
|
-
/**
|
|
3462
|
-
* Set a metadata key-value pair (upsert)
|
|
3463
|
-
*/
|
|
3464
3401
|
setMetadata(key, value) {
|
|
3465
3402
|
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
3403
|
}
|
|
3467
|
-
/**
|
|
3468
|
-
* Get all metadata as a key-value record
|
|
3469
|
-
*/
|
|
3470
3404
|
getAllMetadata() {
|
|
3471
3405
|
const rows = this.db.prepare('SELECT key, value FROM project_metadata').all();
|
|
3472
3406
|
const result = {};
|
|
@@ -3475,9 +3409,6 @@ class QueryBuilder {
|
|
|
3475
3409
|
}
|
|
3476
3410
|
return result;
|
|
3477
3411
|
}
|
|
3478
|
-
/**
|
|
3479
|
-
* Clear all data from the database
|
|
3480
|
-
*/
|
|
3481
3412
|
clear() {
|
|
3482
3413
|
this.nodeCache.clear();
|
|
3483
3414
|
this.db.transaction(() => {
|
|
@@ -3490,8 +3421,6 @@ class QueryBuilder {
|
|
|
3490
3421
|
}
|
|
3491
3422
|
exports.QueryBuilder = QueryBuilder;
|
|
3492
3423
|
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
3424
|
const SEP = '\u0000';
|
|
3496
3425
|
const links = new Map();
|
|
3497
3426
|
const pairKinds = new Set(options.pairKinds);
|
|
@@ -3515,9 +3444,6 @@ function foldModuleRows(rows, options) {
|
|
|
3515
3444
|
uncertain: row.uncertain,
|
|
3516
3445
|
});
|
|
3517
3446
|
}
|
|
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
3447
|
if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind))
|
|
3522
3448
|
continue;
|
|
3523
3449
|
const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;
|