@mrclrchtr/supi-code-intelligence 13.0.0 → 14.0.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -3
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  5. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  6. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  7. package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  8. package/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  9. package/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  10. package/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  11. package/node_modules/@mrclrchtr/supi-lsp/README.md +6 -2
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  20. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +5 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +3 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +14 -1
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-typescript.ts +8 -1
  25. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +4 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-input-admission.ts +7 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +1 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +24 -8
  29. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +5 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +3 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/debug-telemetry.ts +64 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +3 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +27 -2
  34. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +16 -112
  35. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +521 -83
  36. package/node_modules/@mrclrchtr/supi-lsp/src/manager/workspace-symbol-collection.ts +163 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/src/manager/workspace-symbol-row-limit.ts +72 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +11 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +36 -7
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm +0 -0
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm.json +2 -2
  51. package/package.json +5 -5
  52. package/src/analysis/health/server-status.ts +32 -9
  53. package/src/analysis/health/signals.ts +1 -0
  54. package/src/analysis/instruction-files.ts +11 -7
  55. package/src/analysis/search/exclusions.ts +18 -4
  56. package/src/analysis/target/file-outline-omissions.ts +17 -2
  57. package/src/analysis/target/symbol-selection.ts +100 -0
  58. package/src/analysis/target/symbol.ts +48 -8
  59. package/src/analysis/target/types.ts +8 -1
  60. package/src/app/app.ts +37 -21
  61. package/src/extension.ts +1 -2
  62. package/src/headless.ts +4 -2
  63. package/src/session/health-types.ts +2 -0
  64. package/src/session/orientation-types.ts +5 -0
  65. package/src/session/orientation-workflow.ts +13 -3
  66. package/src/session/target-workflow.ts +18 -12
  67. package/src/tool/code_find/render.ts +10 -11
  68. package/src/tool/code_find/result.ts +6 -1
  69. package/src/tool/code_graph/structured.ts +3 -0
  70. package/src/tool/code_health/markdown.ts +3 -1
  71. package/src/tool/code_health/structured-schema.ts +1 -0
  72. package/src/tool/code_health/structured.ts +2 -0
  73. package/src/tool/code_orientation/markdown.ts +6 -1
  74. package/src/tool/code_resolve/result.ts +2 -1
  75. package/src/tool/code_resolve/structured.ts +6 -1
  76. package/src/tool/result/candidate-selection.ts +17 -1
  77. package/src/ui/footer.ts +147 -42
  78. package/src/ui/status-overlay.ts +13 -8
