@wrongstack/tools 0.296.2 → 0.296.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -256,11 +256,18 @@ async function parseSymbols(opts) {
256
256
  } else if (ts.isHeritageClause(node)) {
257
257
  for (const t of node.types) {
258
258
  const name = getTypeName(t.expression);
259
- if (name) refs.push({ fromId: 0, toName: name, callType: node.token === ts.SyntaxKind.ExtendsKeyword ? "inherit" : "implement", line: lineNum });
259
+ if (name)
260
+ refs.push({
261
+ fromId: 0,
262
+ toName: name,
263
+ callType: node.token === ts.SyntaxKind.ExtendsKeyword ? "inherit" : "implement",
264
+ line: lineNum
265
+ });
260
266
  }
261
267
  } else if (ts.isImportDeclaration(node)) {
262
- const moduleName = getModuleName(node);
263
- if (moduleName) refs.push({ fromId: 0, toName: moduleName, callType: "import", line: lineNum });
268
+ emitImportSpecifierRefs(node, refs, lineNum);
269
+ } else if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
270
+ emitExportSpecifierRefs(node, refs, lineNum);
264
271
  }
265
272
  const scopeIdx = scopeParts.length;
266
273
  pushScopeName(node, scopeParts);
@@ -276,11 +283,6 @@ function getTypeName(name) {
276
283
  if (ts.isQualifiedName(name)) return `${getTypeName(name.left)}.${name.right.text}`;
277
284
  return "";
278
285
  }
