@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph.cmd +1 -1
- package/lib/dist/bin/codegraph.js +206 -44
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/context/formatter.d.ts +7 -1
- package/lib/dist/context/formatter.d.ts.map +1 -1
- package/lib/dist/context/formatter.js +12 -6
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +12 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +101 -25
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +179 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +368 -7
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +25 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +234 -5
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +687 -53
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +16 -3
- package/lib/dist/db/sqlite-adapter.d.ts +3 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +22 -4
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +15 -2
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +88 -6
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/directory.d.ts +29 -0
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +52 -0
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/extraction/extraction-version.d.ts +1 -1
- package/lib/dist/extraction/extraction-version.js +1 -1
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +6 -0
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.d.ts +48 -12
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +176 -11
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +101 -2
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +138 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +518 -94
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.d.ts +9 -0
- package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/decode.js +162 -0
- package/lib/dist/extraction/kernel/decode.js.map +1 -0
- package/lib/dist/extraction/kernel/index.d.ts +64 -0
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/index.js +279 -0
- package/lib/dist/extraction/kernel/index.js.map +1 -0
- package/lib/dist/extraction/kernel/layout.d.ts +101 -0
- package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/layout.js +104 -0
- package/lib/dist/extraction/kernel/layout.js.map +1 -0
- package/lib/dist/extraction/kernel/loader.d.ts +103 -0
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/loader.js +146 -0
- package/lib/dist/extraction/kernel/loader.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +868 -16
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
- package/lib/dist/extraction/languages/erlang.js +58 -22
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +4 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +47 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +15 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +35 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +35 -1
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +24 -0
- package/lib/dist/extraction/store-worker.d.ts.map +1 -0
- package/lib/dist/extraction/store-worker.js +139 -0
- package/lib/dist/extraction/store-worker.js.map +1 -0
- package/lib/dist/extraction/store-writer.d.ts +63 -0
- package/lib/dist/extraction/store-writer.d.ts.map +1 -0
- package/lib/dist/extraction/store-writer.js +174 -0
- package/lib/dist/extraction/store-writer.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +27 -5
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +257 -56
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -0
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/traversal.js +1 -1
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +36 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +305 -11
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.d.ts +54 -0
- package/lib/dist/installer/beta-signup.d.ts.map +1 -0
- package/lib/dist/installer/beta-signup.js +178 -0
- package/lib/dist/installer/beta-signup.js.map +1 -0
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +19 -6
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +37 -5
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +22 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +65 -48
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-cli.js +209 -0
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.js +219 -0
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +6 -0
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +6 -5
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +99 -20
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +5 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +1 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +6 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +54 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +10 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +51 -3
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +9 -6
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +10 -8
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +3 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +45 -3
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +137 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +236 -0
- package/lib/dist/mcp/explore-dedup.js.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.js +558 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.d.ts +217 -0
- package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +322 -0
- package/lib/dist/mcp/explore-session-state.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +24 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +67 -6
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +3 -1
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +6 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +2 -2
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +8 -3
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +16 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +36 -13
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +276 -10
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +2425 -237
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/project-config.d.ts +23 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +39 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +287 -167
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
- package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/lib/dist/resolution/cooperative-yield.js +6 -4
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +29 -6
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +11 -1
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +184 -9
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +87 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +731 -134
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/memory-budget.d.ts +48 -0
- package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
- package/lib/dist/resolution/memory-budget.js +162 -0
- package/lib/dist/resolution/memory-budget.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +42 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +681 -99
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/path-aliases.d.ts +6 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +125 -17
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/resolver-pool.d.ts +106 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-pool.js +344 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -0
- package/lib/dist/resolution/resolver-worker.d.ts +17 -0
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-worker.js +141 -0
- package/lib/dist/resolution/resolver-worker.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +3 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.d.ts +10 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.js +29 -0
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-paths.d.ts +57 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +298 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +1 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +13 -3
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +47 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +127 -8
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +61 -3
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +27 -1
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.d.ts +21 -0
- package/lib/dist/ui/color.d.ts.map +1 -0
- package/lib/dist/ui/color.js +42 -0
- package/lib/dist/ui/color.js.map +1 -0
- package/lib/dist/ui/glyphs.d.ts +35 -10
- package/lib/dist/ui/glyphs.d.ts.map +1 -1
- package/lib/dist/ui/glyphs.js +59 -12
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +78 -4
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +25 -17
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui/types.d.ts +0 -2
- package/lib/dist/ui/types.d.ts.map +1 -1
- package/lib/dist/upgrade/index.d.ts +7 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +18 -5
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +0 -0
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +6 -1
- package/package.json +6 -2
package/lib/dist/db/queries.js
CHANGED
|
@@ -5,20 +5,26 @@
|
|
|
5
5
|
* Prepared statements for CRUD operations on the knowledge graph.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.QueryBuilder = void 0;
|
|
8
|
+
exports.QueryBuilder = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const query_utils_1 = require("../search/query-utils");
|
|
11
11
|
const query_parser_1 = require("../search/query-parser");
|
|
12
12
|
const generated_detection_1 = require("../extraction/generated-detection");
|
|
13
13
|
const identifier_segments_1 = require("../search/identifier-segments");
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Files that should not be candidates for "dominant file" detection: test/spec
|
|
16
|
+
* files and tool-generated files. Generated files (`*.pb.go`, `*.pulsar.go`,
|
|
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).
|
|
20
24
|
*/
|
|
21
|
-
function isLowValueFile(filePath) {
|
|
25
|
+
function isLowValueFile(filePath, generated) {
|
|
26
|
+
if (generated?.has(filePath))
|
|
27
|
+
return true;
|
|
22
28
|
const lp = filePath.toLowerCase();
|
|
23
29
|
return (/(?:^|\/)(tests?|__tests?__|spec)\//.test(lp) ||
|
|
24
30
|
/_test\.go$/.test(lp) ||
|
|
@@ -34,6 +40,22 @@ function isLowValueFile(filePath) {
|
|
|
34
40
|
(0, generated_detection_1.isGeneratedFile)(filePath));
|
|
35
41
|
}
|
|
36
42
|
const SQLITE_PARAM_CHUNK_SIZE = 500;
|
|
43
|
+
/**
|
|
44
|
+
* How much of the exact-name bonus a `deprioritize`d path keeps (#982). Damped
|
|
45
|
+
* rather than zeroed: a query that genuinely targets that tree must still rank
|
|
46
|
+
* it, the same "discount, don't erase" rule the path penalty follows.
|
|
47
|
+
*
|
|
48
|
+
* Derived rather than picked. `nameMatchBonus`'s prefix arm tops out below
|
|
49
|
+
* `10 + 30 = 40`, and a de-prioritized node also takes the -15 path penalty, so
|
|
50
|
+
* `80 * SCALE - 15 > 40` is what stops a damped WHOLE-QUERY exact match from
|
|
51
|
+
* losing to a mere prefix match. 0.75 clears it (45). Measured on a 62k-node
|
|
52
|
+
* django index: at 0.25 that invariant breaks in practice — `child`, `parent`
|
|
53
|
+
* and `method` lose rank 1 to `children`, `all_parents` and `method_decorator`
|
|
54
|
+
* — while crowd-out removal is almost flat between 0.75 and 0.5 (39 vs 40 of 88
|
|
55
|
+
* peripheral top-10 slots cleared), so a deeper discount buys little and costs
|
|
56
|
+
* the invariant. Pinned by a test.
|
|
57
|
+
*/
|
|
58
|
+
exports.DEPRIORITIZED_NAME_BONUS_SCALE = 0.75;
|
|
37
59
|
/**
|
|
38
60
|
* Last segment of a (possibly dotted/qualified) reference name — the part a
|
|
39
61
|
* new symbol's plain node name could match: 'util.greet' → 'greet',
|
|
@@ -42,8 +64,11 @@ const SQLITE_PARAM_CHUNK_SIZE = 500;
|
|
|
42
64
|
* refs against newly-added node names.
|
|
43
65
|
*/
|
|
44
66
|
function referenceNameTail(referenceName) {
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
// Erlang refs carry a written arity (`f/1`, `mod::fn/2` — #1610); the tail a
|
|
68
|
+
// new symbol's plain name could match is the arity-less function name.
|
|
69
|
+
const base = referenceName.replace(/\/\d{1,3}$/, '') || referenceName;
|
|
70
|
+
const idx = Math.max(base.lastIndexOf('.'), base.lastIndexOf(':'));
|
|
71
|
+
return idx >= 0 ? base.slice(idx + 1) : base;
|
|
47
72
|
}
|
|
48
73
|
/**
|
|
49
74
|
* Convert database row to Node object
|
|
@@ -100,6 +125,7 @@ function rowToFileRecord(row) {
|
|
|
100
125
|
indexedAt: row.indexed_at,
|
|
101
126
|
nodeCount: row.node_count,
|
|
102
127
|
errors: row.errors ? (0, utils_1.safeJsonParse)(row.errors, undefined) : undefined,
|
|
128
|
+
generated: row.generated === 1,
|
|
103
129
|
};
|
|
104
130
|
}
|
|
105
131
|
/**
|
|
@@ -112,6 +138,7 @@ class QueryBuilder {
|
|
|
112
138
|
// whole project, not a symbol, so it carries no discriminative signal (#720).
|
|
113
139
|
// Set once by the CodeGraph instance; empty by default (no down-weighting).
|
|
114
140
|
projectNameTokens = new Set();
|
|
141
|
+
isDeprioritizedPath;
|
|
115
142
|
// Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
|
|
116
143
|
nodeCache = new Map();
|
|
117
144
|
maxCacheSize = 1000;
|
|
@@ -123,9 +150,67 @@ class QueryBuilder {
|
|
|
123
150
|
// correctness backstop. Bounded so a pathological repo can't grow it forever.
|
|
124
151
|
segmentedNames = new Set();
|
|
125
152
|
static MAX_SEGMENTED_NAMES = 65536;
|
|
153
|
+
// Multi-row INSERT statements, cached per (statement kind × row count). The
|
|
154
|
+
// bulk write path decomposes N rows into a few fixed batch sizes so each
|
|
155
|
+
// size's statement is prepared once and reused — one .run() binds a whole
|
|
156
|
+
// chunk instead of one row, which is where the per-call overhead lives.
|
|
157
|
+
// Row order within and across chunks is the input order, so rowid assignment
|
|
158
|
+
// (and therefore resolution's insertion-order disambiguation) is identical
|
|
159
|
+
// to the one-row-per-run path.
|
|
160
|
+
batchStmts = new Map();
|
|
161
|
+
static BATCH_SIZES = [128, 32, 8, 1];
|
|
162
|
+
/**
|
|
163
|
+
* Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
|
|
164
|
+
* decomposed greedily into the cached batch sizes. Preserves row order.
|
|
165
|
+
*/
|
|
166
|
+
runBatched(kind, head, tuple, rows) {
|
|
167
|
+
if (rows.length === 0)
|
|
168
|
+
return;
|
|
169
|
+
let i = 0;
|
|
170
|
+
for (const size of QueryBuilder.BATCH_SIZES) {
|
|
171
|
+
while (rows.length - i >= size) {
|
|
172
|
+
const key = `${kind}:${size}`;
|
|
173
|
+
let stmt = this.batchStmts.get(key);
|
|
174
|
+
if (!stmt) {
|
|
175
|
+
stmt = this.db.prepare(head + new Array(size).fill(tuple).join(','));
|
|
176
|
+
this.batchStmts.set(key, stmt);
|
|
177
|
+
}
|
|
178
|
+
if (size === 1) {
|
|
179
|
+
stmt.run(...rows[i]);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const params = [];
|
|
183
|
+
for (let r = 0; r < size; r++) {
|
|
184
|
+
const row = rows[i + r];
|
|
185
|
+
for (let c = 0; c < row.length; c++)
|
|
186
|
+
params.push(row[c]);
|
|
187
|
+
}
|
|
188
|
+
stmt.run(...params);
|
|
189
|
+
}
|
|
190
|
+
i += size;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
126
194
|
constructor(db) {
|
|
127
195
|
this.db = db;
|
|
128
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Swap the underlying connection in place. Used by pool workers'
|
|
199
|
+
* connection recycling (plan §7a.6, writes-under-readers): a long-lived
|
|
200
|
+
* read connection pins WAL checkpoint progress, and the deep WAL that
|
|
201
|
+
* accumulates behind it taxes every main-thread B-tree page operation
|
|
202
|
+
* (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
|
|
203
|
+
* identical hardware). Workers therefore close and reopen their read-only
|
|
204
|
+
* connection at the pool-idle boundary; everything above the connection —
|
|
205
|
+
* this QueryBuilder, the resolver and its warm caches — survives, and only
|
|
206
|
+
* connection-derived state (prepared statements) resets, re-preparing
|
|
207
|
+
* lazily on next use.
|
|
208
|
+
*/
|
|
209
|
+
rebind(db) {
|
|
210
|
+
this.db = db;
|
|
211
|
+
this.stmts = {};
|
|
212
|
+
this.batchStmts.clear();
|
|
213
|
+
}
|
|
129
214
|
/** Set the normalized project-name tokens used to down-weight non-discriminative
|
|
130
215
|
* query words in path scoring (#720). Called once when the project opens. */
|
|
131
216
|
setProjectNameTokens(tokens) {
|
|
@@ -135,6 +220,19 @@ class QueryBuilder {
|
|
|
135
220
|
getProjectNameTokens() {
|
|
136
221
|
return this.projectNameTokens;
|
|
137
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Set the predicate that marks a path as de-prioritized by the project's
|
|
225
|
+
* `codegraph.json` `deprioritize` patterns (#982). Ranking-only: those paths
|
|
226
|
+
* stay indexed and findable, they just stop outranking first-party code.
|
|
227
|
+
* Called once when the project opens; undefined disables the lever.
|
|
228
|
+
*/
|
|
229
|
+
setDeprioritizedPathMatcher(matcher) {
|
|
230
|
+
this.isDeprioritizedPath = matcher;
|
|
231
|
+
}
|
|
232
|
+
/** The `deprioritize` predicate (#982), so other rankers apply the same lever. */
|
|
233
|
+
getDeprioritizedPathMatcher() {
|
|
234
|
+
return this.isDeprioritizedPath;
|
|
235
|
+
}
|
|
138
236
|
// ===========================================================================
|
|
139
237
|
// Node Operations
|
|
140
238
|
// ===========================================================================
|
|
@@ -220,28 +318,115 @@ class QueryBuilder {
|
|
|
220
318
|
}
|
|
221
319
|
/** Write `name`'s segments into name_segment_vocab (idempotent). */
|
|
222
320
|
insertNameSegments(name) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.segmentedNames.clear();
|
|
227
|
-
this.segmentedNames.add(name);
|
|
228
|
-
if (!this.stmts.insertNameSegment) {
|
|
229
|
-
this.stmts.insertNameSegment = this.db.prepare('INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES (?, ?)');
|
|
230
|
-
}
|
|
231
|
-
for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name)) {
|
|
232
|
-
this.stmts.insertNameSegment.run(segment, name);
|
|
233
|
-
}
|
|
321
|
+
const rows = [];
|
|
322
|
+
this.collectNameSegmentRows(name, rows);
|
|
323
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
234
324
|
}
|
|
235
325
|
/**
|
|
236
326
|
* Insert multiple nodes in a transaction
|
|
237
327
|
*/
|
|
238
328
|
insertNodes(nodes) {
|
|
239
329
|
this.db.transaction(() => {
|
|
330
|
+
// Bulk path: same semantics as insertNode() per row (validation, cache
|
|
331
|
+
// invalidation, segment vocab), but bound as multi-row INSERTs — the
|
|
332
|
+
// per-.run() call overhead dominates the store phase on full indexes.
|
|
333
|
+
const rows = [];
|
|
334
|
+
const segmentRows = [];
|
|
240
335
|
for (const node of nodes) {
|
|
241
|
-
|
|
336
|
+
if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
|
|
337
|
+
console.error('[CodeGraph] Skipping node with missing required fields:', {
|
|
338
|
+
id: node.id,
|
|
339
|
+
kind: node.kind,
|
|
340
|
+
name: node.name,
|
|
341
|
+
filePath: node.filePath,
|
|
342
|
+
language: node.language,
|
|
343
|
+
});
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
this.nodeCache.delete(node.id);
|
|
347
|
+
rows.push([
|
|
348
|
+
node.id,
|
|
349
|
+
node.kind,
|
|
350
|
+
node.name,
|
|
351
|
+
node.qualifiedName ?? node.name,
|
|
352
|
+
node.filePath,
|
|
353
|
+
node.language,
|
|
354
|
+
node.startLine ?? 0,
|
|
355
|
+
node.endLine ?? 0,
|
|
356
|
+
node.startColumn ?? 0,
|
|
357
|
+
node.endColumn ?? 0,
|
|
358
|
+
node.docstring ?? null,
|
|
359
|
+
node.signature ?? null,
|
|
360
|
+
node.visibility ?? null,
|
|
361
|
+
node.isExported ? 1 : 0,
|
|
362
|
+
node.isAsync ? 1 : 0,
|
|
363
|
+
node.isStatic ? 1 : 0,
|
|
364
|
+
node.isAbstract ? 1 : 0,
|
|
365
|
+
node.decorators ? JSON.stringify(node.decorators) : null,
|
|
366
|
+
node.typeParameters ? JSON.stringify(node.typeParameters) : null,
|
|
367
|
+
node.returnType ?? null,
|
|
368
|
+
node.updatedAt ?? Date.now(),
|
|
369
|
+
]);
|
|
370
|
+
if (this.isSegmentableKind(node.kind))
|
|
371
|
+
this.collectNameSegmentRows(node.name, segmentRows);
|
|
372
|
+
}
|
|
373
|
+
this.runBatched('insertNodes', `INSERT OR REPLACE INTO nodes (
|
|
374
|
+
id, kind, name, qualified_name, file_path, language,
|
|
375
|
+
start_line, end_line, start_column, end_column,
|
|
376
|
+
docstring, signature, visibility,
|
|
377
|
+
is_exported, is_async, is_static, is_abstract,
|
|
378
|
+
decorators, type_parameters, return_type, updated_at
|
|
379
|
+
) VALUES `, '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', rows);
|
|
380
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
|
|
381
|
+
})();
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Store one file's whole extraction bundle — nodes, edges, unresolved refs,
|
|
385
|
+
* and the file record — in a SINGLE transaction. The bulk-index path calls
|
|
386
|
+
* this once per file instead of opening one transaction per table (#1015
|
|
387
|
+
* file-order commit discipline is unchanged: callers still invoke it in file
|
|
388
|
+
* order, and row order within is input order).
|
|
389
|
+
*
|
|
390
|
+
* Edges MUST already be endpoint-filtered by the caller (the store path
|
|
391
|
+
* filters to the file's own inserted node ids), so the per-file existence
|
|
392
|
+
* SELECT that insertEdges() pays is skipped here.
|
|
393
|
+
*/
|
|
394
|
+
storeFileBundle(bundle) {
|
|
395
|
+
this.db.transaction(() => {
|
|
396
|
+
this.insertNodes(bundle.nodes);
|
|
397
|
+
if (bundle.edges.length > 0) {
|
|
398
|
+
const rows = [];
|
|
399
|
+
for (const edge of bundle.edges) {
|
|
400
|
+
rows.push([
|
|
401
|
+
edge.source,
|
|
402
|
+
edge.target,
|
|
403
|
+
edge.kind,
|
|
404
|
+
edge.metadata ? JSON.stringify(edge.metadata) : null,
|
|
405
|
+
edge.line ?? null,
|
|
406
|
+
edge.column ?? null,
|
|
407
|
+
edge.provenance ?? null,
|
|
408
|
+
]);
|
|
409
|
+
}
|
|
410
|
+
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
242
411
|
}
|
|
412
|
+
if (bundle.refs.length > 0)
|
|
413
|
+
this.insertUnresolvedRefsBatch(bundle.refs);
|
|
414
|
+
this.upsertFile(bundle.file);
|
|
243
415
|
})();
|
|
244
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Collect (segment, name) rows for a name, honouring the same session-dedupe
|
|
419
|
+
* semantics as insertNameSegments(). Shared by the bulk write paths.
|
|
420
|
+
*/
|
|
421
|
+
collectNameSegmentRows(name, out) {
|
|
422
|
+
if (this.segmentedNames.has(name))
|
|
423
|
+
return;
|
|
424
|
+
if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
|
|
425
|
+
this.segmentedNames.clear();
|
|
426
|
+
this.segmentedNames.add(name);
|
|
427
|
+
for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
|
|
428
|
+
out.push([segment, name]);
|
|
429
|
+
}
|
|
245
430
|
/**
|
|
246
431
|
* Update an existing node
|
|
247
432
|
*/
|
|
@@ -367,8 +552,10 @@ class QueryBuilder {
|
|
|
367
552
|
/** Insert segments for a batch of names in one transaction (vocab heal path). */
|
|
368
553
|
insertNameSegmentsBatch(names) {
|
|
369
554
|
this.db.transaction(() => {
|
|
555
|
+
const rows = [];
|
|
370
556
|
for (const name of names)
|
|
371
|
-
this.
|
|
557
|
+
this.collectNameSegmentRows(name, rows);
|
|
558
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
372
559
|
})();
|
|
373
560
|
}
|
|
374
561
|
/**
|
|
@@ -579,7 +766,8 @@ class QueryBuilder {
|
|
|
579
766
|
`);
|
|
580
767
|
}
|
|
581
768
|
const rows = this.stmts.getDominantFile.all();
|
|
582
|
-
const
|
|
769
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
770
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
583
771
|
if (filtered.length === 0 || filtered[0].edge_count < 20)
|
|
584
772
|
return null;
|
|
585
773
|
return {
|
|
@@ -612,7 +800,8 @@ class QueryBuilder {
|
|
|
612
800
|
`);
|
|
613
801
|
}
|
|
614
802
|
const rows = this.stmts.getTopRouteFile.all();
|
|
615
|
-
const
|
|
803
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
804
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
616
805
|
if (filtered.length === 0)
|
|
617
806
|
return null;
|
|
618
807
|
const totalRoutes = filtered.reduce((sum, r) => sum + r.cnt, 0);
|
|
@@ -658,7 +847,8 @@ class QueryBuilder {
|
|
|
658
847
|
}
|
|
659
848
|
const rows = this.stmts.getRoutingManifest.all(limit);
|
|
660
849
|
// Drop test/generated handlers — same hygiene as elsewhere.
|
|
661
|
-
const
|
|
850
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
|
|
851
|
+
const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
|
|
662
852
|
if (filtered.length < 3)
|
|
663
853
|
return null;
|
|
664
854
|
// Identify the file holding the most handlers (the "primary handler file").
|
|
@@ -747,11 +937,26 @@ class QueryBuilder {
|
|
|
747
937
|
return new Set(rows.map((r) => r.language));
|
|
748
938
|
}
|
|
749
939
|
/**
|
|
750
|
-
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
940
|
+
* Get nodes by exact name match (uses idx_nodes_name index).
|
|
941
|
+
*
|
|
942
|
+
* This is resolution's candidate list, and the ORDER BY is load-bearing for
|
|
943
|
+
* index correctness, not cosmetic (CG-33). When a reference names a symbol
|
|
944
|
+
* that several files define and nothing disambiguates them, resolution binds
|
|
945
|
+
* to the first candidate — so without an ORDER BY the winner was decided by
|
|
946
|
+
* rowid, i.e. by the order files happened to be WRITTEN. A full index writes
|
|
947
|
+
* them in scan order; an incremental sync appends each file as it changes, so
|
|
948
|
+
* the same tree resolved to different edges depending on how the index was
|
|
949
|
+
* built, and a long-lived synced index drifted away from a rebuild of itself
|
|
950
|
+
* (measured at 4.3% of distinct edges, mostly `calls`).
|
|
951
|
+
*
|
|
952
|
+
* `(file_path, start_line)` is a property of the CODE, so both paths now pick
|
|
953
|
+
* the same candidate. The sort is paid once per distinct name per resolution
|
|
954
|
+
* run — ReferenceResolver memoizes this in its nameCache — and the population
|
|
955
|
+
* is capped by AMBIGUOUS_NAME_CEILING (#999).
|
|
751
956
|
*/
|
|
752
957
|
getNodesByName(name) {
|
|
753
958
|
if (!this.stmts.getNodesByName) {
|
|
754
|
-
this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ?');
|
|
959
|
+
this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line');
|
|
755
960
|
}
|
|
756
961
|
const rows = this.stmts.getNodesByName.all(name);
|
|
757
962
|
return rows.map(rowToNode);
|
|
@@ -778,13 +983,24 @@ class QueryBuilder {
|
|
|
778
983
|
return rows.map(rowToNode);
|
|
779
984
|
}
|
|
780
985
|
/**
|
|
781
|
-
* Get nodes by
|
|
986
|
+
* Get nodes by name, case-insensitively (seeks the idx_nodes_lower_name
|
|
987
|
+
* expression index).
|
|
988
|
+
*
|
|
989
|
+
* The parameter is lowered in SQL rather than trusted to arrive lowered, so
|
|
990
|
+
* the lookup means the same thing whatever casing a caller hands it. Written
|
|
991
|
+
* as a bare `lower(name) = ?` it silently returned nothing for any input
|
|
992
|
+
* carrying an uppercase letter, and — because SQLite's `lower()` folds ASCII
|
|
993
|
+
* only while JavaScript's `.toLowerCase()` folds Unicode — a caller that
|
|
994
|
+
* pre-lowered in JavaScript could not match a non-ASCII name at all.
|
|
995
|
+
*
|
|
996
|
+
* Note this hardens the query, not its one caller: `matchFuzzy` still lowers
|
|
997
|
+
* in JavaScript before calling, so the non-ASCII gap remains open there.
|
|
782
998
|
*/
|
|
783
|
-
getNodesByLowerName(
|
|
999
|
+
getNodesByLowerName(name) {
|
|
784
1000
|
if (!this.stmts.getNodesByLowerName) {
|
|
785
|
-
this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = ?');
|
|
1001
|
+
this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = lower(?)');
|
|
786
1002
|
}
|
|
787
|
-
const rows = this.stmts.getNodesByLowerName.all(
|
|
1003
|
+
const rows = this.stmts.getNodesByLowerName.all(name);
|
|
788
1004
|
return rows.map(rowToNode);
|
|
789
1005
|
}
|
|
790
1006
|
/**
|
|
@@ -842,12 +1058,25 @@ class QueryBuilder {
|
|
|
842
1058
|
// pushing them past the FTS fetch limit before post-hoc scoring can help.
|
|
843
1059
|
// Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
|
|
844
1060
|
// prefix=20) actually differentiates them after rescoring.
|
|
1061
|
+
//
|
|
1062
|
+
// Whole-name equality MUST be written as `lower(name) = lower(?)` so it
|
|
1063
|
+
// seeks `idx_nodes_lower_name`. The equivalent `name = ? COLLATE NOCASE`
|
|
1064
|
+
// matches no index — `idx_nodes_name` is BINARY-collated and the expression
|
|
1065
|
+
// index only matches the same expression — and degrades to a full table
|
|
1066
|
+
// scan. The `LIMIT 20` does not rescue it: SQLite can only stop early once
|
|
1067
|
+
// it has produced 20 rows, and this runs once per query term, most of which
|
|
1068
|
+
// name nothing in the corpus. Measured per term on an unmatched term:
|
|
1069
|
+
// 0.08ms on gin (2.5k nodes), 0.39ms on excalidraw (11k), 2.4ms on django
|
|
1070
|
+
// (62k) — and growing with the corpus, where the seek is flat at ~0.002ms.
|
|
1071
|
+
// Lowering the parameter in SQL rather than in JS is deliberate: SQLite's
|
|
1072
|
+
// `lower()` and NOCASE both fold ASCII only, while JS `.toLowerCase()`
|
|
1073
|
+
// folds Unicode, which would silently stop matching non-ASCII names.
|
|
845
1074
|
if (results.length > 0 && query) {
|
|
846
1075
|
const existingIds = new Set(results.map(r => r.node.id));
|
|
847
1076
|
const maxFtsScore = Math.max(...results.map(r => r.score));
|
|
848
1077
|
const terms = query.split(/\s+/).filter(t => t.length >= 2);
|
|
849
1078
|
for (const term of terms) {
|
|
850
|
-
let sql = 'SELECT * FROM nodes WHERE name = ?
|
|
1079
|
+
let sql = 'SELECT * FROM nodes WHERE lower(name) = lower(?)';
|
|
851
1080
|
const params = [term];
|
|
852
1081
|
if (kinds && kinds.length > 0) {
|
|
853
1082
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -870,13 +1099,24 @@ class QueryBuilder {
|
|
|
870
1099
|
// Apply multi-signal scoring
|
|
871
1100
|
if (results.length > 0 && (text || query)) {
|
|
872
1101
|
const scoringQuery = text || query;
|
|
873
|
-
results = results.map(r =>
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1102
|
+
results = results.map(r => {
|
|
1103
|
+
// A path the project de-prioritized is saying its symbol NAMES are not
|
|
1104
|
+
// the answer, so the exact-name bonus has to be damped too. The -15 path
|
|
1105
|
+
// penalty alone cannot do it: the bonus is additive and larger (measured
|
|
1106
|
+
// on #982's repro, a `usage()` helper sat at 74.8 vs 51.2 for the top
|
|
1107
|
+
// product symbol — -15 lands at 59.8, still ahead). Damped, not zeroed,
|
|
1108
|
+
// so the tree stays findable when it genuinely is what you asked for.
|
|
1109
|
+
// Evaluated once and reused: the predicate stats the config file.
|
|
1110
|
+
const deprioritized = this.isDeprioritizedPath?.(r.node.filePath) ?? false;
|
|
1111
|
+
const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
|
|
1112
|
+
return {
|
|
1113
|
+
...r,
|
|
1114
|
+
score: r.score
|
|
1115
|
+
+ (0, query_utils_1.kindBonus)(r.node.kind)
|
|
1116
|
+
+ (0, query_utils_1.scorePathRelevance)(r.node.filePath, scoringQuery, this.projectNameTokens, deprioritized)
|
|
1117
|
+
+ (deprioritized ? Math.round(nameBonus * exports.DEPRIORITIZED_NAME_BONUS_SCALE) : nameBonus),
|
|
1118
|
+
};
|
|
1119
|
+
});
|
|
880
1120
|
results.sort((a, b) => b.score - a.score);
|
|
881
1121
|
// Trim to requested limit after rescoring
|
|
882
1122
|
if (results.length > limit) {
|
|
@@ -1115,9 +1355,16 @@ class QueryBuilder {
|
|
|
1115
1355
|
// Pass 1: Find which files contain distinctive (rare) symbols from the query.
|
|
1116
1356
|
// Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
|
|
1117
1357
|
// Pass 1: Find files containing each queried name, identify distinctive names
|
|
1358
|
+
//
|
|
1359
|
+
// Both passes spell whole-name equality as `lower(name) = lower(?)` so they
|
|
1360
|
+
// seek `idx_nodes_lower_name` — see the note in `searchNodes` for why the
|
|
1361
|
+
// `name = ? COLLATE NOCASE` form full-scans instead. This path is the one
|
|
1362
|
+
// that hurts most: it runs both passes for every symbol extracted from the
|
|
1363
|
+
// query, and extraction is generous, so most of those names are absent from
|
|
1364
|
+
// the corpus and never reach either LIMIT.
|
|
1118
1365
|
const nameToFiles = new Map();
|
|
1119
1366
|
for (const name of names) {
|
|
1120
|
-
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE name
|
|
1367
|
+
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
|
|
1121
1368
|
const params = [name];
|
|
1122
1369
|
if (kinds && kinds.length > 0) {
|
|
1123
1370
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1143,7 +1390,7 @@ class QueryBuilder {
|
|
|
1143
1390
|
let sql = `
|
|
1144
1391
|
SELECT nodes.*, 1.0 as score
|
|
1145
1392
|
FROM nodes
|
|
1146
|
-
WHERE name
|
|
1393
|
+
WHERE lower(name) = lower(?)
|
|
1147
1394
|
`;
|
|
1148
1395
|
const params = [name];
|
|
1149
1396
|
if (kinds && kinds.length > 0) {
|
|
@@ -1250,12 +1497,22 @@ class QueryBuilder {
|
|
|
1250
1497
|
endpointIds.add(edge.target);
|
|
1251
1498
|
}
|
|
1252
1499
|
const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
|
|
1500
|
+
const rows = [];
|
|
1253
1501
|
for (const edge of edges) {
|
|
1254
1502
|
if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
|
|
1255
1503
|
continue;
|
|
1256
1504
|
}
|
|
1257
|
-
|
|
1505
|
+
rows.push([
|
|
1506
|
+
edge.source,
|
|
1507
|
+
edge.target,
|
|
1508
|
+
edge.kind,
|
|
1509
|
+
edge.metadata ? JSON.stringify(edge.metadata) : null,
|
|
1510
|
+
edge.line ?? null,
|
|
1511
|
+
edge.column ?? null,
|
|
1512
|
+
edge.provenance ?? null,
|
|
1513
|
+
]);
|
|
1258
1514
|
}
|
|
1515
|
+
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
1259
1516
|
})();
|
|
1260
1517
|
}
|
|
1261
1518
|
/**
|
|
@@ -1404,8 +1661,8 @@ class QueryBuilder {
|
|
|
1404
1661
|
upsertFile(file) {
|
|
1405
1662
|
if (!this.stmts.upsertFile) {
|
|
1406
1663
|
this.stmts.upsertFile = this.db.prepare(`
|
|
1407
|
-
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors)
|
|
1408
|
-
VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors)
|
|
1664
|
+
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors, generated)
|
|
1665
|
+
VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors, @generated)
|
|
1409
1666
|
ON CONFLICT(path) DO UPDATE SET
|
|
1410
1667
|
content_hash = @contentHash,
|
|
1411
1668
|
language = @language,
|
|
@@ -1413,7 +1670,8 @@ class QueryBuilder {
|
|
|
1413
1670
|
modified_at = @modifiedAt,
|
|
1414
1671
|
indexed_at = @indexedAt,
|
|
1415
1672
|
node_count = @nodeCount,
|
|
1416
|
-
errors = @errors
|
|
1673
|
+
errors = @errors,
|
|
1674
|
+
generated = @generated
|
|
1417
1675
|
`);
|
|
1418
1676
|
}
|
|
1419
1677
|
this.stmts.upsertFile.run({
|
|
@@ -1425,8 +1683,149 @@ class QueryBuilder {
|
|
|
1425
1683
|
indexedAt: file.indexedAt,
|
|
1426
1684
|
nodeCount: file.nodeCount,
|
|
1427
1685
|
errors: file.errors ? JSON.stringify(file.errors) : null,
|
|
1686
|
+
// The upsert always REWRITES the flag: a file that loses its banner in an
|
|
1687
|
+
// edit must lose the flag on the next sync, not keep a stale 1.
|
|
1688
|
+
generated: file.generated ? 1 : 0,
|
|
1428
1689
|
});
|
|
1429
1690
|
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Which of `filePaths` the index flagged as tool-generated (schema v9+).
|
|
1693
|
+
*
|
|
1694
|
+
* Bounded-lookup by design: every consumer already holds a short candidate
|
|
1695
|
+
* list (a ranked file group, an FTS result page, a LIMIT-20 aggregate), so
|
|
1696
|
+
* this stays a partial-index probe over a handful of paths — no whole-repo
|
|
1697
|
+
* set to materialize, and no cache to invalidate, which means a ranking call
|
|
1698
|
+
* can never serve a verdict the last sync already replaced.
|
|
1699
|
+
*
|
|
1700
|
+
* Returns ONLY the content/index signal; callers union it with
|
|
1701
|
+
* {@link isGeneratedFile} so pre-v9 databases (column present, all zeros
|
|
1702
|
+
* until a re-index) keep the path-only behavior rather than regressing.
|
|
1703
|
+
*/
|
|
1704
|
+
getGeneratedPathsAmong(filePaths) {
|
|
1705
|
+
const unique = [...new Set(filePaths)];
|
|
1706
|
+
const found = new Set();
|
|
1707
|
+
if (unique.length === 0)
|
|
1708
|
+
return found;
|
|
1709
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1710
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1711
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1712
|
+
const rows = this.db
|
|
1713
|
+
.prepare(`SELECT path FROM files WHERE generated = 1 AND path IN (${placeholders})`)
|
|
1714
|
+
.all(...chunk);
|
|
1715
|
+
for (const row of rows)
|
|
1716
|
+
found.add(row.path);
|
|
1717
|
+
}
|
|
1718
|
+
return found;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* A reusable `(path) => boolean` over a bounded candidate list, unioning the
|
|
1722
|
+
* indexed flag with the path convention. This is the shape every ranking
|
|
1723
|
+
* comparator wants: one query up front, then O(1) per comparison.
|
|
1724
|
+
*/
|
|
1725
|
+
generatedPredicateFor(filePaths) {
|
|
1726
|
+
const flagged = this.getGeneratedPathsAmong(filePaths);
|
|
1727
|
+
return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing
|
|
1731
|
+
* but types, and nothing in the index depends on them (CG-28). A hand-written
|
|
1732
|
+
* ambient `.d.ts` of global shims, a vendored typings file, module
|
|
1733
|
+
* augmentation: reachable only by name, structurally attached to nothing.
|
|
1734
|
+
*
|
|
1735
|
+
* Structural, not extension-based, so a hand-written `types.ts` and a `.d.ts`
|
|
1736
|
+
* are judged by the same rule and a `.d.ts` that does declare a class or a
|
|
1737
|
+
* const is (correctly) not caught. Four conditions, all required:
|
|
1738
|
+
*
|
|
1739
|
+
* 1. it declares at least one symbol — an empty or unparsed file is not a
|
|
1740
|
+
* declaration file, it is a file we know nothing about;
|
|
1741
|
+
* 2. EVERY declared symbol is a type-level kind (interface / type alias /
|
|
1742
|
+
* enum / namespace). The narrowness is deliberate and measured: a rule
|
|
1743
|
+
* of "no callables" alone flags 1–18% of a repo, including Kotlin sealed
|
|
1744
|
+
* classes, Rust `mod.rs` re-exports and django's locale constant tables —
|
|
1745
|
+
* real source that must not be demoted. This rule flags 0–4%;
|
|
1746
|
+
* 3. no symbol in it originates a `calls`/`instantiates` edge — the direct
|
|
1747
|
+
* evidence that nothing here has a body;
|
|
1748
|
+
* 4. NOTHING ELSE IN THE INDEX points at it. This is the condition that
|
|
1749
|
+
* separates an ambient shim from a working type module, and it is why
|
|
1750
|
+
* the flag is narrow enough to be safe: `displacement-ts`'s pipeline
|
|
1751
|
+
* `types.ts` passes 1–3 identically but carries 13 inbound imports and
|
|
1752
|
+
* 21 references, so the files that answer a query about the pipeline are
|
|
1753
|
+
* typed BY it — it is part of that answer's structure. An ambient
|
|
1754
|
+
* `declare global` shim has zero. Deliberately index-wide rather than
|
|
1755
|
+
* restricted to the candidate list: the file that imports it is usually
|
|
1756
|
+
* not itself a candidate.
|
|
1757
|
+
*
|
|
1758
|
+
* Bounded-lookup like {@link getGeneratedPathsAmong}: callers hold a ranked
|
|
1759
|
+
* candidate list, so this is a partial-index probe over a handful of paths.
|
|
1760
|
+
*/
|
|
1761
|
+
getAmbientDeclarationPathsAmong(filePaths) {
|
|
1762
|
+
const unique = [...new Set(filePaths)];
|
|
1763
|
+
const found = new Set();
|
|
1764
|
+
if (unique.length === 0)
|
|
1765
|
+
return found;
|
|
1766
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1767
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1768
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1769
|
+
// `file`/`import`/`export`/`parameter` are structural bookkeeping, not
|
|
1770
|
+
// things the file declares, so they neither qualify nor disqualify.
|
|
1771
|
+
const rows = this.db
|
|
1772
|
+
.prepare(`
|
|
1773
|
+
SELECT file_path,
|
|
1774
|
+
SUM(CASE WHEN kind NOT IN ('file','import','export','parameter')
|
|
1775
|
+
THEN 1 ELSE 0 END) AS declared,
|
|
1776
|
+
SUM(CASE WHEN kind IN ('interface','type_alias','enum','enum_member','namespace')
|
|
1777
|
+
THEN 1 ELSE 0 END) AS typeDeclared
|
|
1778
|
+
FROM nodes
|
|
1779
|
+
WHERE file_path IN (${placeholders})
|
|
1780
|
+
GROUP BY file_path
|
|
1781
|
+
`)
|
|
1782
|
+
.all(...chunk);
|
|
1783
|
+
let candidates = rows
|
|
1784
|
+
.filter((r) => r.declared > 0 && r.declared === r.typeDeclared)
|
|
1785
|
+
.map((r) => r.file_path);
|
|
1786
|
+
if (candidates.length === 0)
|
|
1787
|
+
continue;
|
|
1788
|
+
const disqualify = (sql) => {
|
|
1789
|
+
if (candidates.length === 0)
|
|
1790
|
+
return;
|
|
1791
|
+
const hit = new Set(this.db
|
|
1792
|
+
.prepare(sql.replace('$IN$', candidates.map(() => '?').join(',')))
|
|
1793
|
+
.all(...candidates).map((r) => r.file_path));
|
|
1794
|
+
candidates = candidates.filter((p) => !hit.has(p));
|
|
1795
|
+
};
|
|
1796
|
+
// (3) originates behaviour
|
|
1797
|
+
disqualify(`
|
|
1798
|
+
SELECT DISTINCT n.file_path AS file_path
|
|
1799
|
+
FROM edges e JOIN nodes n ON n.id = e.source
|
|
1800
|
+
WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
|
|
1801
|
+
`);
|
|
1802
|
+
// (4) something outside the file depends on it
|
|
1803
|
+
disqualify(`
|
|
1804
|
+
SELECT DISTINCT t.file_path AS file_path
|
|
1805
|
+
FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
|
|
1806
|
+
WHERE t.file_path IN ($IN$) AND s.file_path <> t.file_path
|
|
1807
|
+
`);
|
|
1808
|
+
for (const path of candidates)
|
|
1809
|
+
found.add(path);
|
|
1810
|
+
}
|
|
1811
|
+
return found;
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* A reusable `(path) => boolean` ambient-declaration test over a bounded
|
|
1815
|
+
* candidate list — the shape a ranking comparator wants: one query up front,
|
|
1816
|
+
* O(1) per comparison.
|
|
1817
|
+
*/
|
|
1818
|
+
ambientDeclarationPredicateFor(filePaths) {
|
|
1819
|
+
const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
|
|
1820
|
+
return (filePath) => flagged.has(filePath);
|
|
1821
|
+
}
|
|
1822
|
+
/** How many indexed files carry the generated flag. Surfaced by `status`. */
|
|
1823
|
+
countGeneratedFiles() {
|
|
1824
|
+
const row = this.db
|
|
1825
|
+
.prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
|
|
1826
|
+
.get();
|
|
1827
|
+
return row?.n ?? 0;
|
|
1828
|
+
}
|
|
1430
1829
|
/**
|
|
1431
1830
|
* Delete a file record and its nodes
|
|
1432
1831
|
*/
|
|
@@ -1510,9 +1909,20 @@ class QueryBuilder {
|
|
|
1510
1909
|
if (refs.length === 0)
|
|
1511
1910
|
return;
|
|
1512
1911
|
const insert = this.db.transaction(() => {
|
|
1912
|
+
const rows = [];
|
|
1513
1913
|
for (const ref of refs) {
|
|
1514
|
-
|
|
1914
|
+
rows.push([
|
|
1915
|
+
ref.fromNodeId,
|
|
1916
|
+
ref.referenceName,
|
|
1917
|
+
ref.referenceKind,
|
|
1918
|
+
ref.line,
|
|
1919
|
+
ref.column,
|
|
1920
|
+
ref.candidates ? JSON.stringify(ref.candidates) : null,
|
|
1921
|
+
ref.filePath ?? '',
|
|
1922
|
+
ref.language ?? 'unknown',
|
|
1923
|
+
]);
|
|
1515
1924
|
}
|
|
1925
|
+
this.runBatched('insertUnresolvedRefs', 'INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language) VALUES ', '(?,?,?,?,?,?,?,?)', rows);
|
|
1516
1926
|
});
|
|
1517
1927
|
insert();
|
|
1518
1928
|
}
|
|
@@ -1542,6 +1952,7 @@ class QueryBuilder {
|
|
|
1542
1952
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1543
1953
|
filePath: row.file_path,
|
|
1544
1954
|
language: row.language,
|
|
1955
|
+
rowId: row.id,
|
|
1545
1956
|
}));
|
|
1546
1957
|
}
|
|
1547
1958
|
/**
|
|
@@ -1558,6 +1969,7 @@ class QueryBuilder {
|
|
|
1558
1969
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1559
1970
|
filePath: row.file_path,
|
|
1560
1971
|
language: row.language,
|
|
1972
|
+
rowId: row.id,
|
|
1561
1973
|
}));
|
|
1562
1974
|
}
|
|
1563
1975
|
/**
|
|
@@ -1582,7 +1994,12 @@ class QueryBuilder {
|
|
|
1582
1994
|
*/
|
|
1583
1995
|
getUnresolvedReferencesBatch(offset, limit) {
|
|
1584
1996
|
if (!this.stmts.getUnresolvedBatch) {
|
|
1585
|
-
|
|
1997
|
+
// ORDER BY rowid is load-bearing for the pipelined resolution loop: it
|
|
1998
|
+
// prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
|
|
1999
|
+
// still pending, which is only exact under a stable enumeration. (A plain
|
|
2000
|
+
// scan and the status index both return rowid order anyway — this pins
|
|
2001
|
+
// it.)
|
|
2002
|
+
this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
|
|
1586
2003
|
}
|
|
1587
2004
|
const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
|
|
1588
2005
|
return rows.map((row) => ({
|
|
@@ -1594,6 +2011,32 @@ class QueryBuilder {
|
|
|
1594
2011
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1595
2012
|
filePath: row.file_path,
|
|
1596
2013
|
language: row.language,
|
|
2014
|
+
rowId: row.id,
|
|
2015
|
+
}));
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
|
|
2019
|
+
* resolution loop: seek past the last-seen row id instead of OFFSET-walking.
|
|
2020
|
+
* OFFSET reads re-scan the accumulated failed-row prefix on every batch —
|
|
2021
|
+
* O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
|
|
2022
|
+
* (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
|
|
2023
|
+
* the enumeration order is identical to the OFFSET reader's.
|
|
2024
|
+
*/
|
|
2025
|
+
getUnresolvedReferencesBatchAfter(afterRowId, limit) {
|
|
2026
|
+
if (!this.stmts.getUnresolvedBatchAfter) {
|
|
2027
|
+
this.stmts.getUnresolvedBatchAfter = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' AND id > ? ORDER BY id LIMIT ?");
|
|
2028
|
+
}
|
|
2029
|
+
const rows = this.stmts.getUnresolvedBatchAfter.all(afterRowId, limit);
|
|
2030
|
+
return rows.map((row) => ({
|
|
2031
|
+
fromNodeId: row.from_node_id,
|
|
2032
|
+
referenceName: row.reference_name,
|
|
2033
|
+
referenceKind: row.reference_kind,
|
|
2034
|
+
line: row.line,
|
|
2035
|
+
column: row.col,
|
|
2036
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2037
|
+
filePath: row.file_path,
|
|
2038
|
+
language: row.language,
|
|
2039
|
+
rowId: row.id,
|
|
1597
2040
|
}));
|
|
1598
2041
|
}
|
|
1599
2042
|
/**
|
|
@@ -1646,7 +2089,13 @@ class QueryBuilder {
|
|
|
1646
2089
|
const chunkRows = this.db
|
|
1647
2090
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
|
|
1648
2091
|
.all(...chunk);
|
|
1649
|
-
|
|
2092
|
+
// Append with a loop, never a spread: the INPUT chunk is bounded, but
|
|
2093
|
+
// the RESULT rows per chunk are not — a dense recovery sync (e.g. the
|
|
2094
|
+
// #1541 self-heal re-indexing hundreds of files) returns more rows than
|
|
2095
|
+
// V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum
|
|
2096
|
+
// call stack size exceeded", aborting resolution mid-sync (#1558).
|
|
2097
|
+
for (const row of chunkRows)
|
|
2098
|
+
rows.push(row);
|
|
1650
2099
|
}
|
|
1651
2100
|
return rows.map((row) => ({
|
|
1652
2101
|
fromNodeId: row.from_node_id,
|
|
@@ -1657,6 +2106,7 @@ class QueryBuilder {
|
|
|
1657
2106
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1658
2107
|
filePath: row.file_path,
|
|
1659
2108
|
language: row.language,
|
|
2109
|
+
rowId: row.id,
|
|
1660
2110
|
}));
|
|
1661
2111
|
}
|
|
1662
2112
|
/**
|
|
@@ -1688,14 +2138,55 @@ class QueryBuilder {
|
|
|
1688
2138
|
*/
|
|
1689
2139
|
deleteSpecificResolvedReferences(refs) {
|
|
1690
2140
|
if (refs.length === 0)
|
|
1691
|
-
return;
|
|
2141
|
+
return 0;
|
|
1692
2142
|
const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
|
|
2143
|
+
// Returns rows actually removed (SQLite `changes`, summed): the batched
|
|
2144
|
+
// resolution loop's non-progress guard keys on this — zero removals from
|
|
2145
|
+
// a batch that claimed work is the direct runaway signal (§7a.2).
|
|
2146
|
+
let changed = 0;
|
|
1693
2147
|
const deleteMany = this.db.transaction((items) => {
|
|
1694
2148
|
for (const ref of items) {
|
|
1695
|
-
stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
|
|
2149
|
+
changed += stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
1696
2150
|
}
|
|
1697
2151
|
});
|
|
1698
2152
|
deleteMany(refs);
|
|
2153
|
+
return changed;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Delete unresolved-ref rows by row id — the precise cleanup for refs a
|
|
2157
|
+
* resolution pass actually processed. The key-tuple variant above also
|
|
2158
|
+
* deletes SIBLING rows (same caller calling the same callee at other lines)
|
|
2159
|
+
* that a later batch hasn't attempted yet, so when a batch boundary split a
|
|
2160
|
+
* caller's same-named call sites, the later sites' edges were silently never
|
|
2161
|
+
* created (#1269).
|
|
2162
|
+
*/
|
|
2163
|
+
deleteReferencesByRowIds(rowIds) {
|
|
2164
|
+
if (rowIds.length === 0)
|
|
2165
|
+
return 0;
|
|
2166
|
+
// One transaction for all chunks (each chunk was previously its own
|
|
2167
|
+
// implicit transaction = its own WAL commit — measurable on 100k+-ref
|
|
2168
|
+
// resolution persists), and the full-size chunk statement is cached so
|
|
2169
|
+
// repeat calls skip the re-prepare; only the final partial chunk (if any)
|
|
2170
|
+
// prepares ad hoc. Returns rows actually removed (summed `changes`) for
|
|
2171
|
+
// the batched loop's non-progress guard (§7a.2).
|
|
2172
|
+
let changed = 0;
|
|
2173
|
+
this.db.transaction(() => {
|
|
2174
|
+
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2175
|
+
const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2176
|
+
if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
|
|
2177
|
+
if (!this.stmts.deleteRefsByRowIdsFull) {
|
|
2178
|
+
const placeholders = new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',');
|
|
2179
|
+
this.stmts.deleteRefsByRowIdsFull = this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`);
|
|
2180
|
+
}
|
|
2181
|
+
changed += this.stmts.deleteRefsByRowIdsFull.run(...chunk).changes;
|
|
2182
|
+
}
|
|
2183
|
+
else {
|
|
2184
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2185
|
+
changed += this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`).run(...chunk).changes;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
})();
|
|
2189
|
+
return changed;
|
|
1699
2190
|
}
|
|
1700
2191
|
/**
|
|
1701
2192
|
* Mark refs a completed resolution pass could not resolve as status='failed'
|
|
@@ -1708,14 +2199,37 @@ class QueryBuilder {
|
|
|
1708
2199
|
*/
|
|
1709
2200
|
markReferencesFailed(refs) {
|
|
1710
2201
|
if (refs.length === 0)
|
|
1711
|
-
return;
|
|
2202
|
+
return 0;
|
|
1712
2203
|
const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?");
|
|
2204
|
+
let changed = 0;
|
|
1713
2205
|
const markMany = this.db.transaction((items) => {
|
|
1714
2206
|
for (const ref of items) {
|
|
1715
|
-
stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind);
|
|
2207
|
+
changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
1716
2208
|
}
|
|
1717
2209
|
});
|
|
1718
2210
|
markMany(refs);
|
|
2211
|
+
return changed;
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Park refs as status='failed' by row id — the precise counterpart of
|
|
2215
|
+
* markReferencesFailed, for the same reason as deleteReferencesByRowIds:
|
|
2216
|
+
* the key-tuple variant also flips same-key sibling rows in later batches
|
|
2217
|
+
* to 'failed' before they were ever attempted (#1269). Resolution outcome
|
|
2218
|
+
* can differ per call site (receiver-type inference reads the ref's line),
|
|
2219
|
+
* so a sibling must not inherit this row's failure.
|
|
2220
|
+
*/
|
|
2221
|
+
markReferencesFailedByRowIds(refs) {
|
|
2222
|
+
if (refs.length === 0)
|
|
2223
|
+
return 0;
|
|
2224
|
+
const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE id = ?");
|
|
2225
|
+
let changed = 0;
|
|
2226
|
+
const markMany = this.db.transaction((items) => {
|
|
2227
|
+
for (const ref of items) {
|
|
2228
|
+
changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
markMany(refs);
|
|
2232
|
+
return changed;
|
|
1719
2233
|
}
|
|
1720
2234
|
/**
|
|
1721
2235
|
* Failed refs whose name tail matches one of the given symbol names — the
|
|
@@ -1752,7 +2266,11 @@ class QueryBuilder {
|
|
|
1752
2266
|
const chunkRows = this.db
|
|
1753
2267
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
|
|
1754
2268
|
.all(...chunk);
|
|
1755
|
-
|
|
2269
|
+
// Loop, not spread — same V8 argument-limit hazard as
|
|
2270
|
+
// getUnresolvedReferencesByFiles (#1558): a large definition delta can
|
|
2271
|
+
// select an unbounded number of failed rows per chunk.
|
|
2272
|
+
for (const row of chunkRows)
|
|
2273
|
+
rows.push(row);
|
|
1756
2274
|
}
|
|
1757
2275
|
return rows.map((row) => ({
|
|
1758
2276
|
fromNodeId: row.from_node_id,
|
|
@@ -1763,8 +2281,95 @@ class QueryBuilder {
|
|
|
1763
2281
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1764
2282
|
filePath: row.file_path,
|
|
1765
2283
|
language: row.language,
|
|
2284
|
+
rowId: row.id,
|
|
1766
2285
|
}));
|
|
1767
2286
|
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Resolution edges whose TARGET symbol is named one of `names` — the edges a
|
|
2289
|
+
* sync must re-resolve after `names` gained or lost a definition (CG-33).
|
|
2290
|
+
*
|
|
2291
|
+
* Resolution binds a reference to a node whose name matches the reference's
|
|
2292
|
+
* tail, and it picks among ALL same-named definitions project-wide. So adding
|
|
2293
|
+
* or removing one definition of `pct` changes the answer for every `pct(...)`
|
|
2294
|
+
* reference in the repo — including references in files this sync never
|
|
2295
|
+
* touches, whose edges nothing else revisits. Those edges' current target is,
|
|
2296
|
+
* by that same rule, a node named `pct`, which is why the target's name is a
|
|
2297
|
+
* sufficient (and index-backed, via idx_nodes_name) way to find them without
|
|
2298
|
+
* a schema change or a scan of edge metadata.
|
|
2299
|
+
*
|
|
2300
|
+
* Returns the source file/language alongside each edge so the caller can
|
|
2301
|
+
* resurrect it as its original reference. Excludes `provenance='heuristic'`
|
|
2302
|
+
* (synthesized dispatch edges are not resolution output and carry no refName
|
|
2303
|
+
* stamp to resurrect from — deleting one would be a permanent loss).
|
|
2304
|
+
*
|
|
2305
|
+
* Names matching more than `perNameCeiling` edges are skipped entirely, same
|
|
2306
|
+
* rationale and same default as {@link getRetryableFailedReferences}: at that
|
|
2307
|
+
* population the name is generic (`get`, `clear`, …), one definition changing
|
|
2308
|
+
* won't flip most of them, and rebinding an arbitrary subset is both wasted
|
|
2309
|
+
* work and incoherent coverage.
|
|
2310
|
+
*/
|
|
2311
|
+
getResolutionEdgesByTargetName(names, perNameCeiling = 500) {
|
|
2312
|
+
if (names.length === 0)
|
|
2313
|
+
return [];
|
|
2314
|
+
// Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
|
|
2315
|
+
const keep = [];
|
|
2316
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2317
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2318
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2319
|
+
const counts = this.db
|
|
2320
|
+
.prepare(`SELECT tgt.name AS name, COUNT(*) AS count
|
|
2321
|
+
FROM edges e
|
|
2322
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2323
|
+
WHERE tgt.name IN (${placeholders})
|
|
2324
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
2325
|
+
GROUP BY tgt.name`)
|
|
2326
|
+
.all(...chunk);
|
|
2327
|
+
for (const row of counts) {
|
|
2328
|
+
if (row.count <= perNameCeiling)
|
|
2329
|
+
keep.push(row.name);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
if (keep.length === 0)
|
|
2333
|
+
return [];
|
|
2334
|
+
// Pass 2: load the surviving edges with the source file context a
|
|
2335
|
+
// resurrection needs.
|
|
2336
|
+
const out = [];
|
|
2337
|
+
for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2338
|
+
const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2339
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2340
|
+
const rows = this.db
|
|
2341
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
2342
|
+
FROM edges e
|
|
2343
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
2344
|
+
JOIN nodes src ON src.id = e.source
|
|
2345
|
+
WHERE tgt.name IN (${placeholders})
|
|
2346
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
2347
|
+
.all(...chunk);
|
|
2348
|
+
for (const row of rows) {
|
|
2349
|
+
out.push({
|
|
2350
|
+
...rowToEdge(row),
|
|
2351
|
+
edgeId: row.id,
|
|
2352
|
+
sourceFilePath: row.source_file_path,
|
|
2353
|
+
sourceLanguage: row.source_language,
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
return out;
|
|
2358
|
+
}
|
|
2359
|
+
/** Delete edges by primary key — the rebind pass's half of a re-resolution. */
|
|
2360
|
+
deleteEdgesByIds(edgeIds) {
|
|
2361
|
+
if (edgeIds.length === 0)
|
|
2362
|
+
return 0;
|
|
2363
|
+
let changed = 0;
|
|
2364
|
+
this.db.transaction(() => {
|
|
2365
|
+
for (let i = 0; i < edgeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2366
|
+
const chunk = edgeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2367
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2368
|
+
changed += this.db.prepare(`DELETE FROM edges WHERE id IN (${placeholders})`).run(...chunk).changes;
|
|
2369
|
+
}
|
|
2370
|
+
})();
|
|
2371
|
+
return changed;
|
|
2372
|
+
}
|
|
1768
2373
|
/**
|
|
1769
2374
|
* Distinct node names present in the given files — the symbol names a sync
|
|
1770
2375
|
* pass uses to look up retryable failed refs after those files changed.
|
|
@@ -1784,6 +2389,34 @@ class QueryBuilder {
|
|
|
1784
2389
|
}
|
|
1785
2390
|
return [...names];
|
|
1786
2391
|
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Distinct `file\0name` pairs defined by the given files — the shape sync's
|
|
2394
|
+
* definition delta needs (CG-33).
|
|
2395
|
+
*
|
|
2396
|
+
* Deliberately NOT `getNodeNamesByFiles`: a bare name set is taken over the
|
|
2397
|
+
* WHOLE changed batch, so a name that moves between two files in one commit
|
|
2398
|
+
* (or exists in one changed file and is newly added to another) appears on
|
|
2399
|
+
* both sides and cancels out of the symmetric difference — even though a
|
|
2400
|
+
* definition genuinely appeared or vanished and every reference to that name
|
|
2401
|
+
* repo-wide may now bind elsewhere. Keying by file makes each definition its
|
|
2402
|
+
* own fact, so the move is seen as one removal plus one addition.
|
|
2403
|
+
*/
|
|
2404
|
+
getNodeNamePairsByFiles(filePaths) {
|
|
2405
|
+
const pairs = new Set();
|
|
2406
|
+
if (filePaths.length === 0)
|
|
2407
|
+
return pairs;
|
|
2408
|
+
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2409
|
+
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2410
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2411
|
+
const rows = this.db
|
|
2412
|
+
.prepare(`SELECT DISTINCT file_path, name FROM nodes WHERE file_path IN (${placeholders})`)
|
|
2413
|
+
.all(...chunk);
|
|
2414
|
+
// NUL-joined: a path or a symbol name can contain a space, never a NUL.
|
|
2415
|
+
for (const row of rows)
|
|
2416
|
+
pairs.add(`${row.file_path}\0${row.name}`);
|
|
2417
|
+
}
|
|
2418
|
+
return pairs;
|
|
2419
|
+
}
|
|
1787
2420
|
// ===========================================================================
|
|
1788
2421
|
// Statistics
|
|
1789
2422
|
// ===========================================================================
|
|
@@ -1839,6 +2472,7 @@ class QueryBuilder {
|
|
|
1839
2472
|
edgesByKind,
|
|
1840
2473
|
filesByLanguage,
|
|
1841
2474
|
dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
|
|
2475
|
+
walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
|
|
1842
2476
|
lastUpdated: Date.now(),
|
|
1843
2477
|
};
|
|
1844
2478
|
}
|