@@ -50,7 +50,7 @@ import type {
50
50
  import { FileChangeType } from "../config/types.ts";
51
51
  import { inspectTypeScriptLaunch } from "../config/typescript-launch.ts";
52
52
  import { getTypeScript } from "../config/typescript-module.ts";
53
- import { boundCwd } from "../debug-telemetry.ts";
53
+ import { type BatchedRequestControl, boundCwd, RequestTimingBatch } from "../debug-telemetry.ts";
54
54
  import {
55
55
  accumulateOutstandingDiagnostics,
56
56
  collectDiagnosticSummaryCounts,
@@ -142,15 +142,19 @@ import {
142
142
  type WorkspaceRecoveryResult,
143
143
  } from "./manager-workspace-recovery.ts";
144
144
  import {
145
- collectWorkspaceSymbols,
146
145
  findWorkspaceSymbolWarmTargets,
147
146
  getWorkspaceSymbolWarmPosition,
148
147
  isWithinAnyScope,
148
+ limitWorkspaceSymbolWarmRoots,
149
+ } from "./manager-workspace-symbol.ts";
150
+ import { isFileLocalTopLevelDeclaration } from "./typescript-file-local.ts";
151
+ import {
152
+ collectWorkspaceSymbols,
153
+ joinWorkspaceSymbolReasons,
149
154
  type WorkspaceSymbolCollection,
150
155
  workspaceSymbolCollectionResult,
151
156
  workspaceSymbolCoverageGap,
152
- } from "./manager-workspace-symbol.ts";
153
- import { isFileLocalTopLevelDeclaration } from "./typescript-file-local.ts";
157
+ } from "./workspace-symbol-collection.ts";
154
158
 
155
159
  type UnavailableReason = "missing-command" | "start-failed" | "runtime-error";
156
160
 
@@ -270,6 +274,8 @@ type FileClientRequestOptions = {
270
274
  recoverProcessCrash?: boolean;
271
275
  /** Control only this caller's wait for a shared replacement. */
272
276
  control?: CodeRequestControl;
277
+ /** Receives why a routed client could not open the file; not called for interruptions. */
278
+ onOpenFailure?: (reason: string) => void;
273
279
  };
274
280
 
275
281
  interface FileReadinessResult {
@@ -420,6 +426,31 @@ export class LspManager {
420
426
  * are not reopened, but they do not prove project coverage.
421
427
  */
422
428
  private warmedWorkspaceSymbolFiles = new Map<string, ProjectMembership>();
429
+ /**
430
+ * Routes and scopes whose every project root was probed, with the coverage
431
+ * limit that pass left behind (`null` when none). `workspace/symbol` on a
432
+ * TypeScript server searches only loaded projects, so a result is complete
433
+ * only after such a pass.
434
+ */
435
+ private warmedWorkspaceSymbolRoutes = new Map<string, string | null>();
436
+ /** In-flight all-roots warm-up passes; concurrent queries wait instead of reopening files. */
437
+ private pendingWorkspaceSymbolRouteWarmups = new Map<string, Promise<void>>();
438
+ /**
439
+ * Background all-roots passes by client key (`clientKey`, not the warm-pass
440
+ * route key); no caller owns them, so shutdown and route restart abort them.
441
+ */
442
+ private backgroundWorkspaceSymbolWarmups = new Map<
443
+ string,
444
+ /** `loading` turns true once the client is ready and the pass opens files. */
445
+ { abort: AbortController; loading: boolean }
446
+ >();
447
+ /**
448
+ * Advances when a warm-up opens a file on any route. Rows collected across
449
+ * an advance may miss the project that open loaded.
450
+ */
451
+ private workspaceSymbolLoadGeneration = 0;
452
+ /** Advances on a project-config change; a pass that spans one must not be recorded. */
453
+ private projectConfigGeneration = 0;
423
454
  /** Project roots whose semantic state was warmed with a readiness probe. */
424
455
  private warmedSemanticProjects = new Set<string>();
425
456
  /** In-flight warm-up probes keyed by project key so concurrent callers share one probe. */
@@ -1592,7 +1623,11 @@ export class LspManager {
1592
1623
  private async performStart(route: FileRoute, routeGeneration: number): Promise<LspClient | null> {
1593
1624
  const { serverName, serverConfig, root, key } = route;
1594
1625
  // Client.start resolves again at actual spawn time, including every retry.
1595
- if (this.recordUnavailableLaunch(route)) return null;
1626
+ if (this.recordUnavailableLaunch(route)) {
1627
+ // No client lifecycle runs for an unlaunchable route; publish its new status here.
1628
+ this.publishLifecycle("startup");
1629
+ return null;
1630
+ }
1596
1631
 
1597
1632
  // Spawn new client
1598
1633
  const client = this.createClient(serverName, serverConfig, root, key);
@@ -1624,6 +1659,7 @@ export class LspManager {
1624
1659
  ...(error instanceof Error && error.message ? { failureMessage: error.message } : {}),
1625
1660
  });
1626
1661
  if (this.clients.get(key) === client) this.clients.delete(key);
1662
+ this.publishLifecycle("startup");
1627
1663
  return null;
1628
1664
  }
1629
1665
  }
@@ -1725,6 +1761,8 @@ export class LspManager {
1725
1761
  .getDiagnosticSnapshot()
1726
1762
  .documents.map((document) => uriToFile(document.uri));
1727
1763
  const files = [...new Set([...openFiles, ...trackedDiagnosticFiles])];
1764
+ // Before the shutdown wait: a running pass would start a client for its next file.
1765
+ this.abortBackgroundWorkspaceSymbolWarmup(key);
1728
1766
  try {
1729
1767
  await client.shutdown();
1730
1768
  } catch {
@@ -1805,6 +1843,7 @@ export class LspManager {
1805
1843
  client: this.clients.get(key),
1806
1844
  unavailableReason: this.getUnavailableReason(key, serverName, root) ?? undefined,
1807
1845
  statusReason: this.processCrashRecoveries.get(key)?.statusReason,
1846
+ loadingProjects: this.backgroundWorkspaceSymbolWarmups.get(key)?.loading === true,
1808
1847
  includeOpenFile: (file) => this.isAutomaticScopePath(file),
1809
1848
  },
1810
1849
  this.cwd,
@@ -2219,7 +2258,7 @@ export class LspManager {
2219
2258
  ).slice(0, MAX_BULK_TRACK_FILES);
2220
2259
  if (selected.length === 0) return { outcomes: [] };
2221
2260
 
2222
- this.trackedFilesBatchDepth++;
2261
+ const endTrackedFilesBatch = this.beginTrackedFilesBatch();
2223
2262
  const outcomes = new Array<BulkTrackFileOutcome>(selected.length);
2224
2263
  const workerCount = Math.min(MAX_CONCURRENT_BULK_TRACKS, selected.length);
2225
2264
  let nextIndex = 0;
@@ -2242,14 +2281,25 @@ export class LspManager {
2242
2281
  await Promise.allSettled(workers);
2243
2282
  throw error;
2244
2283
  } finally {
2245
- this.trackedFilesBatchDepth--;
2246
- if (this.trackedFilesBatchDepth === 0 && this.trackedFilesBatchChanged) {
2247
- this.trackedFilesBatchChanged = false;
2248
- this.publishLifecycle("tracked-files");
2249
- }
2284
+ endTrackedFilesBatch();
2250
2285
  }
2251
2286
  }
2252
2287
 
2288
+ /**
2289
+ * Hold back `tracked-files` transitions until the returned function runs,
2290
+ * then publish one for the whole batch. Opening many files otherwise
2291
+ * publishes one transition, and one `runtime.transition` debug event, each.
2292
+ */
2293
+ private beginTrackedFilesBatch(): () => void {
2294
+ this.trackedFilesBatchDepth++;
2295
+ return () => {
2296
+ this.trackedFilesBatchDepth--;
2297
+ if (this.trackedFilesBatchDepth > 0 || !this.trackedFilesBatchChanged) return;
2298
+ this.trackedFilesBatchChanged = false;
2299
+ if (!this.shuttingDown) this.publishLifecycle("tracked-files");
2300
+ };
2301
+ }
2302
+
2253
2303
  private async trackBulkFile(
2254
2304
  filePath: string,
2255
2305
  control?: CodeRequestControl,
@@ -2487,7 +2537,12 @@ export class LspManager {
2487
2537
  */
2488
2538
  noteWorkspaceChanges(changes: FileEvent[]): void {
2489
2539
  if (changes.length > 0) this.invalidationEpoch++;
2490
- if (invalidateProjectConfigCaches(changes)) this.typeScriptProjectConfigs.clear();
2540
+ if (invalidateProjectConfigCaches(changes)) {
2541
+ this.typeScriptProjectConfigs.clear();
2542
+ // A new or changed project config can add a root that was never probed.
2543
+ this.warmedWorkspaceSymbolRoutes.clear();
2544
+ this.projectConfigGeneration++;
2545
+ }
2491
2546
  this.notifyWorkspaceFileChanges(changes);
2492
2547
  }
2493
2548
 
@@ -2654,6 +2709,9 @@ export class LspManager {
2654
2709
  /** Shut down all running LSP servers. */
2655
2710
  async shutdownAll(): Promise<void> {
2656
2711
  this.shuttingDown = true;
2712
+ for (const key of Array.from(this.backgroundWorkspaceSymbolWarmups.keys())) {
2713
+ this.abortBackgroundWorkspaceSymbolWarmup(key);
2714
+ }
2657
2715
  const clients = Array.from(this.clients.values());
2658
2716
  const shutdowns = clients.map((client) => client.shutdown().catch(() => {}));
2659
2717
  await Promise.all([...shutdowns, ...this.retiredClientShutdowns]);
@@ -2675,6 +2733,8 @@ export class LspManager {
2675
2733
  this.unavailable.clear();
2676
2734
  this.knownRoots.clear();
2677
2735
  this.warmedWorkspaceSymbolFiles.clear();
2736
+ this.warmedWorkspaceSymbolRoutes.clear();
2737
+ this.pendingWorkspaceSymbolRouteWarmups.clear();
2678
2738
  this.warmedSemanticProjects.clear();
2679
2739
  this.pendingWarmProbes.clear();
2680
2740
  this.typeScriptProjectConfigs.clear();
@@ -3025,12 +3085,17 @@ export class LspManager {
3025
3085
  Array.from(clients).filter((client) => routeMatches(client)),
3026
3086
  value,
3027
3087
  control,
3088
+ // A scope equal to the session root narrows nothing, so advising a scope still helps.
3089
+ resolvedScopes?.some((scope) => path.resolve(scope) !== path.resolve(this.cwd)) ?? false,
3028
3090
  ),
3029
3091
  demand,
3030
3092
  );
3031
3093
  return this.filterWorkspaceSymbolCollection(collection, resolvedScopes);
3032
3094
  };
3095
+ const loadsBefore = this.workspaceSymbolLoadGeneration;
3033
3096
  const initial = await collect(this.clients.values(), query);
3097
+ // A pass that opened files while these rows were collected may have loaded projects they miss.
3098
+ const initialStale = loadsBefore !== this.workspaceSymbolLoadGeneration;
3034
3099
  // Allowed out-of-scope rows do not show that the server knows the scope yet.
3035
3100
  const hasScopedResult = (collection: WorkspaceSymbolCollection) =>
3036
3101
  collection.hasSupport &&
@@ -3041,9 +3106,14 @@ export class LspManager {
3041
3106
  );
3042
3107
  // Rows from a route whose warm-up reached only inferred projects may come
3043
3108
  // from those files alone, so they cannot end the search early.
3109
+ const answered = hasScopedResult(initial) && !this.hasInferredOnlyWarmRoute(routeMatches);
3110
+ // A route that searches only loaded projects can answer from one project
3111
+ // and miss the same name in another, so its rows do not end the search either.
3044
3112
  if (
3045
3113
  !initial.hasSupport ||
3046
- (hasScopedResult(initial) && !this.hasInferredOnlyWarmRoute(routeMatches))
3114
+ (answered &&
3115
+ !initialStale &&
3116
+ !this.hasUnconfirmedWorkspaceSymbolRoute(routeMatches, resolvedScopes))
3047
3117
  ) {
3048
3118
  return workspaceSymbolCollectionResult(initial);
3049
3119
  }
@@ -3058,14 +3128,76 @@ export class LspManager {
3058
3128
  collect,
3059
3129
  hasResult: hasScopedResult,
3060
3130
  routeMatches,
3131
+ scopes: resolvedScopes,
3132
+ skipFirstResultRoutes: answered,
3133
+ initialStale,
3061
3134
  query,
3062
3135
  control,
3063
3136
  });
3064
- const collection = warmed.collection ?? initial;
3065
- return workspaceSymbolCollectionResult(
3066
- warmed.coverageConfirmed
3067
- ? collection
3068
- : workspaceSymbolCoverageGap(collection, warmed.inferredProbeCount),
3137
+ let collection = warmed.collection ?? initial;
3138
+ if (!warmed.coverageConfirmed) {
3139
+ collection = workspaceSymbolCoverageGap(collection, warmed.inferredProbeCount);
3140
+ }
3141
+ if (warmed.coverageGaps.length > 0) {
3142
+ collection = {
3143
+ ...collection,
3144
+ coverageGap: joinWorkspaceSymbolReasons([collection.coverageGap, ...warmed.coverageGaps]),
3145
+ };
3146
+ }
3147
+ return workspaceSymbolCollectionResult(collection);
3148
+ }
3149
+
3150
+ /**
3151
+ * Load every project of the routes whose `workspace/symbol` searches only
3152
+ * loaded projects, without a query. Runs in the background after startup so
3153
+ * the first symbol query finds the projects loaded; a query that arrives
3154
+ * during the pass waits for it. Resolves when the pass ends, so startup must
3155
+ * not await it. Never rejects.
3156
+ */
3157
+ async startWorkspaceSymbolWarmup(): Promise<void> {
3158
+ const routes = Array.from(this.clients.entries()).filter(
3159
+ ([key, client]) =>
3160
+ this.warmsEveryWorkspaceSymbolProject(client) &&
3161
+ !this.backgroundWorkspaceSymbolWarmups.has(key),
3162
+ );
3163
+ await Promise.all(
3164
+ routes.map(async ([key, client]) => {
3165
+ const warmup = { abort: new AbortController(), loading: false };
3166
+ this.backgroundWorkspaceSymbolWarmups.set(key, warmup);
3167
+ const control = { signal: warmup.abort.signal };
3168
+ try {
3169
+ await client.getReady(control);
3170
+ if (this.clients.get(key) !== client) return;
3171
+ warmup.loading = true;
3172
+ this.publishLifecycle("readiness");
3173
+ await this.warmWorkspaceSymbolProjectsUntilResult({
3174
+ findWarmTargets: (root, rootMarkers, fileTypes) =>
3175
+ findWorkspaceSymbolWarmTargets(root, rootMarkers, fileTypes, {
3176
+ policy: this.automaticPathPolicy,
3177
+ }),
3178
+ getWarmPosition: getWorkspaceSymbolWarmPosition,
3179
+ // No query waits for rows: the pass only loads projects.
3180
+ collect: async () => ({
3181
+ results: [],
3182
+ hasSupport: true,
3183
+ completedClientCount: 0,
3184
+ failures: [],
3185
+ }),
3186
+ hasResult: () => false,
3187
+ routeMatches: (candidate) => candidate === client,
3188
+ skipFirstResultRoutes: true,
3189
+ query: "",
3190
+ control,
3191
+ });
3192
+ } catch {
3193
+ // The first symbol query runs the pass when the background one fails or is aborted.
3194
+ } finally {
3195
+ if (this.backgroundWorkspaceSymbolWarmups.get(key) === warmup) {
3196
+ this.backgroundWorkspaceSymbolWarmups.delete(key);
3197
+ if (warmup.loading && !this.shuttingDown) this.publishLifecycle("readiness");
3198
+ }
3199
+ }
3200
+ }),
3069
3201
  );
3070
3202
  }
3071
3203
 
@@ -3248,10 +3380,83 @@ export class LspManager {
3248
3380
  return client;
3249
3381
  } catch (error) {
3250
3382
  if (isCodeRequestInterruption(error, options.control)) throw error;
3383
+ const reason = error instanceof Error ? error.message : String(error);
3384
+ this.recordOpenFailureEvent(client.name, resolvedPath, reason, options.control);
3385
+ options.onOpenFailure?.(reason);
3251
3386
  return null;
3252
3387
  }
3253
3388
  }
3254
3389
 
3390
+ /**
3391
+ * Record a routed client that could not open a file. The caller only sees
3392
+ * an unavailable result, so this event is the trace of the cause.
3393
+ */
3394
+ private recordOpenFailureEvent(
3395
+ serverName: string,
3396
+ file: string,
3397
+ reason: string,
3398
+ control?: CodeRequestControl,
3399
+ ): void {
3400
+ try {
3401
+ recordDebugEvent({
3402
+ operationId: control?.operationId,
3403
+ source: "lsp",
3404
+ level: "warning",
3405
+ category: "document.open-failed",
3406
+ message: "LSP client could not open a document",
3407
+ cwd: boundCwd(this.cwd),
3408
+ data: {
3409
+ server: truncateIdentity(serverName),
3410
+ file: truncateIdentity(displayRelativeFilePath(file, this.cwd)),
3411
+ reason: truncateIdentity(reason),
3412
+ },
3413
+ });
3414
+ } catch {
3415
+ // Telemetry must never change query behavior.
3416
+ }
3417
+ }
3418
+
3419
+ /**
3420
+ * Record one finished all-roots warm-up pass. Per-file probes are `debug`
3421
+ * events and are not persisted; this summary is. `requests` holds the
3422
+ * completed protocol requests of the pass by method: only an all-roots
3423
+ * pass records this summary, so only its probes batch their timings.
3424
+ */
3425
+ private recordWarmPassEvent(
3426
+ serverName: string,
3427
+ pass: {
3428
+ roots: number;
3429
+ loadedRoots: number;
3430
+ inferredProbes: number;
3431
+ failedProbes: number;
3432
+ limited: boolean;
3433
+ startedAt: number;
3434
+ requestTimings: RequestTimingBatch;
3435
+ },
3436
+ control?: CodeRequestControl,
3437
+ ): void {
3438
+ try {
3439
+ const { startedAt, requestTimings, ...counts } = pass;
3440
+ const requests = requestTimings.snapshot();
3441
+ recordDebugEvent({
3442
+ operationId: control?.operationId,
3443
+ source: "lsp",
3444
+ level: "info",
3445
+ category: "workspace-symbol.warm-pass",
3446
+ message: `Workspace-symbol warm-up loaded ${pass.loadedRoots} of ${pass.roots} project roots`,
3447
+ cwd: boundCwd(this.cwd),
3448
+ data: {
3449
+ server: truncateIdentity(serverName),
3450
+ ...counts,
3451
+ elapsedMs: Math.max(0, Date.now() - startedAt),
3452
+ ...(requests ? { requests } : {}),
3453
+ },
3454
+ });
3455
+ } catch {
3456
+ // Telemetry must never change query behavior.
3457
+ }
3458
+ }
3459
+
3255
3460
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: warm-up coordinates client/project iteration, targeted semantic nudges, and early-return queries in one place.
3256
3461
  private async warmWorkspaceSymbolProjectsUntilResult(options: {
3257
3462
  findWarmTargets: (
@@ -3266,6 +3471,12 @@ export class LspManager {
3266
3471
  /** Stop warming once a collection contains a row that answers the request. */
3267
3472
  hasResult: (collection: WorkspaceSymbolCollection) => boolean;
3268
3473
  routeMatches?: (client: LspClient) => boolean;
3474
+ /** Absolute request scopes, identifying the all-roots pass. */
3475
+ scopes?: readonly string[];
3476
+ /** The initial rows already answer the request for routes that index their workspace. */
3477
+ skipFirstResultRoutes?: boolean;
3478
+ /** The caller's rows predate a recorded pass; collect again before returning. */
3479
+ initialStale?: boolean;
3269
3480
  query: string;
3270
3481
  control?: CodeRequestControl;
3271
3482
  }): Promise<{
@@ -3273,9 +3484,14 @@ export class LspManager {
3273
3484
  /** False only when every probe the server classified landed in an inferred project. */
3274
3485
  coverageConfirmed: boolean;
3275
3486
  inferredProbeCount: number;
3487
+ /** Coverage limits of all-roots passes: roots past the limit, or a config change during the pass. */
3488
+ coverageGaps: string[];
3276
3489
  }> {
3277
3490
  const { findWarmTargets, getWarmPosition, collect, hasResult, routeMatches, query, control } =
3278
3491
  options;
3492
+ const coverageGaps: string[] = [];
3493
+ /** An all-roots pass opened a project after the last collection. */
3494
+ let collectionStale = options.initialStale === true;
3279
3495
  let latestCollection: WorkspaceSymbolCollection | null = null;
3280
3496
  // A route with no inferred probe keeps today's evidence: non-TypeScript
3281
3497
  // servers index the workspace, and `unknown` cannot prove a gap.
@@ -3285,97 +3501,257 @@ export class LspManager {
3285
3501
  collection: latestCollection,
3286
3502
  coverageConfirmed: routeCoverage.every(Boolean),
3287
3503
  inferredProbeCount,
3504
+ coverageGaps,
3288
3505
  });
3289
3506
 
3290
- for (const client of Array.from(this.clients.values())) {
3291
- if (routeMatches && !routeMatches(client)) continue;
3292
- if (client.status !== "running") continue;
3293
- if (!client.serverCapabilities?.workspaceSymbolProvider) continue;
3294
-
3507
+ const warmClients = this.workspaceSymbolWarmClients(
3508
+ routeMatches,
3509
+ options.skipFirstResultRoutes === true,
3510
+ );
3511
+ for (const client of warmClients) {
3512
+ const allRoots = this.warmsEveryWorkspaceSymbolProject(client);
3513
+ if (!allRoots && collectionStale) {
3514
+ latestCollection = await collect(this.clients.values(), query);
3515
+ collectionStale = false;
3516
+ if (hasResult(latestCollection)) return outcome();
3517
+ }
3295
3518
  const serverConfig = this.config.servers[client.name];
3296
3519
  if (!serverConfig) continue;
3297
3520
 
3298
- const warmTargets = findWarmTargets(
3299
- client.root,
3300
- serverConfig.rootMarkers,
3301
- serverConfig.fileTypes,
3302
- ).slice(0, 24);
3303
-
3521
+ const pass = allRoots
3522
+ ? await this.joinOrBeginWorkspaceSymbolRouteWarmup(client, options.scopes, control)
3523
+ : null;
3524
+ if (pass && "recorded" in pass) {
3525
+ if (pass.recorded) coverageGaps.push(pass.recorded);
3526
+ // Another query's pass may have loaded projects after this query's rows.
3527
+ collectionStale ||= pass.waited;
3528
+ continue;
3529
+ }
3304
3530
  // Marker roots whose program an earlier candidate already loaded.
3305
3531
  const coveredRoots = new Set<string>();
3306
- let routeInferred = false;
3307
- for (const target of warmTargets) {
3308
- if (coveredRoots.has(target.projectRoot)) continue;
3309
- // A file probe does not load every program under the route root.
3310
- const fileKey = `${client.name}:${path.resolve(target.file)}`;
3311
- const previous = this.warmedWorkspaceSymbolFiles.get(fileKey);
3312
- if (previous === "inferred") {
3313
- routeInferred = true;
3314
- inferredProbeCount++;
3315
- continue;
3316
- }
3317
- if (previous !== undefined) {
3318
- coveredRoots.add(target.projectRoot);
3319
- continue;
3320
- }
3321
-
3322
- const openedClient = await this.ensureFileOpen(target.file, { control });
3323
- if (!openedClient) {
3324
- this.recordWarmProbeEvent(client.name, target.file, "open-failed", control);
3325
- continue;
3326
- }
3327
-
3328
- // A cancelled pass must not mark projects warmed on its way out.
3329
- throwIfCodeRequestInterrupted(control);
3330
- const available = await this.probeDocumentSymbols(
3331
- openedClient,
3332
- target.file,
3333
- getWarmPosition,
3334
- control,
3532
+ let routeInferredProbes = 0;
3533
+ let failedProbes = 0;
3534
+ let rootLimitGap: string | null = null;
3535
+ let roots = 0;
3536
+ const configGeneration = this.projectConfigGeneration;
3537
+ const timing = { startedAt: Date.now(), requestTimings: new RequestTimingBatch() };
3538
+ try {
3539
+ const candidates = findWarmTargets(
3540
+ client.root,
3541
+ serverConfig.rootMarkers,
3542
+ serverConfig.fileTypes,
3335
3543
  );
3336
- if (!available) {
3337
- this.recordWarmProbeEvent(client.name, target.file, "probe-unavailable", control);
3338
- continue;
3339
- }
3340
- const membership = await openedClient.projectMembership(target.file, control);
3341
- throwIfCodeRequestInterrupted(control);
3342
- this.warmedWorkspaceSymbolFiles.set(fileKey, membership);
3343
- this.recordWarmProbeEvent(client.name, target.file, membership, control);
3344
- if (membership === "inferred") {
3345
- // The file loaded only its own inferred project; workspace/symbol
3346
- // still cannot see the configured program, so try the next file
3347
- // without collecting: a hit here could come from that inferred
3348
- // project alone and would hide the configured program's rows.
3349
- routeInferred = true;
3350
- inferredProbeCount++;
3351
- continue;
3352
- }
3544
+ const limited = allRoots
3545
+ ? limitWorkspaceSymbolWarmRoots(candidates)
3546
+ : { targets: candidates.slice(0, 24), gap: null };
3547
+ rootLimitGap = limited.gap;
3548
+ roots = new Set(limited.targets.map((target) => target.projectRoot)).size;
3549
+ for (const target of limited.targets) {
3550
+ if (coveredRoots.has(target.projectRoot)) continue;
3551
+ // A file probe does not load every program under the route root.
3552
+ const fileKey = `${client.name}:${path.resolve(target.file)}`;
3553
+ const previous = this.warmedWorkspaceSymbolFiles.get(fileKey);
3554
+ if (previous === "inferred") {
3555
+ routeInferredProbes++;
3556
+ inferredProbeCount++;
3557
+ continue;
3558
+ }
3559
+ if (previous !== undefined) {
3560
+ coveredRoots.add(target.projectRoot);
3561
+ continue;
3562
+ }
3353
3563
 
3354
- coveredRoots.add(target.projectRoot);
3355
- latestCollection = await collect(this.clients.values(), query);
3356
- if (hasResult(latestCollection)) {
3357
- return { ...outcome(), coverageConfirmed: true };
3564
+ const membership = await this.probeWorkspaceSymbolWarmFile(
3565
+ client.name,
3566
+ target.file,
3567
+ getWarmPosition,
3568
+ { control, requestTimings: allRoots ? timing.requestTimings : undefined },
3569
+ );
3570
+ if (membership === null) {
3571
+ failedProbes++;
3572
+ continue;
3573
+ }
3574
+ this.warmedWorkspaceSymbolFiles.set(fileKey, membership);
3575
+ if (membership === "inferred") {
3576
+ // The file loaded only its own inferred project; workspace/symbol
3577
+ // still cannot see the configured program, so try the next file
3578
+ // without collecting: a hit here could come from that inferred
3579
+ // project alone and would hide the configured program's rows.
3580
+ routeInferredProbes++;
3581
+ inferredProbeCount++;
3582
+ continue;
3583
+ }
3584
+
3585
+ coveredRoots.add(target.projectRoot);
3586
+ if (allRoots) {
3587
+ // Another root may declare the same name, so keep loading before collecting.
3588
+ collectionStale = true;
3589
+ continue;
3590
+ }
3591
+ latestCollection = await collect(this.clients.values(), query);
3592
+ if (hasResult(latestCollection)) {
3593
+ return { ...outcome(), coverageConfirmed: true };
3594
+ }
3358
3595
  }
3596
+ } finally {
3597
+ pass?.finish();
3598
+ }
3599
+ const covered = coveredRoots.size > 0 || routeInferredProbes === 0;
3600
+ routeCoverage.push(covered);
3601
+ if (!allRoots) continue;
3602
+ if (rootLimitGap) coverageGaps.push(rootLimitGap);
3603
+ // A failed probe is retried, and an inferred-only route recounted, by the next query.
3604
+ if (configGeneration !== this.projectConfigGeneration) {
3605
+ // The change may have added a root this pass never saw; the next query runs its own pass.
3606
+ coverageGaps.push(PROJECT_CONFIG_CHANGED_GAP);
3607
+ } else if (pass && failedProbes === 0 && covered) {
3608
+ this.warmedWorkspaceSymbolRoutes.set(pass.routeKey, rootLimitGap);
3359
3609
  }
3360
- routeCoverage.push(coveredRoots.size > 0 || !routeInferred);
3610
+ const counts = { roots, loadedRoots: coveredRoots.size, failedProbes };
3611
+ this.recordWarmPassEvent(
3612
+ client.name,
3613
+ {
3614
+ ...counts,
3615
+ inferredProbes: routeInferredProbes,
3616
+ limited: rootLimitGap !== null,
3617
+ ...timing,
3618
+ },
3619
+ control,
3620
+ );
3361
3621
  }
3362
3622
 
3363
- if (inferredProbeCount > 0 && latestCollection === null) {
3623
+ if (collectionStale || (inferredProbeCount > 0 && latestCollection === null)) {
3364
3624
  latestCollection = await collect(this.clients.values(), query);
3365
3625
  }
3366
3626
  // A completed-empty retry replaces an earlier failure too.
3367
3627
  return outcome();
3368
3628
  }
3369
3629
 
3630
+ /**
3631
+ * Routes to warm for a symbol query. All-roots routes go first so a
3632
+ * first-result route cannot end the search before them.
3633
+ */
3634
+ private workspaceSymbolWarmClients(
3635
+ routeMatches: ((client: LspClient) => boolean) | undefined,
3636
+ skipFirstResultRoutes: boolean,
3637
+ ): LspClient[] {
3638
+ const clients = Array.from(this.clients.values()).filter(
3639
+ (client) =>
3640
+ (!routeMatches || routeMatches(client)) &&
3641
+ client.status === "running" &&
3642
+ Boolean(client.serverCapabilities?.workspaceSymbolProvider) &&
3643
+ this.config.servers[client.name] !== undefined,
3644
+ );
3645
+ const allRoots = clients.filter((client) => this.warmsEveryWorkspaceSymbolProject(client));
3646
+ return skipFirstResultRoutes
3647
+ ? allRoots
3648
+ : [...allRoots, ...clients.filter((client) => !allRoots.includes(client))];
3649
+ }
3650
+
3651
+ /**
3652
+ * Wait for in-flight all-roots passes on this route, then report the
3653
+ * recorded pass or register this query's own. The last check and the
3654
+ * registration share one synchronous step: with an await between them,
3655
+ * concurrent queries each see no pass and each start one.
3656
+ */
3657
+ private async joinOrBeginWorkspaceSymbolRouteWarmup(
3658
+ client: LspClient,
3659
+ scopes: readonly string[] | undefined,
3660
+ control?: CodeRequestControl,
3661
+ ): Promise<
3662
+ { waited: boolean; recorded: string | null } | { routeKey: string; finish: () => void }
3663
+ > {
3664
+ const routeKey = this.workspaceSymbolRouteWarmKey(client, scopes);
3665
+ let waited = false;
3666
+ for (
3667
+ let running = this.pendingWorkspaceSymbolRouteWarmups.get(routeKey);
3668
+ running !== undefined;
3669
+ running = this.pendingWorkspaceSymbolRouteWarmups.get(routeKey)
3670
+ ) {
3671
+ waited = true;
3672
+ await raceRequestControl(running, control);
3673
+ }
3674
+ const recorded = this.warmedWorkspaceSymbolRoute(client, scopes);
3675
+ if (recorded !== undefined) return { waited, recorded };
3676
+
3677
+ let release = () => {};
3678
+ const pending = new Promise<void>((resolve) => {
3679
+ release = resolve;
3680
+ });
3681
+ this.pendingWorkspaceSymbolRouteWarmups.set(routeKey, pending);
3682
+ // The pass opens one file per project root; publish their tracking once.
3683
+ const endTrackedFilesBatch = this.beginTrackedFilesBatch();
3684
+ return {
3685
+ routeKey,
3686
+ finish: () => {
3687
+ endTrackedFilesBatch();
3688
+ if (this.pendingWorkspaceSymbolRouteWarmups.get(routeKey) === pending) {
3689
+ this.pendingWorkspaceSymbolRouteWarmups.delete(routeKey);
3690
+ }
3691
+ release();
3692
+ },
3693
+ };
3694
+ }
3695
+
3696
+ /**
3697
+ * Open one warm-up file and report the project the server placed it in;
3698
+ * `null` when the file could not be opened or probed. With
3699
+ * `probe.requestTimings`, the probe's completed requests are added to that
3700
+ * batch.
3701
+ */
3702
+ private async probeWorkspaceSymbolWarmFile(
3703
+ serverName: string,
3704
+ file: string,
3705
+ getWarmPosition: (
3706
+ symbols: import("../config/types.ts").DocumentSymbol[] | SymbolInformation[] | null,
3707
+ ) => import("../config/types.ts").Position | null,
3708
+ probe: { control?: CodeRequestControl; requestTimings?: RequestTimingBatch },
3709
+ ): Promise<ProjectMembership | null> {
3710
+ const { control, requestTimings } = probe;
3711
+ const openedClient = await this.ensureFileOpen(file, { control });
3712
+ if (!openedClient) {
3713
+ this.recordWarmProbeEvent(serverName, file, "open-failed", control);
3714
+ return null;
3715
+ }
3716
+ this.workspaceSymbolLoadGeneration++;
3717
+ // A cancelled pass must not mark projects warmed on its way out.
3718
+ throwIfCodeRequestInterrupted(control);
3719
+ const requestControl: BatchedRequestControl | undefined = requestTimings
3720
+ ? { ...control, requestTimings }
3721
+ : control;
3722
+ if (!(await this.probeDocumentSymbols(openedClient, file, getWarmPosition, requestControl))) {
3723
+ this.recordWarmProbeEvent(serverName, file, "probe-unavailable", control);
3724
+ return null;
3725
+ }
3726
+ const reported = await openedClient.projectMembership(file, requestControl);
3727
+ throwIfCodeRequestInterrupted(control);
3728
+ // The native server reports no membership. It does not keep a project loaded
3729
+ // for an open file that project excludes, so the pass tries the next candidate.
3730
+ const excluded =
3731
+ reported === "unknown" &&
3732
+ serverName === "typescript" &&
3733
+ getFileScopeDecision(file, this.cwd).status === "excluded";
3734
+ const membership = excluded ? "inferred" : reported;
3735
+ // An all-roots pass counts its loaded roots in the `warm-pass` summary.
3736
+ if (!requestTimings || membership === "inferred") {
3737
+ this.recordWarmProbeEvent(serverName, file, excluded ? "excluded" : membership, control);
3738
+ }
3739
+ return membership;
3740
+ }
3741
+
3370
3742
  /**
3371
3743
  * Record one workspace-symbol warm-up probe: which file was opened and
3372
3744
  * whether the server placed it in a configured project. `unknown` means the
3373
- * route cannot report membership (non-TypeScript or native TS7).
3745
+ * route cannot report membership (non-TypeScript or native TS7). `excluded`
3746
+ * is a native TS7 probe of a file its nearest project config excludes; the
3747
+ * pass treats it like `inferred`. An all-roots pass records only probes that
3748
+ * did not load a root: failed opens, unavailable probes, and inferred or
3749
+ * excluded files.
3374
3750
  */
3375
3751
  private recordWarmProbeEvent(
3376
3752
  serverName: string,
3377
3753
  file: string,
3378
- outcome: ProjectMembership | "open-failed" | "probe-unavailable",
3754
+ outcome: ProjectMembership | "excluded" | "open-failed" | "probe-unavailable",
3379
3755
  control?: CodeRequestControl,
3380
3756
  ): void {
3381
3757
  try {
@@ -3501,13 +3877,71 @@ export class LspManager {
3501
3877
  return `${serverName}:${path.resolve(projectRoot)}`;
3502
3878
  }
3503
3879
 
3880
+ private abortBackgroundWorkspaceSymbolWarmup(key: string): void {
3881
+ this.backgroundWorkspaceSymbolWarmups.get(key)?.abort.abort();
3882
+ this.backgroundWorkspaceSymbolWarmups.delete(key);
3883
+ }
3884
+
3504
3885
  private clearWarmedWorkspaceSymbolFiles(serverName: string, root: string): void {
3886
+ // The route is restarting or retiring: its background pass must not keep opening files.
3887
+ this.abortBackgroundWorkspaceSymbolWarmup(clientKey(serverName, root));
3505
3888
  const prefix = `${serverName}:${path.resolve(root)}`;
3506
3889
  for (const key of Array.from(this.warmedWorkspaceSymbolFiles.keys())) {
3507
3890
  if (key === prefix || key.startsWith(`${prefix}${path.sep}`)) {
3508
3891
  this.warmedWorkspaceSymbolFiles.delete(key);
3509
3892
  }
3510
3893
  }
3894
+ for (const key of Array.from(this.warmedWorkspaceSymbolRoutes.keys())) {
3895
+ if (key.startsWith(`${prefix}\0`)) this.warmedWorkspaceSymbolRoutes.delete(key);
3896
+ }
3897
+ }
3898
+
3899
+ /**
3900
+ * True for routes whose `workspace/symbol` searches only loaded projects.
3901
+ * Other servers index their workspace, so one answering row is enough.
3902
+ */
3903
+ private warmsEveryWorkspaceSymbolProject(client: LspClient): boolean {
3904
+ return client.name === "typescript";
3905
+ }
3906
+
3907
+ /**
3908
+ * Identity of one all-roots pass. A scope that contains the route root
3909
+ * selects every project root, so it shares the unscoped pass: `code_find`
3910
+ * passes the workspace root as its default scope, symbol targets pass none.
3911
+ */
3912
+ private workspaceSymbolRouteWarmKey(client: LspClient, scopes?: readonly string[]): string {
3913
+ const root = path.resolve(client.root);
3914
+ const prefix = `${client.name}:${root}`;
3915
+ const narrowing = scopes?.some((scope) => projectRoots.isWithinOrEqual(scope, root))
3916
+ ? []
3917
+ : [...(scopes ?? [])];
3918
+ return `${prefix}\0${narrowing.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)).join("\0")}`;
3919
+ }
3920
+
3921
+ /** The recorded all-roots pass for these scopes; an unscoped pass covers every scope. */
3922
+ private warmedWorkspaceSymbolRoute(
3923
+ client: LspClient,
3924
+ scopes?: readonly string[],
3925
+ ): string | null | undefined {
3926
+ const key = this.workspaceSymbolRouteWarmKey(client, scopes);
3927
+ return this.warmedWorkspaceSymbolRoutes.has(key)
3928
+ ? this.warmedWorkspaceSymbolRoutes.get(key)
3929
+ : this.warmedWorkspaceSymbolRoutes.get(this.workspaceSymbolRouteWarmKey(client));
3930
+ }
3931
+
3932
+ /** True when a matching route still needs an all-roots pass or carries its coverage limit. */
3933
+ private hasUnconfirmedWorkspaceSymbolRoute(
3934
+ routeMatches: (client: LspClient) => boolean,
3935
+ scopes?: readonly string[],
3936
+ ): boolean {
3937
+ return Array.from(this.clients.values()).some(
3938
+ (client) =>
3939
+ routeMatches(client) &&
3940
+ client.status === "running" &&
3941
+ Boolean(client.serverCapabilities?.workspaceSymbolProvider) &&
3942
+ this.warmsEveryWorkspaceSymbolProject(client) &&
3943
+ this.warmedWorkspaceSymbolRoute(client, scopes) !== null,
3944
+ );
3511
3945
  }
3512
3946
 
3513
3947
  private clearWarmedSemanticProjects(serverName: string, root: string): void {
@@ -3529,6 +3963,10 @@ export class LspManager {
3529
3963
  }
3530
3964
  }
3531
3965
 
3966
+ /** Coverage limit of an all-roots pass that a project-config change overtook. */
3967
+ const PROJECT_CONFIG_CHANGED_GAP =
3968
+ "Workspace-symbol coverage is limited: a project config changed while projects were loading. Retry to include every project.";
3969
+
3532
3970
  /** Invalidate parsed project configs; returns whether any config changed. */
3533
3971
  function invalidateProjectConfigCaches(changes: readonly FileEvent[]): boolean {
3534
3972
  let changed = false;