@colbymchenry/codegraph-win32-arm64 1.5.0 → 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/lib/dist/bin/codegraph.js +145 -29
- 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 +60 -14
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +37 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +101 -1
- 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 +160 -3
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +400 -33
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +16 -3
- 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 +38 -2
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +106 -0
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +284 -53
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +19 -4
- 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 +7 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +20 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/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 +5 -1
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +106 -50
- package/lib/dist/extraction/tree-sitter.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 +22 -0
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +117 -1
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +8 -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 +2402 -241
- 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.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +21 -19
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +39 -11
- package/lib/dist/resolution/callback-synthesizer.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.map +1 -1
- package/lib/dist/resolution/import-resolver.js +18 -2
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +15 -4
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/name-matcher.d.ts +30 -0
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +295 -5
- 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/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 +22 -0
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +51 -5
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +20 -1
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +1 -0
- package/lib/dist/types.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 +1 -1
- package/package.json +1 -1
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;
|
|
@@ -193,6 +220,19 @@ class QueryBuilder {
|
|
|
193
220
|
getProjectNameTokens() {
|
|
194
221
|
return this.projectNameTokens;
|
|
195
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
|
+
}
|
|
196
236
|
// ===========================================================================
|
|
197
237
|
// Node Operations
|
|
198
238
|
// ===========================================================================
|
|
@@ -726,7 +766,8 @@ class QueryBuilder {
|
|
|
726
766
|
`);
|
|
727
767
|
}
|
|
728
768
|
const rows = this.stmts.getDominantFile.all();
|
|
729
|
-
const
|
|
769
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
770
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
730
771
|
if (filtered.length === 0 || filtered[0].edge_count < 20)
|
|
731
772
|
return null;
|
|
732
773
|
return {
|
|
@@ -759,7 +800,8 @@ class QueryBuilder {
|
|
|
759
800
|
`);
|
|
760
801
|
}
|
|
761
802
|
const rows = this.stmts.getTopRouteFile.all();
|
|
762
|
-
const
|
|
803
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
804
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
763
805
|
if (filtered.length === 0)
|
|
764
806
|
return null;
|
|
765
807
|
const totalRoutes = filtered.reduce((sum, r) => sum + r.cnt, 0);
|
|
@@ -805,7 +847,8 @@ class QueryBuilder {
|
|
|
805
847
|
}
|
|
806
848
|
const rows = this.stmts.getRoutingManifest.all(limit);
|
|
807
849
|
// Drop test/generated handlers — same hygiene as elsewhere.
|
|
808
|
-
const
|
|
850
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
|
|
851
|
+
const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
|
|
809
852
|
if (filtered.length < 3)
|
|
810
853
|
return null;
|
|
811
854
|
// Identify the file holding the most handlers (the "primary handler file").
|
|
@@ -894,11 +937,26 @@ class QueryBuilder {
|
|
|
894
937
|
return new Set(rows.map((r) => r.language));
|
|
895
938
|
}
|
|
896
939
|
/**
|
|
897
|
-
* 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).
|
|
898
956
|
*/
|
|
899
957
|
getNodesByName(name) {
|
|
900
958
|
if (!this.stmts.getNodesByName) {
|
|
901
|
-
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');
|
|
902
960
|
}
|
|
903
961
|
const rows = this.stmts.getNodesByName.all(name);
|
|
904
962
|
return rows.map(rowToNode);
|
|
@@ -925,13 +983,24 @@ class QueryBuilder {
|
|
|
925
983
|
return rows.map(rowToNode);
|
|
926
984
|
}
|
|
927
985
|
/**
|
|
928
|
-
* 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.
|
|
929
998
|
*/
|
|
930
|
-
getNodesByLowerName(
|
|
999
|
+
getNodesByLowerName(name) {
|
|
931
1000
|
if (!this.stmts.getNodesByLowerName) {
|
|
932
|
-
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(?)');
|
|
933
1002
|
}
|
|
934
|
-
const rows = this.stmts.getNodesByLowerName.all(
|
|
1003
|
+
const rows = this.stmts.getNodesByLowerName.all(name);
|
|
935
1004
|
return rows.map(rowToNode);
|
|
936
1005
|
}
|
|
937
1006
|
/**
|
|
@@ -989,12 +1058,25 @@ class QueryBuilder {
|
|
|
989
1058
|
// pushing them past the FTS fetch limit before post-hoc scoring can help.
|
|
990
1059
|
// Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
|
|
991
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.
|
|
992
1074
|
if (results.length > 0 && query) {
|
|
993
1075
|
const existingIds = new Set(results.map(r => r.node.id));
|
|
994
1076
|
const maxFtsScore = Math.max(...results.map(r => r.score));
|
|
995
1077
|
const terms = query.split(/\s+/).filter(t => t.length >= 2);
|
|
996
1078
|
for (const term of terms) {
|
|
997
|
-
let sql = 'SELECT * FROM nodes WHERE name = ?
|
|
1079
|
+
let sql = 'SELECT * FROM nodes WHERE lower(name) = lower(?)';
|
|
998
1080
|
const params = [term];
|
|
999
1081
|
if (kinds && kinds.length > 0) {
|
|
1000
1082
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1017,13 +1099,24 @@ class QueryBuilder {
|
|
|
1017
1099
|
// Apply multi-signal scoring
|
|
1018
1100
|
if (results.length > 0 && (text || query)) {
|
|
1019
1101
|
const scoringQuery = text || query;
|
|
1020
|
-
results = results.map(r =>
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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
|
+
});
|
|
1027
1120
|
results.sort((a, b) => b.score - a.score);
|
|
1028
1121
|
// Trim to requested limit after rescoring
|
|
1029
1122
|
if (results.length > limit) {
|
|
@@ -1262,9 +1355,16 @@ class QueryBuilder {
|
|
|
1262
1355
|
// Pass 1: Find which files contain distinctive (rare) symbols from the query.
|
|
1263
1356
|
// Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
|
|
1264
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.
|
|
1265
1365
|
const nameToFiles = new Map();
|
|
1266
1366
|
for (const name of names) {
|
|
1267
|
-
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE name
|
|
1367
|
+
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
|
|
1268
1368
|
const params = [name];
|
|
1269
1369
|
if (kinds && kinds.length > 0) {
|
|
1270
1370
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1290,7 +1390,7 @@ class QueryBuilder {
|
|
|
1290
1390
|
let sql = `
|
|
1291
1391
|
SELECT nodes.*, 1.0 as score
|
|
1292
1392
|
FROM nodes
|
|
1293
|
-
WHERE name
|
|
1393
|
+
WHERE lower(name) = lower(?)
|
|
1294
1394
|
`;
|
|
1295
1395
|
const params = [name];
|
|
1296
1396
|
if (kinds && kinds.length > 0) {
|
|
@@ -1561,8 +1661,8 @@ class QueryBuilder {
|
|
|
1561
1661
|
upsertFile(file) {
|
|
1562
1662
|
if (!this.stmts.upsertFile) {
|
|
1563
1663
|
this.stmts.upsertFile = this.db.prepare(`
|
|
1564
|
-
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors)
|
|
1565
|
-
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)
|
|
1566
1666
|
ON CONFLICT(path) DO UPDATE SET
|
|
1567
1667
|
content_hash = @contentHash,
|
|
1568
1668
|
language = @language,
|
|
@@ -1570,7 +1670,8 @@ class QueryBuilder {
|
|
|
1570
1670
|
modified_at = @modifiedAt,
|
|
1571
1671
|
indexed_at = @indexedAt,
|
|
1572
1672
|
node_count = @nodeCount,
|
|
1573
|
-
errors = @errors
|
|
1673
|
+
errors = @errors,
|
|
1674
|
+
generated = @generated
|
|
1574
1675
|
`);
|
|
1575
1676
|
}
|
|
1576
1677
|
this.stmts.upsertFile.run({
|
|
@@ -1582,8 +1683,149 @@ class QueryBuilder {
|
|
|
1582
1683
|
indexedAt: file.indexedAt,
|
|
1583
1684
|
nodeCount: file.nodeCount,
|
|
1584
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,
|
|
1585
1689
|
});
|
|
1586
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
|
+
}
|
|
1587
1829
|
/**
|
|
1588
1830
|
* Delete a file record and its nodes
|
|
1589
1831
|
*/
|
|
@@ -1847,7 +2089,13 @@ class QueryBuilder {
|
|
|
1847
2089
|
const chunkRows = this.db
|
|
1848
2090
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
|
|
1849
2091
|
.all(...chunk);
|
|
1850
|
-
|
|
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);
|
|
1851
2099
|
}
|
|
1852
2100
|
return rows.map((row) => ({
|
|
1853
2101
|
fromNodeId: row.from_node_id,
|
|
@@ -2018,7 +2266,11 @@ class QueryBuilder {
|
|
|
2018
2266
|
const chunkRows = this.db
|
|
2019
2267
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
|
|
2020
2268
|
.all(...chunk);
|
|
2021
|
-
|
|
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);
|
|
2022
2274
|
}
|
|
2023
2275
|
return rows.map((row) => ({
|
|
2024
2276
|
fromNodeId: row.from_node_id,
|
|
@@ -2032,6 +2284,92 @@ class QueryBuilder {
|
|
|
2032
2284
|
rowId: row.id,
|
|
2033
2285
|
}));
|
|
2034
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
|
+
}
|
|
2035
2373
|
/**
|
|
2036
2374
|
* Distinct node names present in the given files — the symbol names a sync
|
|
2037
2375
|
* pass uses to look up retryable failed refs after those files changed.
|
|
@@ -2051,6 +2389,34 @@ class QueryBuilder {
|
|
|
2051
2389
|
}
|
|
2052
2390
|
return [...names];
|
|
2053
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
|
+
}
|
|
2054
2420
|
// ===========================================================================
|
|
2055
2421
|
// Statistics
|
|
2056
2422
|
// ===========================================================================
|
|
@@ -2106,6 +2472,7 @@ class QueryBuilder {
|
|
|
2106
2472
|
edgesByKind,
|
|
2107
2473
|
filesByLanguage,
|
|
2108
2474
|
dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
|
|
2475
|
+
walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
|
|
2109
2476
|
lastUpdated: Date.now(),
|
|
2110
2477
|
};
|
|
2111
2478
|
}
|