279
- function getModuleName(node) {
280
- const moduleSpecifier = node.moduleSpecifier;
281
- if (ts.isStringLiteral(moduleSpecifier)) return moduleSpecifier.text;
282
- return "";
283
- }
284
286
  function deduplicateRefs(refs) {
285
287
  const seen = /* @__PURE__ */ new Set();
286
288
  return refs.filter((r) => {
@@ -290,6 +292,44 @@ function deduplicateRefs(refs) {
290
292
  return true;
291
293
  });
292
294
  }
295
+ function getImportSpecifierName(spec) {
296
+ return spec.propertyName?.text ?? spec.name.text;
297
+ }
298
+ function emitImportSpecifierRefs(node, refs, lineNum) {
299
+ const clause = node.importClause;
300
+ if (!clause) return;
301
+ if (clause.name) {
302
+ refs.push({ fromId: 0, toName: clause.name.text, callType: "import", line: lineNum });
303
+ }
304
+ const bindings = clause.namedBindings;
305
+ if (!bindings) return;
306
+ if (ts.isNamedImports(bindings)) {
307
+ for (const element of bindings.elements) {
308
+ refs.push({
309
+ fromId: 0,
310
+ toName: getImportSpecifierName(element),
311
+ callType: "import",
312
+ line: lineNum
313
+ });
314
+ }
315
+ } else if (ts.isNamespaceImport(bindings)) {
316
+ refs.push({ fromId: 0, toName: bindings.name.text, callType: "import", line: lineNum });
317
+ }
318
+ }
319
+ function emitExportSpecifierRefs(node, refs, lineNum) {
320
+ const clause = node.exportClause;
321
+ if (clause && ts.isNamespaceExport(clause)) {
322
+ refs.push({ fromId: 0, toName: clause.name.text, callType: "import", line: lineNum });
323
+ return;
324
+ }
325
+ if (clause && ts.isNamedExports(clause)) {
326
+ for (const element of clause.elements) {
327
+ const originalName = element.propertyName?.text ?? element.name.text;
328
+ refs.push({ fromId: 0, toName: originalName, callType: "import", line: lineNum });
329
+ }
330
+ return;
331
+ }
332
+ }
293
333
  var ts, tsLoad, kindMapCache;
294
334
  var init_ts_parser = __esm({
295
335
  "src/codebase-index/ts-parser.ts"() {
@@ -1935,9 +1975,9 @@ var init_yaml_parser = __esm({
1935
1975
  import * as fs10 from "node:fs";
1936
1976
  import * as net from "node:net";
1937
1977
  import * as path13 from "node:path";
1938
- import { useDaemonPerfDefaults } from "@wrongstack/core/utils";
1939
1978
  import {
1940
1979
  DEFAULT_WALK_IGNORE_SET,
1980
+ useDaemonPerfDefaults,
1941
1981
  watchProjectTree
1942
1982
  } from "@wrongstack/core/utils";
1943
1983
 
@@ -2053,42 +2093,6 @@ import { expectDefined as expectDefined4 } from "@wrongstack/core/utils";
2053
2093
  import * as fs7 from "node:fs";
2054
2094
  import * as path10 from "node:path";
2055
2095
 
2056
- // src/codebase-index/schema.ts
2057
- var SCHEMA_VERSION = 3;
2058
-
2059
- // src/codebase-index/lsp-kind.ts
2060
- function lspKindToInternalKind(k) {
2061
- switch (k) {
2062
- case 5 /* Class */:
2063
- return "class";
2064
- case 6 /* Method */:
2065
- return "method";
2066
- case 7 /* Property */:
2067
- case 8 /* Field */:
2068
- return "property";
2069
- case 9 /* Constructor */:
2070
- return "class";
2071
- case 10 /* Enum */:
2072
- return "enum";
2073
- case 11 /* Interface */:
2074
- return "interface";
2075
- case 12 /* Function */:
2076
- return "function";
2077
- case 13 /* Variable */:
2078
- return "var";
2079
- case 14 /* Constant */:
2080
- return "const";
2081
- case 22 /* EnumMember */:
2082
- return "enum";
2083
- case 26 /* TypeParameter */:
2084
- return "type";
2085
- case 3 /* Namespace */:
2086
- return "namespace";
2087
- default:
2088
- return null;
2089
- }
2090
- }
2091
-
2092
2096
  // src/codebase-index/bm25.ts
2093
2097
  var K1 = 1.5;
2094
2098
  var B = 0.75;
@@ -2178,6 +2182,42 @@ var Bm25Index = class {
2178
2182
  }
2179
2183
  };
2180
2184
 
2185
+ // src/codebase-index/lsp-kind.ts
2186
+ function lspKindToInternalKind(k) {
2187
+ switch (k) {
2188
+ case 5 /* Class */:
2189
+ return "class";
2190
+ case 6 /* Method */:
2191
+ return "method";
2192
+ case 7 /* Property */:
2193
+ case 8 /* Field */:
2194
+ return "property";
2195
+ case 9 /* Constructor */:
2196
+ return "class";
2197
+ case 10 /* Enum */:
2198
+ return "enum";
2199
+ case 11 /* Interface */:
2200
+ return "interface";
2201
+ case 12 /* Function */:
2202
+ return "function";
2203
+ case 13 /* Variable */:
2204
+ return "var";
2205
+ case 14 /* Constant */:
2206
+ return "const";
2207
+ case 22 /* EnumMember */:
2208
+ return "enum";
2209
+ case 26 /* TypeParameter */:
2210
+ return "type";
2211
+ case 3 /* Namespace */:
2212
+ return "namespace";
2213
+ default:
2214
+ return null;
2215
+ }
2216
+ }
2217
+
2218
+ // src/codebase-index/schema.ts
2219
+ var SCHEMA_VERSION = 3;
2220
+
2181
2221
  // src/codebase-index/sqlite-runtime.ts
2182
2222
  import { createRequire } from "node:module";
2183
2223
  import { toErrorMessage } from "@wrongstack/core/utils";
@@ -2321,92 +2361,6 @@ function runSqliteWithRetry(fn) {
2321
2361
  throw lastError;
2322
2362
  }
2323
2363
 
2324
- // src/codebase-index/writer-helpers.ts
2325
- import { resolveWstackPaths } from "@wrongstack/core/utils";
2326
- function escapeLike(value) {
2327
- return value.replace(/[\\%_]/g, (char) => `\\${char}`);
2328
- }
2329
- function assignRefsToSymbols(refs, symbols) {
2330
- if (refs.length === 0 || symbols.length === 0) return [];
2331
- const ordered = [...symbols].sort((a, b) => a.line - b.line || a.col - b.col || a.id - b.id);
2332
- const seen = /* @__PURE__ */ new Set();
2333
- const assigned = [];
2334
- for (const ref of refs) {
2335
- let owner;
2336
- for (const symbol of ordered) {
2337
- if (symbol.line > ref.line) break;
2338
- owner = symbol;
2339
- }
2340
- if (!owner && ref.callType === "import") owner = ordered[0];
2341
- if (!owner || owner.id <= 0) continue;
2342
- const key = `${owner.id}:${ref.toName}:${ref.callType}`;
2343
- if (seen.has(key)) continue;
2344
- seen.add(key);
2345
- assigned.push({ ...ref, fromId: owner.id });
2346
- }
2347
- return assigned;
2348
- }
2349
- function resolveIndexDir(projectRoot2, override) {
2350
- return override ?? resolveWstackPaths({ projectRoot: projectRoot2 }).projectCodebaseIndex;
2351
- }
2352
-
2353
- // src/codebase-index/writer-schema.ts
2354
- var METADATA_TABLE_SQL = `
2355
- CREATE TABLE IF NOT EXISTS metadata (
2356
- key TEXT PRIMARY KEY,
2357
- value TEXT NOT NULL
2358
- );
2359
- `;
2360
- var CORE_TABLES_SQL = `
2361
- CREATE TABLE IF NOT EXISTS files (
2362
- file TEXT PRIMARY KEY,
2363
- lang TEXT NOT NULL,
2364
- mtime_ms INTEGER NOT NULL,
2365
- symbol_count INTEGER NOT NULL DEFAULT 0,
2366
- last_indexed INTEGER NOT NULL
2367
- );
2368
- CREATE TABLE IF NOT EXISTS symbols (
2369
- id INTEGER PRIMARY KEY,
2370
- lang TEXT NOT NULL,
2371
- kind TEXT NOT NULL,
2372
- name TEXT NOT NULL,
2373
- file TEXT NOT NULL,
2374
- line INTEGER NOT NULL,
2375
- col INTEGER NOT NULL,
2376
- signature TEXT NOT NULL DEFAULT '',
2377
- doc_comment TEXT NOT NULL DEFAULT '',
2378
- scope TEXT NOT NULL DEFAULT '',
2379
- text TEXT NOT NULL DEFAULT '',
2380
- file_fk TEXT NOT NULL
2381
- );
2382
- `;
2383
- var SYMBOL_INDEX_SQL = [
2384
- "CREATE INDEX IF NOT EXISTS idx_s_name ON symbols(name)",
2385
- "CREATE INDEX IF NOT EXISTS idx_s_kind ON symbols(kind)",
2386
- "CREATE INDEX IF NOT EXISTS idx_s_lang ON symbols(lang)",
2387
- "CREATE INDEX IF NOT EXISTS idx_s_file ON symbols(file)",
2388
- "CREATE INDEX IF NOT EXISTS idx_s_lang_kind ON symbols(lang, kind)",
2389
- "CREATE INDEX IF NOT EXISTS idx_s_file_fk ON symbols(file_fk)",
2390
- "CREATE INDEX IF NOT EXISTS idx_s_name_id ON symbols(name, id)"
2391
- ];
2392
- var REFS_TABLE_SQL = `
2393
- CREATE TABLE IF NOT EXISTS refs (
2394
- id INTEGER PRIMARY KEY,
2395
- from_id INTEGER NOT NULL,
2396
- to_name TEXT NOT NULL,
2397
- to_id INTEGER,
2398
- call_type TEXT NOT NULL,
2399
- line INTEGER NOT NULL
2400
- );
2401
- `;
2402
- var REFS_INDEX_SQL = [
2403
- "CREATE INDEX IF NOT EXISTS idx_r_from ON refs(from_id)",
2404
- "CREATE INDEX IF NOT EXISTS idx_r_to_id ON refs(to_id)",
2405
- "CREATE INDEX IF NOT EXISTS idx_r_to_name ON refs(to_name)",
2406
- "CREATE INDEX IF NOT EXISTS idx_r_call_type ON refs(call_type)"
2407
- ];
2408
- var SYMBOLS_FTS_SQL = "CREATE VIRTUAL TABLE IF NOT EXISTS symbols_fts USING fts5(text, tokenize = 'unicode61')";
2409
-
2410
2364
  // src/codebase-index/writer-admin.ts
2411
2365
  import * as fs6 from "node:fs";
2412
2366
  import * as path8 from "node:path";
@@ -2879,6 +2833,35 @@ function getSymbolGraphWithStatement(stmt, fileFilter) {
2879
2833
  return { nodes, edges };
2880
2834
  }
2881
2835
 
2836
+ // src/codebase-index/writer-helpers.ts
2837
+ import { resolveWstackPaths } from "@wrongstack/core/utils";
2838
+ function escapeLike(value) {
2839
+ return value.replace(/[\\%_]/g, (char) => `\\${char}`);
2840
+ }
2841
+ function assignRefsToSymbols(refs, symbols) {
2842
+ if (refs.length === 0 || symbols.length === 0) return [];
2843
+ const ordered = [...symbols].sort((a, b) => a.line - b.line || a.col - b.col || a.id - b.id);
2844
+ const seen = /* @__PURE__ */ new Set();
2845
+ const assigned = [];
2846
+ for (const ref of refs) {
2847
+ let owner;
2848
+ for (const symbol of ordered) {
2849
+ if (symbol.line > ref.line) break;
2850
+ owner = symbol;
2851
+ }
2852
+ if (!owner && ref.callType === "import") owner = ordered[0];
2853
+ if (!owner || owner.id <= 0) continue;
2854
+ const key = `${owner.id}:${ref.toName}:${ref.callType}`;
2855
+ if (seen.has(key)) continue;
2856
+ seen.add(key);
2857
+ assigned.push({ ...ref, fromId: owner.id });
2858
+ }
2859
+ return assigned;
2860
+ }
2861
+ function resolveIndexDir(projectRoot2, override) {
2862
+ return override ?? resolveWstackPaths({ projectRoot: projectRoot2 }).projectCodebaseIndex;
2863
+ }
2864
+
2882
2865
  // src/codebase-index/writer-pragmas.ts
2883
2866
  import { sqliteCachePragmas } from "@wrongstack/core/utils";
2884
2867
  function applyIndexStorePragmas(db) {
@@ -2897,6 +2880,63 @@ function applyIndexStorePragmas(db) {
2897
2880
  }
2898
2881
  }
2899
2882
 
2883
+ // src/codebase-index/writer-schema.ts
2884
+ var METADATA_TABLE_SQL = `
2885
+ CREATE TABLE IF NOT EXISTS metadata (
2886
+ key TEXT PRIMARY KEY,
2887
+ value TEXT NOT NULL
2888
+ );
2889
+ `;
2890
+ var CORE_TABLES_SQL = `
2891
+ CREATE TABLE IF NOT EXISTS files (
2892
+ file TEXT PRIMARY KEY,
2893
+ lang TEXT NOT NULL,
2894
+ mtime_ms INTEGER NOT NULL,
2895
+ symbol_count INTEGER NOT NULL DEFAULT 0,
2896
+ last_indexed INTEGER NOT NULL
2897
+ );
2898
+ CREATE TABLE IF NOT EXISTS symbols (
2899
+ id INTEGER PRIMARY KEY,
2900
+ lang TEXT NOT NULL,
2901
+ kind TEXT NOT NULL,
2902
+ name TEXT NOT NULL,
2903
+ file TEXT NOT NULL,
2904
+ line INTEGER NOT NULL,
2905
+ col INTEGER NOT NULL,
2906
+ signature TEXT NOT NULL DEFAULT '',
2907
+ doc_comment TEXT NOT NULL DEFAULT '',
2908
+ scope TEXT NOT NULL DEFAULT '',
2909
+ text TEXT NOT NULL DEFAULT '',
2910
+ file_fk TEXT NOT NULL
2911
+ );
2912
+ `;
2913
+ var SYMBOL_INDEX_SQL = [
2914
+ "CREATE INDEX IF NOT EXISTS idx_s_name ON symbols(name)",
2915
+ "CREATE INDEX IF NOT EXISTS idx_s_kind ON symbols(kind)",
2916
+ "CREATE INDEX IF NOT EXISTS idx_s_lang ON symbols(lang)",
2917
+ "CREATE INDEX IF NOT EXISTS idx_s_file ON symbols(file)",
2918
+ "CREATE INDEX IF NOT EXISTS idx_s_lang_kind ON symbols(lang, kind)",
2919
+ "CREATE INDEX IF NOT EXISTS idx_s_file_fk ON symbols(file_fk)",
2920
+ "CREATE INDEX IF NOT EXISTS idx_s_name_id ON symbols(name, id)"
2921
+ ];
2922
+ var REFS_TABLE_SQL = `
2923
+ CREATE TABLE IF NOT EXISTS refs (
2924
+ id INTEGER PRIMARY KEY,
2925
+ from_id INTEGER NOT NULL,
2926
+ to_name TEXT NOT NULL,
2927
+ to_id INTEGER,
2928
+ call_type TEXT NOT NULL,
2929
+ line INTEGER NOT NULL
2930
+ );
2931
+ `;
2932
+ var REFS_INDEX_SQL = [
2933
+ "CREATE INDEX IF NOT EXISTS idx_r_from ON refs(from_id)",
2934
+ "CREATE INDEX IF NOT EXISTS idx_r_to_id ON refs(to_id)",
2935
+ "CREATE INDEX IF NOT EXISTS idx_r_to_name ON refs(to_name)",
2936
+ "CREATE INDEX IF NOT EXISTS idx_r_call_type ON refs(call_type)"
2937
+ ];
2938
+ var SYMBOLS_FTS_SQL = "CREATE VIRTUAL TABLE IF NOT EXISTS symbols_fts USING fts5(text, tokenize = 'unicode61')";
2939
+
2900
2940
  // src/codebase-index/writer-search-helpers.ts
2901
2941
  function normalizeSearchLimit(limit) {
2902
2942
  return typeof limit === "number" && Number.isFinite(limit) ? Math.max(0, Math.trunc(limit)) : void 0;
@@ -3105,9 +3145,15 @@ var IndexStore = class _IndexStore {
3105
3145
  DROP TABLE IF EXISTS refs;
3106
3146
  `);
3107
3147
  this.db.exec("DROP TABLE IF EXISTS symbols_fts");
3108
- this.stmt("UPDATE metadata SET value = ? WHERE key = ?").run(String(SCHEMA_VERSION), "version");
3148
+ this.stmt("UPDATE metadata SET value = ? WHERE key = ?").run(
3149
+ String(SCHEMA_VERSION),
3150
+ "version"
3151
+ );
3109
3152
  } else if (storedVersion === null) {
3110
- this.stmt("INSERT INTO metadata(key, value) VALUES (?, ?)").run("version", String(SCHEMA_VERSION));
3153
+ this.stmt("INSERT INTO metadata(key, value) VALUES (?, ?)").run(
3154
+ "version",
3155
+ String(SCHEMA_VERSION)
3156
+ );
3111
3157
  }
3112
3158
  this.db.exec(CORE_TABLES_SQL);
3113
3159
  for (const sql of SYMBOL_INDEX_SQL) this.db.exec(sql);
@@ -3124,7 +3170,9 @@ var IndexStore = class _IndexStore {
3124
3170
  );
3125
3171
  if (symbolCount !== ftsCount) {
3126
3172
  this.db.exec("DELETE FROM symbols_fts");
3127
- const rows = this.stmt("SELECT id, name, signature, doc_comment FROM symbols ORDER BY id").all();
3173
+ const rows = this.stmt(
3174
+ "SELECT id, name, signature, doc_comment FROM symbols ORDER BY id"
3175
+ ).all();
3128
3176
  bulkInsertFtsWithStatement(
3129
3177
  (sql) => this.stmt(sql),
3130
3178
  _IndexStore.MAX_SQL_VARS,
@@ -3346,7 +3394,9 @@ var IndexStore = class _IndexStore {
3346
3394
  const limitSql = limit !== void 0 ? " LIMIT ?" : "";
3347
3395
  const sql = `SELECT id, lang, kind, name, file, line, col, signature, doc_comment, text FROM symbols ${where}${limitSql}`;
3348
3396
  const binds = limit !== void 0 ? [...values, limit] : values;
3349
- const rows = this.stmt(sql).all(...binds);
3397
+ const rows = this.stmt(sql).all(
3398
+ ...binds
3399
+ );
3350
3400
  return rows.map((row) => mapWriterSearchRow(row, filter?.lspKind));
3351
3401
  }
3352
3402
  /** Shared WHERE builder for {@link search} / empty-query ranked totals. */
@@ -3522,7 +3572,9 @@ var IndexStore = class _IndexStore {
3522
3572
  }
3523
3573
  setLastIndexed(ts2) {
3524
3574
  this.runWithRetry(() => {
3525
- this.stmt("INSERT OR REPLACE INTO metadata(key, value) VALUES('last_indexed', ?)").run(String(ts2));
3575
+ this.stmt("INSERT OR REPLACE INTO metadata(key, value) VALUES('last_indexed', ?)").run(
3576
+ String(ts2)
3577
+ );
3526
3578
  });
3527
3579
  }
3528
3580
  getMetadata(key) {
@@ -3633,7 +3685,9 @@ var IndexStore = class _IndexStore {
3633
3685
  this.stmt(
3634
3686
  `DELETE FROM refs WHERE from_id IN (SELECT id FROM symbols WHERE file IN (${placeholders}))`
3635
3687
  ).run(...options.deleteForFiles);
3636
- this.stmt(`DELETE FROM symbols WHERE file IN (${placeholders})`).run(...options.deleteForFiles);
3688
+ this.stmt(`DELETE FROM symbols WHERE file IN (${placeholders})`).run(
3689
+ ...options.deleteForFiles
3690
+ );
3637
3691
  }
3638
3692
  const totalSymbols = entries.reduce((n, e) => n + e.symbols.length, 0);
3639
3693
  let nextId = this.allocateSymbolIds(totalSymbols);
@@ -3677,11 +3731,7 @@ var IndexStore = class _IndexStore {
3677
3731
  this.ftsAvailable,
3678
3732
  ftsRows
3679
3733
  );
3680
- bulkInsertRefsWithStatement(
3681
- (sql) => this.stmt(sql),
3682
- _IndexStore.MAX_SQL_VARS,
3683
- refsToInsert
3684
- );
3734
+ bulkInsertRefsWithStatement((sql) => this.stmt(sql), _IndexStore.MAX_SQL_VARS, refsToInsert);
3685
3735
  const upsertStmt = this.stmt(
3686
3736
  `INSERT INTO files(file, lang, mtime_ms, symbol_count, last_indexed)
3687
3737
  VALUES (?, ?, ?, ?, ?)
@@ -3710,7 +3760,9 @@ var IndexStore = class _IndexStore {
3710
3760
  */
3711
3761
  deleteRefsForFile(file) {
3712
3762
  this.runWithRetry(() => {
3713
- this.stmt("DELETE FROM refs WHERE from_id IN (SELECT id FROM symbols WHERE file = ?)").run(file);
3763
+ this.stmt("DELETE FROM refs WHERE from_id IN (SELECT id FROM symbols WHERE file = ?)").run(
3764
+ file
3765
+ );
3714
3766
  });
3715
3767
  }
3716
3768
  /**
@@ -3865,9 +3917,7 @@ var IndexStore = class _IndexStore {
3865
3917
  * build the full symbol universe for the reachability scan.
3866
3918
  */
3867
3919
  getAllSymbols() {
3868
- return this.stmt(
3869
- "SELECT id, name, file, kind, line FROM symbols ORDER BY id"
3870
- ).all().map((r) => ({ ...r, kind: r.kind }));
3920
+ return this.stmt("SELECT id, name, file, kind, line FROM symbols ORDER BY id").all().map((r) => ({ ...r, kind: r.kind }));
3871
3921
  }
3872
3922
  /**
3873
3923
  * Returns every resolved reference (to_id IS NOT NULL). Used by
@@ -3879,6 +3929,25 @@ var IndexStore = class _IndexStore {
3879
3929
  "SELECT from_id AS fromId, to_id AS toId, call_type AS callType FROM refs WHERE to_id IS NOT NULL"
3880
3930
  ).all();
3881
3931
  }
3932
+ /**
3933
+ * Returns ALL import refs (including unresolved) with their source-file
3934
+ * path and resolved target id. Used by the dead-code scan's file-level
3935
+ * graph traversal to handle barrel-only entry points where no symbol
3936
+ * carries the ref.
3937
+ *
3938
+ * Refs whose `from_id` doesn't match a known symbol (e.g. pure-barrel
3939
+ * files with no declarations) will have `sourceFile === null`.
3940
+ */
3941
+ getAllImportRefs() {
3942
+ return this.stmt(
3943
+ `SELECT s.file AS sourceFile, r.to_name AS toName, r.to_id AS toId,
3944
+ r.call_type AS callType, r.line
3945
+ FROM refs r
3946
+ LEFT JOIN symbols s ON r.from_id = s.id
3947
+ WHERE r.call_type = 'import'
3948
+ ORDER BY r.line`
3949
+ ).all();
3950
+ }
3882
3951
  close() {
3883
3952
  this.stmtCache.clear();
3884
3953
  this.bm25Dirty = true;
@@ -4570,8 +4639,14 @@ function cachedRead(cache, key, load) {
4570
4639
  const value = load();
4571
4640
  return indexActivity.indexing ? value : cache.set(key, generation, value);
4572
4641
  }
4642
+ var MAX_CLIENT_WRITE_BUFFER_BYTES = 8 * 1024 * 1024;
4573
4643
  function send(state, message) {
4574
- if (!state.socket.destroyed) state.socket.write(encodeProjectServerMessage(message));
4644
+ if (state.socket.destroyed) return;
4645
+ if (state.socket.writableLength > MAX_CLIENT_WRITE_BUFFER_BYTES) {
4646
+ state.socket.destroy(new Error("Index client fell too far behind on reads"));
4647
+ return;
4648
+ }
4649
+ state.socket.write(encodeProjectServerMessage(message));
4575
4650
  }
4576
4651
  function withWriteMutex(job) {
4577
4652
  queuedWrites++;