@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.5.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 +61 -15
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +41 -11
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +142 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +267 -6
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/queries.d.ts +74 -2
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +287 -20
- package/lib/dist/db/queries.js.map +1 -1
- 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/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +63 -0
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +32 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +254 -61
- 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 +849 -12
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +8 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +15 -0
- 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.d.ts +22 -4
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +151 -6
- 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/index.d.ts +14 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +188 -10
- 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.map +1 -1
- package/lib/dist/installer/index.js +11 -0
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +27 -0
- package/lib/dist/mcp/tools.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 +574 -132
- 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 +249 -157
- 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/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +166 -7
- 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 +716 -130
- 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 +12 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +387 -95
- package/lib/dist/resolution/name-matcher.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/sync/watcher.d.ts +25 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +76 -3
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +41 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +26 -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
|
@@ -123,9 +123,67 @@ class QueryBuilder {
|
|
|
123
123
|
// correctness backstop. Bounded so a pathological repo can't grow it forever.
|
|
124
124
|
segmentedNames = new Set();
|
|
125
125
|
static MAX_SEGMENTED_NAMES = 65536;
|
|
126
|
+
// Multi-row INSERT statements, cached per (statement kind × row count). The
|
|
127
|
+
// bulk write path decomposes N rows into a few fixed batch sizes so each
|
|
128
|
+
// size's statement is prepared once and reused — one .run() binds a whole
|
|
129
|
+
// chunk instead of one row, which is where the per-call overhead lives.
|
|
130
|
+
// Row order within and across chunks is the input order, so rowid assignment
|
|
131
|
+
// (and therefore resolution's insertion-order disambiguation) is identical
|
|
132
|
+
// to the one-row-per-run path.
|
|
133
|
+
batchStmts = new Map();
|
|
134
|
+
static BATCH_SIZES = [128, 32, 8, 1];
|
|
135
|
+
/**
|
|
136
|
+
* Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
|
|
137
|
+
* decomposed greedily into the cached batch sizes. Preserves row order.
|
|
138
|
+
*/
|
|
139
|
+
runBatched(kind, head, tuple, rows) {
|
|
140
|
+
if (rows.length === 0)
|
|
141
|
+
return;
|
|
142
|
+
let i = 0;
|
|
143
|
+
for (const size of QueryBuilder.BATCH_SIZES) {
|
|
144
|
+
while (rows.length - i >= size) {
|
|
145
|
+
const key = `${kind}:${size}`;
|
|
146
|
+
let stmt = this.batchStmts.get(key);
|
|
147
|
+
if (!stmt) {
|
|
148
|
+
stmt = this.db.prepare(head + new Array(size).fill(tuple).join(','));
|
|
149
|
+
this.batchStmts.set(key, stmt);
|
|
150
|
+
}
|
|
151
|
+
if (size === 1) {
|
|
152
|
+
stmt.run(...rows[i]);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const params = [];
|
|
156
|
+
for (let r = 0; r < size; r++) {
|
|
157
|
+
const row = rows[i + r];
|
|
158
|
+
for (let c = 0; c < row.length; c++)
|
|
159
|
+
params.push(row[c]);
|
|
160
|
+
}
|
|
161
|
+
stmt.run(...params);
|
|
162
|
+
}
|
|
163
|
+
i += size;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
126
167
|
constructor(db) {
|
|
127
168
|
this.db = db;
|
|
128
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Swap the underlying connection in place. Used by pool workers'
|
|
172
|
+
* connection recycling (plan §7a.6, writes-under-readers): a long-lived
|
|
173
|
+
* read connection pins WAL checkpoint progress, and the deep WAL that
|
|
174
|
+
* accumulates behind it taxes every main-thread B-tree page operation
|
|
175
|
+
* (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
|
|
176
|
+
* identical hardware). Workers therefore close and reopen their read-only
|
|
177
|
+
* connection at the pool-idle boundary; everything above the connection —
|
|
178
|
+
* this QueryBuilder, the resolver and its warm caches — survives, and only
|
|
179
|
+
* connection-derived state (prepared statements) resets, re-preparing
|
|
180
|
+
* lazily on next use.
|
|
181
|
+
*/
|
|
182
|
+
rebind(db) {
|
|
183
|
+
this.db = db;
|
|
184
|
+
this.stmts = {};
|
|
185
|
+
this.batchStmts.clear();
|
|
186
|
+
}
|
|
129
187
|
/** Set the normalized project-name tokens used to down-weight non-discriminative
|
|
130
188
|
* query words in path scoring (#720). Called once when the project opens. */
|
|
131
189
|
setProjectNameTokens(tokens) {
|
|
@@ -220,28 +278,115 @@ class QueryBuilder {
|
|
|
220
278
|
}
|
|
221
279
|
/** Write `name`'s segments into name_segment_vocab (idempotent). */
|
|
222
280
|
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
|
-
}
|
|
281
|
+
const rows = [];
|
|
282
|
+
this.collectNameSegmentRows(name, rows);
|
|
283
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
234
284
|
}
|
|
235
285
|
/**
|
|
236
286
|
* Insert multiple nodes in a transaction
|
|
237
287
|
*/
|
|
238
288
|
insertNodes(nodes) {
|
|
239
289
|
this.db.transaction(() => {
|
|
290
|
+
// Bulk path: same semantics as insertNode() per row (validation, cache
|
|
291
|
+
// invalidation, segment vocab), but bound as multi-row INSERTs — the
|
|
292
|
+
// per-.run() call overhead dominates the store phase on full indexes.
|
|
293
|
+
const rows = [];
|
|
294
|
+
const segmentRows = [];
|
|
240
295
|
for (const node of nodes) {
|
|
241
|
-
|
|
296
|
+
if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
|
|
297
|
+
console.error('[CodeGraph] Skipping node with missing required fields:', {
|
|
298
|
+
id: node.id,
|
|
299
|
+
kind: node.kind,
|
|
300
|
+
name: node.name,
|
|
301
|
+
filePath: node.filePath,
|
|
302
|
+
language: node.language,
|
|
303
|
+
});
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
this.nodeCache.delete(node.id);
|
|
307
|
+
rows.push([
|
|
308
|
+
node.id,
|
|
309
|
+
node.kind,
|
|
310
|
+
node.name,
|
|
311
|
+
node.qualifiedName ?? node.name,
|
|
312
|
+
node.filePath,
|
|
313
|
+
node.language,
|
|
314
|
+
node.startLine ?? 0,
|
|
315
|
+
node.endLine ?? 0,
|
|
316
|
+
node.startColumn ?? 0,
|
|
317
|
+
node.endColumn ?? 0,
|
|
318
|
+
node.docstring ?? null,
|
|
319
|
+
node.signature ?? null,
|
|
320
|
+
node.visibility ?? null,
|
|
321
|
+
node.isExported ? 1 : 0,
|
|
322
|
+
node.isAsync ? 1 : 0,
|
|
323
|
+
node.isStatic ? 1 : 0,
|
|
324
|
+
node.isAbstract ? 1 : 0,
|
|
325
|
+
node.decorators ? JSON.stringify(node.decorators) : null,
|
|
326
|
+
node.typeParameters ? JSON.stringify(node.typeParameters) : null,
|
|
327
|
+
node.returnType ?? null,
|
|
328
|
+
node.updatedAt ?? Date.now(),
|
|
329
|
+
]);
|
|
330
|
+
if (this.isSegmentableKind(node.kind))
|
|
331
|
+
this.collectNameSegmentRows(node.name, segmentRows);
|
|
332
|
+
}
|
|
333
|
+
this.runBatched('insertNodes', `INSERT OR REPLACE INTO nodes (
|
|
334
|
+
id, kind, name, qualified_name, file_path, language,
|
|
335
|
+
start_line, end_line, start_column, end_column,
|
|
336
|
+
docstring, signature, visibility,
|
|
337
|
+
is_exported, is_async, is_static, is_abstract,
|
|
338
|
+
decorators, type_parameters, return_type, updated_at
|
|
339
|
+
) VALUES `, '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', rows);
|
|
340
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
|
|
341
|
+
})();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Store one file's whole extraction bundle — nodes, edges, unresolved refs,
|
|
345
|
+
* and the file record — in a SINGLE transaction. The bulk-index path calls
|
|
346
|
+
* this once per file instead of opening one transaction per table (#1015
|
|
347
|
+
* file-order commit discipline is unchanged: callers still invoke it in file
|
|
348
|
+
* order, and row order within is input order).
|
|
349
|
+
*
|
|
350
|
+
* Edges MUST already be endpoint-filtered by the caller (the store path
|
|
351
|
+
* filters to the file's own inserted node ids), so the per-file existence
|
|
352
|
+
* SELECT that insertEdges() pays is skipped here.
|
|
353
|
+
*/
|
|
354
|
+
storeFileBundle(bundle) {
|
|
355
|
+
this.db.transaction(() => {
|
|
356
|
+
this.insertNodes(bundle.nodes);
|
|
357
|
+
if (bundle.edges.length > 0) {
|
|
358
|
+
const rows = [];
|
|
359
|
+
for (const edge of bundle.edges) {
|
|
360
|
+
rows.push([
|
|
361
|
+
edge.source,
|
|
362
|
+
edge.target,
|
|
363
|
+
edge.kind,
|
|
364
|
+
edge.metadata ? JSON.stringify(edge.metadata) : null,
|
|
365
|
+
edge.line ?? null,
|
|
366
|
+
edge.column ?? null,
|
|
367
|
+
edge.provenance ?? null,
|
|
368
|
+
]);
|
|
369
|
+
}
|
|
370
|
+
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
242
371
|
}
|
|
372
|
+
if (bundle.refs.length > 0)
|
|
373
|
+
this.insertUnresolvedRefsBatch(bundle.refs);
|
|
374
|
+
this.upsertFile(bundle.file);
|
|
243
375
|
})();
|
|
244
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Collect (segment, name) rows for a name, honouring the same session-dedupe
|
|
379
|
+
* semantics as insertNameSegments(). Shared by the bulk write paths.
|
|
380
|
+
*/
|
|
381
|
+
collectNameSegmentRows(name, out) {
|
|
382
|
+
if (this.segmentedNames.has(name))
|
|
383
|
+
return;
|
|
384
|
+
if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
|
|
385
|
+
this.segmentedNames.clear();
|
|
386
|
+
this.segmentedNames.add(name);
|
|
387
|
+
for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
|
|
388
|
+
out.push([segment, name]);
|
|
389
|
+
}
|
|
245
390
|
/**
|
|
246
391
|
* Update an existing node
|
|
247
392
|
*/
|
|
@@ -367,8 +512,10 @@ class QueryBuilder {
|
|
|
367
512
|
/** Insert segments for a batch of names in one transaction (vocab heal path). */
|
|
368
513
|
insertNameSegmentsBatch(names) {
|
|
369
514
|
this.db.transaction(() => {
|
|
515
|
+
const rows = [];
|
|
370
516
|
for (const name of names)
|
|
371
|
-
this.
|
|
517
|
+
this.collectNameSegmentRows(name, rows);
|
|
518
|
+
this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
|
|
372
519
|
})();
|
|
373
520
|
}
|
|
374
521
|
/**
|
|
@@ -1250,12 +1397,22 @@ class QueryBuilder {
|
|
|
1250
1397
|
endpointIds.add(edge.target);
|
|
1251
1398
|
}
|
|
1252
1399
|
const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
|
|
1400
|
+
const rows = [];
|
|
1253
1401
|
for (const edge of edges) {
|
|
1254
1402
|
if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
|
|
1255
1403
|
continue;
|
|
1256
1404
|
}
|
|
1257
|
-
|
|
1405
|
+
rows.push([
|
|
1406
|
+
edge.source,
|
|
1407
|
+
edge.target,
|
|
1408
|
+
edge.kind,
|
|
1409
|
+
edge.metadata ? JSON.stringify(edge.metadata) : null,
|
|
1410
|
+
edge.line ?? null,
|
|
1411
|
+
edge.column ?? null,
|
|
1412
|
+
edge.provenance ?? null,
|
|
1413
|
+
]);
|
|
1258
1414
|
}
|
|
1415
|
+
this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
|
|
1259
1416
|
})();
|
|
1260
1417
|
}
|
|
1261
1418
|
/**
|
|
@@ -1510,9 +1667,20 @@ class QueryBuilder {
|
|
|
1510
1667
|
if (refs.length === 0)
|
|
1511
1668
|
return;
|
|
1512
1669
|
const insert = this.db.transaction(() => {
|
|
1670
|
+
const rows = [];
|
|
1513
1671
|
for (const ref of refs) {
|
|
1514
|
-
|
|
1672
|
+
rows.push([
|
|
1673
|
+
ref.fromNodeId,
|
|
1674
|
+
ref.referenceName,
|
|
1675
|
+
ref.referenceKind,
|
|
1676
|
+
ref.line,
|
|
1677
|
+
ref.column,
|
|
1678
|
+
ref.candidates ? JSON.stringify(ref.candidates) : null,
|
|
1679
|
+
ref.filePath ?? '',
|
|
1680
|
+
ref.language ?? 'unknown',
|
|
1681
|
+
]);
|
|
1515
1682
|
}
|
|
1683
|
+
this.runBatched('insertUnresolvedRefs', 'INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language) VALUES ', '(?,?,?,?,?,?,?,?)', rows);
|
|
1516
1684
|
});
|
|
1517
1685
|
insert();
|
|
1518
1686
|
}
|
|
@@ -1542,6 +1710,7 @@ class QueryBuilder {
|
|
|
1542
1710
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1543
1711
|
filePath: row.file_path,
|
|
1544
1712
|
language: row.language,
|
|
1713
|
+
rowId: row.id,
|
|
1545
1714
|
}));
|
|
1546
1715
|
}
|
|
1547
1716
|
/**
|
|
@@ -1558,6 +1727,7 @@ class QueryBuilder {
|
|
|
1558
1727
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1559
1728
|
filePath: row.file_path,
|
|
1560
1729
|
language: row.language,
|
|
1730
|
+
rowId: row.id,
|
|
1561
1731
|
}));
|
|
1562
1732
|
}
|
|
1563
1733
|
/**
|
|
@@ -1582,7 +1752,12 @@ class QueryBuilder {
|
|
|
1582
1752
|
*/
|
|
1583
1753
|
getUnresolvedReferencesBatch(offset, limit) {
|
|
1584
1754
|
if (!this.stmts.getUnresolvedBatch) {
|
|
1585
|
-
|
|
1755
|
+
// ORDER BY rowid is load-bearing for the pipelined resolution loop: it
|
|
1756
|
+
// prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
|
|
1757
|
+
// still pending, which is only exact under a stable enumeration. (A plain
|
|
1758
|
+
// scan and the status index both return rowid order anyway — this pins
|
|
1759
|
+
// it.)
|
|
1760
|
+
this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
|
|
1586
1761
|
}
|
|
1587
1762
|
const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
|
|
1588
1763
|
return rows.map((row) => ({
|
|
@@ -1594,6 +1769,32 @@ class QueryBuilder {
|
|
|
1594
1769
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1595
1770
|
filePath: row.file_path,
|
|
1596
1771
|
language: row.language,
|
|
1772
|
+
rowId: row.id,
|
|
1773
|
+
}));
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
|
|
1777
|
+
* resolution loop: seek past the last-seen row id instead of OFFSET-walking.
|
|
1778
|
+
* OFFSET reads re-scan the accumulated failed-row prefix on every batch —
|
|
1779
|
+
* O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
|
|
1780
|
+
* (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
|
|
1781
|
+
* the enumeration order is identical to the OFFSET reader's.
|
|
1782
|
+
*/
|
|
1783
|
+
getUnresolvedReferencesBatchAfter(afterRowId, limit) {
|
|
1784
|
+
if (!this.stmts.getUnresolvedBatchAfter) {
|
|
1785
|
+
this.stmts.getUnresolvedBatchAfter = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' AND id > ? ORDER BY id LIMIT ?");
|
|
1786
|
+
}
|
|
1787
|
+
const rows = this.stmts.getUnresolvedBatchAfter.all(afterRowId, limit);
|
|
1788
|
+
return rows.map((row) => ({
|
|
1789
|
+
fromNodeId: row.from_node_id,
|
|
1790
|
+
referenceName: row.reference_name,
|
|
1791
|
+
referenceKind: row.reference_kind,
|
|
1792
|
+
line: row.line,
|
|
1793
|
+
column: row.col,
|
|
1794
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1795
|
+
filePath: row.file_path,
|
|
1796
|
+
language: row.language,
|
|
1797
|
+
rowId: row.id,
|
|
1597
1798
|
}));
|
|
1598
1799
|
}
|
|
1599
1800
|
/**
|
|
@@ -1657,6 +1858,7 @@ class QueryBuilder {
|
|
|
1657
1858
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1658
1859
|
filePath: row.file_path,
|
|
1659
1860
|
language: row.language,
|
|
1861
|
+
rowId: row.id,
|
|
1660
1862
|
}));
|
|
1661
1863
|
}
|
|
1662
1864
|
/**
|
|
@@ -1688,14 +1890,55 @@ class QueryBuilder {
|
|
|
1688
1890
|
*/
|
|
1689
1891
|
deleteSpecificResolvedReferences(refs) {
|
|
1690
1892
|
if (refs.length === 0)
|
|
1691
|
-
return;
|
|
1893
|
+
return 0;
|
|
1692
1894
|
const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
|
|
1895
|
+
// Returns rows actually removed (SQLite `changes`, summed): the batched
|
|
1896
|
+
// resolution loop's non-progress guard keys on this — zero removals from
|
|
1897
|
+
// a batch that claimed work is the direct runaway signal (§7a.2).
|
|
1898
|
+
let changed = 0;
|
|
1693
1899
|
const deleteMany = this.db.transaction((items) => {
|
|
1694
1900
|
for (const ref of items) {
|
|
1695
|
-
stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
|
|
1901
|
+
changed += stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
1696
1902
|
}
|
|
1697
1903
|
});
|
|
1698
1904
|
deleteMany(refs);
|
|
1905
|
+
return changed;
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Delete unresolved-ref rows by row id — the precise cleanup for refs a
|
|
1909
|
+
* resolution pass actually processed. The key-tuple variant above also
|
|
1910
|
+
* deletes SIBLING rows (same caller calling the same callee at other lines)
|
|
1911
|
+
* that a later batch hasn't attempted yet, so when a batch boundary split a
|
|
1912
|
+
* caller's same-named call sites, the later sites' edges were silently never
|
|
1913
|
+
* created (#1269).
|
|
1914
|
+
*/
|
|
1915
|
+
deleteReferencesByRowIds(rowIds) {
|
|
1916
|
+
if (rowIds.length === 0)
|
|
1917
|
+
return 0;
|
|
1918
|
+
// One transaction for all chunks (each chunk was previously its own
|
|
1919
|
+
// implicit transaction = its own WAL commit — measurable on 100k+-ref
|
|
1920
|
+
// resolution persists), and the full-size chunk statement is cached so
|
|
1921
|
+
// repeat calls skip the re-prepare; only the final partial chunk (if any)
|
|
1922
|
+
// prepares ad hoc. Returns rows actually removed (summed `changes`) for
|
|
1923
|
+
// the batched loop's non-progress guard (§7a.2).
|
|
1924
|
+
let changed = 0;
|
|
1925
|
+
this.db.transaction(() => {
|
|
1926
|
+
for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1927
|
+
const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1928
|
+
if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
|
|
1929
|
+
if (!this.stmts.deleteRefsByRowIdsFull) {
|
|
1930
|
+
const placeholders = new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',');
|
|
1931
|
+
this.stmts.deleteRefsByRowIdsFull = this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`);
|
|
1932
|
+
}
|
|
1933
|
+
changed += this.stmts.deleteRefsByRowIdsFull.run(...chunk).changes;
|
|
1934
|
+
}
|
|
1935
|
+
else {
|
|
1936
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1937
|
+
changed += this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`).run(...chunk).changes;
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
})();
|
|
1941
|
+
return changed;
|
|
1699
1942
|
}
|
|
1700
1943
|
/**
|
|
1701
1944
|
* Mark refs a completed resolution pass could not resolve as status='failed'
|
|
@@ -1708,14 +1951,37 @@ class QueryBuilder {
|
|
|
1708
1951
|
*/
|
|
1709
1952
|
markReferencesFailed(refs) {
|
|
1710
1953
|
if (refs.length === 0)
|
|
1711
|
-
return;
|
|
1954
|
+
return 0;
|
|
1712
1955
|
const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?");
|
|
1956
|
+
let changed = 0;
|
|
1957
|
+
const markMany = this.db.transaction((items) => {
|
|
1958
|
+
for (const ref of items) {
|
|
1959
|
+
changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
markMany(refs);
|
|
1963
|
+
return changed;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Park refs as status='failed' by row id — the precise counterpart of
|
|
1967
|
+
* markReferencesFailed, for the same reason as deleteReferencesByRowIds:
|
|
1968
|
+
* the key-tuple variant also flips same-key sibling rows in later batches
|
|
1969
|
+
* to 'failed' before they were ever attempted (#1269). Resolution outcome
|
|
1970
|
+
* can differ per call site (receiver-type inference reads the ref's line),
|
|
1971
|
+
* so a sibling must not inherit this row's failure.
|
|
1972
|
+
*/
|
|
1973
|
+
markReferencesFailedByRowIds(refs) {
|
|
1974
|
+
if (refs.length === 0)
|
|
1975
|
+
return 0;
|
|
1976
|
+
const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE id = ?");
|
|
1977
|
+
let changed = 0;
|
|
1713
1978
|
const markMany = this.db.transaction((items) => {
|
|
1714
1979
|
for (const ref of items) {
|
|
1715
|
-
stmt.run(referenceNameTail(ref.referenceName), ref.
|
|
1980
|
+
changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
|
|
1716
1981
|
}
|
|
1717
1982
|
});
|
|
1718
1983
|
markMany(refs);
|
|
1984
|
+
return changed;
|
|
1719
1985
|
}
|
|
1720
1986
|
/**
|
|
1721
1987
|
* Failed refs whose name tail matches one of the given symbol names — the
|
|
@@ -1763,6 +2029,7 @@ class QueryBuilder {
|
|
|
1763
2029
|
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
1764
2030
|
filePath: row.file_path,
|
|
1765
2031
|
language: row.language,
|
|
2032
|
+
rowId: row.id,
|
|
1766
2033
|
}));
|
|
1767
2034
|
}
|
|
1768
2035
|
/**
|