@mrclrchtr/supi-code-intelligence 11.3.0 → 12.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 (132) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +15 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  7. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  8. package/node_modules/@mrclrchtr/supi-lsp/README.md +22 -17
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  19. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
  20. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
  25. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
  27. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +67 -3
  30. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
  32. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
  34. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  35. package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +106 -16
  37. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
  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/api.ts +3 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
  58. package/package.json +5 -5
  59. package/src/analysis/health/server-status.ts +41 -12
  60. package/src/analysis/helpers.ts +0 -7
  61. package/src/analysis/relations/implementations.ts +5 -0
  62. package/src/analysis/relations/references.ts +5 -0
  63. package/src/analysis/target/anchored-structural.ts +4 -1
  64. package/src/analysis/target/file-merge.ts +162 -0
  65. package/src/analysis/target/file-outline-omissions.ts +146 -0
  66. package/src/analysis/target/file-refinement.ts +7 -7
  67. package/src/analysis/target/file.ts +44 -156
  68. package/src/analysis/target/symbol.ts +5 -1
  69. package/src/analysis/target/types.ts +32 -6
  70. package/src/api.ts +1 -1
  71. package/src/app/app.ts +9 -3
  72. package/src/session/find-types.ts +8 -4
  73. package/src/session/find-workflow.ts +11 -16
  74. package/src/session/graph/collect.ts +2 -0
  75. package/src/session/graph-types.ts +3 -1
  76. package/src/session/graph-workflow.ts +5 -4
  77. package/src/session/input/health-refactor.ts +48 -34
  78. package/src/session/input/workflows.ts +45 -46
  79. package/src/session/inspect/file-point.ts +2 -2
  80. package/src/session/inspect-types.ts +1 -1
  81. package/src/session/inspect-workflow.ts +3 -3
  82. package/src/session/orientation/workspace-context.ts +3 -0
  83. package/src/session/orientation-workflow.ts +6 -3
  84. package/src/session/refactor-file-actions.ts +122 -0
  85. package/src/session/refactor-plan-pipeline.ts +152 -0
  86. package/src/session/refactor-plans.ts +18 -15
  87. package/src/session/refactor-types.ts +24 -12
  88. package/src/session/refactor-workflow.ts +70 -244
  89. package/src/session/session.ts +87 -12
  90. package/src/session/target-workflow.ts +23 -21
  91. package/src/tool/code_find/execute.ts +6 -7
  92. package/src/tool/code_find/spec.ts +9 -16
  93. package/src/tool/code_find/tui.ts +12 -6
  94. package/src/tool/code_graph/section.ts +4 -0
  95. package/src/tool/code_graph/spec.ts +6 -0
  96. package/src/tool/code_health/spec.ts +6 -0
  97. package/src/tool/code_health/structured-schema.ts +4 -4
  98. package/src/tool/code_health/structured.ts +15 -17
  99. package/src/tool/code_inspect/execute.ts +1 -1
  100. package/src/tool/code_inspect/markdown.ts +33 -6
  101. package/src/tool/code_inspect/result.ts +1 -1
  102. package/src/tool/code_inspect/spec.ts +14 -6
  103. package/src/tool/code_inspect/structured.ts +2 -2
  104. package/src/tool/code_inspect/tui.ts +2 -2
  105. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  106. package/src/tool/code_orientation/spec.ts +8 -0
  107. package/src/tool/code_orientation/workspace-output.ts +40 -13
  108. package/src/tool/code_orientation/workspace-sections.ts +45 -2
  109. package/src/tool/code_refactor_apply/result.ts +2 -1
  110. package/src/tool/code_refactor_apply/spec.ts +7 -0
  111. package/src/tool/code_refactor_plan/execute.ts +0 -2
  112. package/src/tool/code_refactor_plan/result.ts +23 -13
  113. package/src/tool/code_refactor_plan/spec.ts +8 -2
  114. package/src/tool/code_refactor_plan/structured.ts +59 -12
  115. package/src/tool/code_refactor_plan/tui.ts +14 -17
  116. package/src/tool/code_resolve/guidance.ts +1 -1
  117. package/src/tool/code_resolve/markdown.ts +121 -34
  118. package/src/tool/code_resolve/result.ts +18 -15
  119. package/src/tool/code_resolve/spec.ts +6 -0
  120. package/src/tool/code_resolve/structured.ts +43 -10
  121. package/src/tool/namespace.ts +14 -0
  122. package/src/tool/refactor-markdown.ts +55 -15
  123. package/src/tool/register.ts +3 -0
  124. package/src/tool/result/model-budget.ts +2 -2
  125. package/src/tool/result/refactor-preview.ts +118 -0
  126. package/src/tool/result/refactor-unavailable.ts +16 -0
  127. package/src/tool/result/refactor.ts +8 -2
  128. package/src/tool/result/types.ts +13 -10
  129. package/src/tool/schemas.ts +63 -20
  130. package/src/tool/specs.ts +3 -0
  131. package/src/ui/status-overlay.ts +1 -1
  132. package/src/ui/tui/common.ts +10 -10
@@ -1,11 +1,13 @@
1
1
  // Shared session-scoped LSP service registry reused by peer extensions.
2
2
 
3
3
  // biome-ignore lint/style/noExcessiveLinesPerFile: session registry, runtime recovery, and telemetry stay in one file; splitting would hide the recovery contract.
4
+ import { fileURLToPath } from "node:url";
4
5
  import {
5
6
  type CodeQueryResult,
6
7
  type CodeRequestControl,
7
8
  isCodeRequestInterruption,
8
9
  mapCodeQueryResult,
10
+ partialCodeQuery,
9
11
  throwIfCodeRequestInterrupted,
10
12
  unavailableCodeQuery,
11
13
  } from "@mrclrchtr/supi-code-runtime/api";
@@ -16,6 +18,8 @@ import {
16
18
  import { resolveToolPath as resolveSessionPath } from "@mrclrchtr/supi-core/path";
17
19
  import { createSessionStateRegistry } from "@mrclrchtr/supi-core/session";
18
20
  import { CodeActionTriggerKind } from "vscode-languageserver-types";
21
+ import type { CommandEditCaptureResult } from "../client/client-edit-capture.ts";
22
+ import { advertisedCodeActionKinds } from "../config/operation-support.ts";
19
23
  import type {
20
24
  CodeAction,
21
25
  Diagnostic,
@@ -37,7 +41,12 @@ import type {
37
41
  WorkspaceSentinelSyncResult,
38
42
  } from "../diagnostics/workspace-sentinels.ts";
39
43
  import type { LspManager } from "../manager/manager.ts";
44
+ import {
45
+ COMMAND_ONLY_ACTION_REASON,
46
+ captureEligibleActions,
47
+ } from "../provider/refactor-command-capture.ts";
40
48
  import { raceReadinessValue } from "./readiness.ts";
49
+ import { outsideRouteRootReason } from "./route-boundary.ts";
41
50
  import type {
42
51
  DiagnosticEvidenceSummary,
43
52
  ProcessCrashRecoveryReport,
@@ -47,6 +56,7 @@ import type {
47
56
  import { runRoutedRename } from "./runtime-rename.ts";
48
57
  import type {
49
58
  BulkTrackFilesResult,
59
+ RoutedCodeActionResponse,
50
60
  RoutedMutationResponse,
51
61
  SemanticReadinessResult,
52
62
  WorkspaceCodeActionRequestOptions,
@@ -54,6 +64,9 @@ import type {
54
64
  WorkspaceLspRuntimeState,
55
65
  } from "./workspace-lsp-runtime.ts";
56
66
 
67
+ /** Upper bound for a server command run to capture its pushed edit. */
68
+ const COMMAND_CAPTURE_TIMEOUT_MS = 10_000;
69
+
57
70
  export type {
58
71
  ProcessCrashDiagnosticDemand,
59
72
  WorkspaceLspDiagnosticSurface,
@@ -82,6 +95,7 @@ export {
82
95
  export type {
83
96
  BulkTrackFileOutcome,
84
97
  BulkTrackFilesResult,
98
+ RoutedCodeActionResponse,
85
99
  RoutedMutationDocumentSnapshot,
86
100
  RoutedMutationResponse,
87
101
  SemanticReadinessResult,
@@ -193,9 +207,14 @@ class DefaultWorkspaceLspRuntime implements WorkspaceLspRuntime {
193
207
  control,
194
208
  });
195
209
  if (!client) return unavailableFileQuery("references", resolvedPath);
196
- return mapCodeQueryResult(
197
- await client.references(resolvedPath, position, control),
198
- (data) => data ?? [],
210
+ return this.withProjectCoverage(
211
+ client,
212
+ { file: resolvedPath, position },
213
+ "references",
214
+ mapCodeQueryResult(
215
+ await client.references(resolvedPath, position, control),
216
+ (data) => data ?? [],
217
+ ),
199
218
  );
200
219
  }
201
220
 
@@ -211,7 +230,30 @@ class DefaultWorkspaceLspRuntime implements WorkspaceLspRuntime {
211
230
  control,
212
231
  });
213
232
  if (!client) return unavailableFileQuery("implementation", resolvedPath);
214
- return client.implementation(resolvedPath, position, control);
233
+ return this.withProjectCoverage(
234
+ client,
235
+ { file: resolvedPath, position },
236
+ "implementation",
237
+ await client.implementation(resolvedPath, position, control),
238
+ );
239
+ }
240
+
241
+ /**
242
+ * Downgrade a completed project-wide answer to partial when the TypeScript
243
+ * server may not have searched every relevant project.
244
+ */
245
+ private withProjectCoverage<T extends Location[] | Location | LocationLink[] | null>(
246
+ client: NonNullable<Awaited<ReturnType<LspManager["ensureFileOpen"]>>>,
247
+ target: { readonly file: string; readonly position: Position },
248
+ request: "references" | "implementation",
249
+ result: CodeQueryResult<T>,
250
+ ): CodeQueryResult<T> {
251
+ if (result.kind !== "completed") return result;
252
+ const gap = this.manager.typeScriptProjectCoverageGap(client, target.file, request, {
253
+ resultFiles: locationFiles(result.data),
254
+ position: target.position,
255
+ });
256
+ return gap ? partialCodeQuery(result.data, gap) : result;
215
257
  }
216
258
 
217
259
  async documentSymbols(
@@ -258,12 +300,39 @@ class DefaultWorkspaceLspRuntime implements WorkspaceLspRuntime {
258
300
  return this.manager.getOpenDocumentVersion(this.resolveFilePath(filePath));
259
301
  }
260
302
 
303
+ async captureCodeActionEdit(
304
+ filePath: string,
305
+ action: CodeAction,
306
+ control?: CodeRequestControl,
307
+ ): Promise<RoutedMutationResponse<CommandEditCaptureResult | null> | null> {
308
+ const resolvedPath = this.resolveFilePath(filePath);
309
+ const client = await this.manager.ensureFileOpen(resolvedPath, {
310
+ recoverProcessCrash: true,
311
+ protectInputs: true,
312
+ control,
313
+ });
314
+ if (!client) return null;
315
+ const authorizedMutationRoots = [client.root];
316
+ const outside = outsideRouteRootReason(resolvedPath, client.root);
317
+ if (outside) return { value: null, authorizedMutationRoots, reason: outside };
318
+ const listed = client.serverCapabilities?.executeCommandProvider?.commands;
319
+ const [eligible] = captureEligibleActions([action], Array.isArray(listed) ? listed : undefined);
320
+ if (!eligible) {
321
+ return { value: null, authorizedMutationRoots, reason: COMMAND_ONLY_ACTION_REASON };
322
+ }
323
+ const value = await client.captureCommandEdits(eligible.command, {
324
+ timeoutMs: COMMAND_CAPTURE_TIMEOUT_MS,
325
+ ...(control ? { control } : {}),
326
+ });
327
+ return { value, authorizedMutationRoots };
328
+ }
329
+
261
330
  async codeActions(
262
331
  filePath: string,
263
332
  positionOrRange: Position | Range,
264
333
  control?: CodeRequestControl,
265
334
  options?: WorkspaceCodeActionRequestOptions,
266
- ): Promise<RoutedMutationResponse<CodeAction[] | null> | null> {
335
+ ): Promise<RoutedCodeActionResponse | null> {
267
336
  const resolvedPath = this.resolveFilePath(filePath);
268
337
  const client = await this.manager.ensureFileOpen(resolvedPath, {
269
338
  recoverProcessCrash: true,
@@ -271,6 +340,10 @@ class DefaultWorkspaceLspRuntime implements WorkspaceLspRuntime {
271
340
  control,
272
341
  });
273
342
  if (!client) return null;
343
+ const outside = outsideRouteRootReason(resolvedPath, client.root);
344
+ if (outside) {
345
+ return { value: null, authorizedMutationRoots: [client.root], reason: outside };
346
+ }
274
347
 
275
348
  const range = isRange(positionOrRange)
276
349
  ? positionOrRange
@@ -285,21 +358,23 @@ class DefaultWorkspaceLspRuntime implements WorkspaceLspRuntime {
285
358
  triggerKind: options?.triggerKind ?? CodeActionTriggerKind.Invoked,
286
359
  ...(options?.only ? { only: [...options.only] } : {}),
287
360
  };
361
+ const advertisedKinds = advertisedCodeActionKinds(client.serverCapabilities ?? null);
362
+ const advertisedCommands = client.serverCapabilities?.executeCommandProvider?.commands;
363
+ const routed = {
364
+ authorizedMutationRoots: [client.root],
365
+ ...(advertisedKinds ? { advertisedKinds } : {}),
366
+ ...(Array.isArray(advertisedCommands) ? { advertisedCommands } : {}),
367
+ };
288
368
  if (typeof client.codeActionsDetailed === "function") {
289
369
  const result = await client.codeActionsDetailed(resolvedPath, range, context, control);
290
- return {
291
- value: result.kind === "completed" ? result.data : null,
292
- authorizedMutationRoots: [client.root],
293
- ...(result.kind === "unavailable"
294
- ? { reason: result.reason }
295
- : result.data === null
296
- ? { reason: "LSP server returned no code actions." }
297
- : {}),
298
- };
370
+ // A completed `null` result means the server has no actions here (LSP spec).
371
+ return result.kind === "completed"
372
+ ? { ...routed, value: result.data ?? [] }
373
+ : { ...routed, value: null, reason: result.reason };
299
374
  }
300
375
  return {
301
- value: await client.codeActions(resolvedPath, range, context, control),
302
- authorizedMutationRoots: [client.root],
376
+ ...routed,
377
+ value: (await client.codeActions(resolvedPath, range, context, control)) ?? [],
303
378
  };
304
379
  }
305
380
 
@@ -605,6 +680,21 @@ export async function waitForWorkspaceLspRuntime(
605
680
  return state;
606
681
  }
607
682
 
683
+ /** Local file paths of LSP locations or location links; non-file URIs are skipped. */
684
+ function locationFiles(data: Location[] | Location | LocationLink[] | null): string[] {
685
+ const items: (Location | LocationLink)[] =
686
+ data === null ? [] : Array.isArray(data) ? data : [data];
687
+ return items.flatMap((item) => {
688
+ const uri = "targetUri" in item ? item.targetUri : item.uri;
689
+ if (!uri.startsWith("file:")) return [];
690
+ try {
691
+ return [fileURLToPath(uri)];
692
+ } catch {
693
+ return [];
694
+ }
695
+ });
696
+ }
697
+
608
698
  /** Remove the LSP service state for a session cwd. */
609
699
  export function clearWorkspaceLspRuntime(cwd: string): void {
610
700
  registry.clear(cwd);
@@ -5,6 +5,7 @@ import type { SemanticInputDocumentSnapshot } from "../client/client-semantic-in
5
5
  import type { Position, WorkspaceEdit } from "../config/types.ts";
6
6
  import type { LspManager } from "../manager/manager.ts";
7
7
  import { discoverSemanticEditFiles } from "../provider/semantic-edit-discovery.ts";
8
+ import { outsideRouteRootReason } from "./route-boundary.ts";
8
9
  import type {
9
10
  RoutedMutationDocumentSnapshot,
10
11
  RoutedMutationResponse,
@@ -26,6 +27,8 @@ export async function runRoutedRename(options: {
26
27
  });
27
28
  if (!client) return null;
28
29
  const authorizedMutationRoots = [client.root];
30
+ const outside = outsideRouteRootReason(file, client.root);
31
+ if (outside) return { value: null, authorizedMutationRoots, reason: outside };
29
32
 
30
33
  if (typeof client.renameDetailedWithSnapshots === "function") {
31
34
  return renameWithSnapshots({
@@ -1,4 +1,5 @@
1
1
  import type { CodeQueryResult, CodeRequestControl } from "@mrclrchtr/supi-code-runtime/api";
2
+ import type { CommandEditCaptureResult } from "../client/client-edit-capture.ts";
2
3
  import type {
3
4
  CodeAction,
4
5
  CodeActionContext,
@@ -80,6 +81,14 @@ export interface RoutedMutationResponse<T> {
80
81
  readonly reason?: string;
81
82
  }
82
83
 
84
+ /** One code-action response with the routed server's negotiated kinds. */
85
+ export interface RoutedCodeActionResponse extends RoutedMutationResponse<CodeAction[] | null> {
86
+ /** Negotiated `codeActionProvider.codeActionKinds`; undefined when the server did not narrow them. */
87
+ readonly advertisedKinds?: readonly string[];
88
+ /** Negotiated `executeCommandProvider.commands`; undefined when the server lists none. */
89
+ readonly advertisedCommands?: readonly string[];
90
+ }
91
+
83
92
  /** Extra protocol context for one explicit code-action request. */
84
93
  export interface WorkspaceCodeActionRequestOptions {
85
94
  /** Operation-specific CodeActionKind filters. */
@@ -164,7 +173,19 @@ export interface WorkspaceLspRuntime extends WorkspaceLspDiagnosticSurface {
164
173
  positionOrRange: Position | Range,
165
174
  control?: CodeRequestControl,
166
175
  options?: WorkspaceCodeActionRequestOptions,
167
- ): Promise<RoutedMutationResponse<CodeAction[] | null> | null>;
176
+ ): Promise<RoutedCodeActionResponse | null>;
177
+ /**
178
+ * Run the command of one command-only code action on the client routed to
179
+ * `filePath` and capture the single edit the server pushes. No pushed edit is
180
+ * applied. The runtime enforces eligibility itself: a `refactor*`,
181
+ * `source.organizeImports*`, or `source.fixAll*` kind, and a command the
182
+ * server lists when it lists any; other actions are unavailable unrun.
183
+ */
184
+ captureCodeActionEdit(
185
+ filePath: string,
186
+ action: CodeAction,
187
+ control?: CodeRequestControl,
188
+ ): Promise<RoutedMutationResponse<CommandEditCaptureResult | null> | null>;
168
189
  getOpenDocumentVersion(filePath: string): number | null;
169
190
  /**
170
191
  * Wait for file readiness; an explicit refresh may make one shared route
@@ -82,7 +82,7 @@ The `type` filter accepts `class`, `interface`, `type`, `enum`, `struct`, `union
82
82
  ### Extraction limits
83
83
 
84
84
  - TS/JS, Python, Java, Go, Rust, and C/C++ outlines include nested named declarations and members. They are not complete indexes of local variables, parameters, or anonymous expressions. Other languages retain their existing extraction depth. HTML outlines list only elements with non-empty `id` attributes. SQL outlines list supported `CREATE` declarations and first-level table/type members. LaTeX outlines list section headings and selected command, environment, label, acronym, glossary-entry, and color definitions.
85
- - TypeScript and TSX use [checked build-time grammar patches](scripts/generate-typescript-wasm.mjs) for type-only star re-exports, arrays of qualified import types such as `import("node:fs").Dirent[]`, and import types in generic calls such as `read<import("./api").Value>()` or `read<typeof import("./api")>()`. Runtime parsing retains the original source and coordinates; other grammar gaps still report recovered syntax.
85
+ - TypeScript and TSX use [checked build-time grammar patches](scripts/generate-typescript-wasm.mjs) for type-only star re-exports, arrays of qualified import types such as `import("node:fs").Dirent[]`, import types in generic calls such as `read<import("./api").Value>()` or `read<typeof import("./api")>()`, and import types with type arguments such as `import("typebox").Static<T>`. Runtime parsing retains the original source and coordinates; other grammar gaps still report recovered syntax.
86
86
  - JavaScript-family imports collect `import` statements, not CommonJS `require()` calls. Exports collect file-level `export` statements, including TypeScript `export =`; they do not collect `module.exports` assignments or nested namespace exports. An eligible `.cjs` file can therefore return no imports or exports.
87
87
  - Python imports retain `import`/`from` module targets, including relative prefixes. Java imports retain ordinary/static targets. Go imports retain single/grouped paths. Rust imports retain explicit `use` paths, `extern crate`, and external `mod` names; inline module bodies are not imports. C/C++ imports retain literal quoted and angle-bracket include targets. Grouped paths use explicit syntax only; no files or bindings are resolved. Conditional directives are written evidence, not proof of active dependencies. Dynamic loaders, computed targets, and C++20 module imports remain outside extraction support.
88
88
  - LaTeX imports include package, class, source, and bibliography directives. Bibliography directives can refer to `.bib` files, but the grammar does not parse those files.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-code-runtime",
3
- "version": "11.3.0",
3
+ "version": "12.0.0",
4
4
  "description": "Shared workspace context and capability contracts for code intelligence",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,6 +14,7 @@ export type {
14
14
  StructuralProvider,
15
15
  StructuralResult,
16
16
  } from "./capability/types.ts";
17
+ export { childDeclarationLevel } from "./declaration-level.ts";
17
18
  export type {
18
19
  CFamilyExtension,
19
20
  CFamilyFileAssociationResolver,
@@ -50,7 +51,7 @@ export type {
50
51
  CodeResult,
51
52
  CodeSymbol,
52
53
  ConfidenceMode,
53
- DeclarationNesting,
54
+ DeclarationLevel,
54
55
  DisambiguationCandidate,
55
56
  DocumentCodeSymbol,
56
57
  DocumentEditPrecondition,
@@ -59,6 +60,7 @@ export type {
59
60
  ImportData,
60
61
  NodeAtData,
61
62
  OutlineData,
63
+ RefactorActionIdentity,
62
64
  RefactorOperation,
63
65
  RefactorRequest,
64
66
  RefactorResult,
@@ -0,0 +1,34 @@
1
+ import type { DeclarationLevel } from "./types.ts";
2
+
3
+ /** Declarations whose body holds statements, so nested declarations are local to it. */
4
+ const FUNCTION_LIKE_KINDS = new Set(["function", "method", "constructor"]);
5
+ /** Bindings whose value may be a function (locals) or an object literal (members). */
6
+ const VALUE_BINDING_KINDS = new Set(["variable", "constant", "property", "field"]);
7
+ /** Kinds that name an entry of an object, type, or enum rather than a statement-level binding. */
8
+ const MEMBER_ENTRY_KINDS = new Set(["property", "field", "method", "enummember", "key", "event"]);
9
+
10
+ /**
11
+ * Level of a declaration reported directly inside `parent`.
12
+ *
13
+ * Inside a local declaration everything stays local. A function, method, or
14
+ * constructor makes its nested declarations local. A variable, constant,
15
+ * property, or field holds either a function body (nested bindings are local)
16
+ * or an object literal (nested properties and methods are members). Every
17
+ * other container — class, interface, enum, struct, namespace, module, or a
18
+ * document section — makes its nested declarations members.
19
+ *
20
+ * Kinds compare case-insensitively, so LSP SymbolKind names and Tree-sitter
21
+ * outline kinds share one rule.
22
+ */
23
+ export function childDeclarationLevel(
24
+ parent: { readonly kind: string | null; readonly level: DeclarationLevel },
25
+ childKind: string | null,
26
+ ): Exclude<DeclarationLevel, "top-level" | "unknown"> {
27
+ if (parent.level === "local") return "local";
28
+ const parentKind = parent.kind?.toLowerCase() ?? "";
29
+ if (FUNCTION_LIKE_KINDS.has(parentKind)) return "local";
30
+ if (VALUE_BINDING_KINDS.has(parentKind)) {
31
+ return MEMBER_ENTRY_KINDS.has(childKind?.toLowerCase() ?? "") ? "member" : "local";
32
+ }
33
+ return "member";
34
+ }
@@ -34,8 +34,16 @@ export interface SymbolAnchor {
34
34
  character: number;
35
35
  }
36
36
 
37
- /** Provider-backed nesting evidence for a declaration reported within one document. */
38
- export type DeclarationNesting = "top-level" | "nested" | "unknown";
37
+ /**
38
+ * Where a declaration sits within its file, as reported by a provider.
39
+ *
40
+ * - `top-level`: directly in the file, not inside another declaration.
41
+ * - `member`: directly inside a class, interface, enum, struct, namespace,
42
+ * module, or object literal (methods, fields, properties, enum members).
43
+ * - `local`: inside the body of a function, method, or constructor.
44
+ * - `unknown`: the provider reported a flat symbol list without hierarchy.
45
+ */
46
+ export type DeclarationLevel = "top-level" | "member" | "local" | "unknown";
39
47
 
40
48
  /**
41
49
  * A discovered symbol / declaration.
@@ -54,7 +62,7 @@ export interface CodeSymbol {
54
62
  file: string;
55
63
  declarationAnchor: SymbolAnchor;
56
64
  nameAnchor?: SymbolAnchor;
57
- /** Named symbolic container when reported; absence does not prove top-level nesting. */
65
+ /** Named enclosing declaration when reported; absence does not prove a top-level declaration. */
58
66
  container?: string | null;
59
67
  }
60
68
 
@@ -63,10 +71,10 @@ export interface CodeSymbol {
63
71
  *
64
72
  * `unknown` means the provider returned a flat observation without an actual
65
73
  * hierarchy. A reported container name remains metadata and does not promote
66
- * a flat observation to known nesting.
74
+ * a flat observation to a known level.
67
75
  */
68
76
  export interface DocumentCodeSymbol extends CodeSymbol {
69
- nesting: DeclarationNesting;
77
+ level: DeclarationLevel;
70
78
  }
71
79
 
72
80
  // ── Result types ───────────────────────────────────────────────────────
@@ -185,31 +193,53 @@ export interface WorkspaceEdit {
185
193
  }
186
194
 
187
195
  /**
188
- * Supported refactor operation names for the current semantic planning path.
189
- */
190
- export type RefactorOperation =
191
- | "rename_symbol"
192
- | "extract_function"
193
- | "extract_variable"
194
- | "rename_file"
195
- | "move_file"
196
- | "update_imports"
197
- | "delete_dead_code";
198
-
199
- /**
200
- * Operation-aware refactor planning request.
196
+ * Operation-aware refactor planning request. Each operation carries only the
197
+ * scope it needs:
198
+ *
199
+ * - `rename_symbol`: one symbol position and the new name.
200
+ * - `code_action`: one file range and a CodeActionKind prefix under `refactor`.
201
+ * - `source_action`: one whole file and a CodeActionKind prefix under `source`.
201
202
  *
202
- * Consumers provide a target file/position plus operation-specific options.
203
- * File/resource operations remain requestable so providers can reject them
204
- * explicitly and honestly until shared workspace-edit resource ops exist.
203
+ * `kind` matches the requested kind and its dotted sub-kinds. `title`, when
204
+ * present, selects one action by its exact title.
205
205
  */
206
- export interface RefactorRequest {
207
- operation: RefactorOperation;
208
- file: string;
209
- position: CodePosition;
210
- range?: SourceRange;
211
- newName?: string;
212
- destination?: string;
206
+ export type RefactorRequest =
207
+ | {
208
+ operation: "rename_symbol";
209
+ file: string;
210
+ position: CodePosition;
211
+ newName: string;
212
+ }
213
+ | {
214
+ operation: "code_action";
215
+ file: string;
216
+ range: SourceRange;
217
+ kind: string;
218
+ title?: string;
219
+ }
220
+ | {
221
+ operation: "source_action";
222
+ file: string;
223
+ kind: string;
224
+ title?: string;
225
+ };
226
+
227
+ /** Supported refactor operation names. */
228
+ export type RefactorOperation = RefactorRequest["operation"];
229
+
230
+ /** The code action selected for a precise code- or source-action plan. */
231
+ export interface RefactorActionIdentity {
232
+ /** Server-reported CodeActionKind. */
233
+ kind: string;
234
+ /** Server-reported action title. */
235
+ title: string;
236
+ /**
237
+ * How the edits were obtained: `edit` from the action itself (after
238
+ * `codeAction/resolve` when needed), or `captured-command` from the single
239
+ * `workspace/applyEdit` the server pushed while running the action's command.
240
+ * Captured edits were refused, never applied.
241
+ */
242
+ provenance?: "edit" | "captured-command";
213
243
  }
214
244
 
215
245
  /**
@@ -220,6 +250,10 @@ export interface DisambiguationCandidate {
220
250
  file?: string;
221
251
  line?: number;
222
252
  character?: number;
253
+ /** Server-reported CodeActionKind, for code-action candidates. */
254
+ kind?: string;
255
+ /** Exact action title to pass back as `title`, for code-action candidates. */
256
+ title?: string;
223
257
  }
224
258
 
225
259
  /**
@@ -233,6 +267,8 @@ export type RefactorResult =
233
267
  | {
234
268
  kind: "precise";
235
269
  edits: WorkspaceEdit;
270
+ /** The selected code action, for code- and source-action plans. */
271
+ action?: RefactorActionIdentity;
236
272
  /** Provider roots authorized by the semantic route. Consumers canonicalize before storage. */
237
273
  authorizedMutationRoots: string[];
238
274
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "11.3.0",
3
+ "version": "12.0.0",
4
4
  "description": "Shared settings, configuration, reporting, and session infrastructure",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-tree-sitter",
3
- "version": "11.3.0",
3
+ "version": "12.0.0",
4
4
  "description": "Structural AST analysis for SuPi code intelligence",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,8 +36,8 @@
36
36
  "dependencies": {
37
37
  "jiti": "^2.7.0",
38
38
  "web-tree-sitter": "^0.27.0",
39
- "@mrclrchtr/supi-code-runtime": "11.3.0",
40
- "@mrclrchtr/supi-core": "11.3.0"
39
+ "@mrclrchtr/supi-code-runtime": "12.0.0",
40
+ "@mrclrchtr/supi-core": "12.0.0"
41
41
  },
42
42
  "bundledDependencies": [
43
43
  "@mrclrchtr/supi-code-runtime",
@@ -22,7 +22,11 @@
22
22
  {
23
23
  "id": "import-type-generic-calls-v1",
24
24
  "file": "common/define-grammar.js"
25
+ },
26
+ {
27
+ "id": "import-type-member-type-arguments-v1",
28
+ "file": "common/define-grammar.js"
25
29
  }
26
30
  ],
27
- "sha256": "aaa2904a00000d8e058708845172bd3ce7836566c7e16e9ee594c43f4ba4f451"
31
+ "sha256": "7c7552ea30a3a6785826e26c12c9dd33410ac577d9cb09a4fa5cf5701665abd8"
28
32
  }
@@ -22,7 +22,11 @@
22
22
  {
23
23
  "id": "import-type-generic-calls-v1",
24
24
  "file": "common/define-grammar.js"
25
+ },
26
+ {
27
+ "id": "import-type-member-type-arguments-v1",
28
+ "file": "common/define-grammar.js"
25
29
  }
26
30
  ],
27
- "sha256": "86ba3af6f8214c90f32af1ea82214a0c1da87c9e2f5ea47c19577ba5b6c78bfb"
31
+ "sha256": "d9e67877e2da665b26ab837bccd036e267cf1b5f521073e76352ec4af22ded4c"
28
32
  }
@@ -100,7 +100,21 @@ export function validatePublicPositionBounds(
100
100
  return null;
101
101
  }
102
102
 
103
- /** Split source into logical lines without CRLF line-ending bytes. */
103
+ /**
104
+ * Split source into Tree-sitter rows, dropping the `\r` of CRLF endings.
105
+ * Tree-sitter rows break only on `\n`, so a lone `\r` is not a line break here.
106
+ * LSP treats a lone `\r` as a line break, so structural lines after one differ from LSP lines.
107
+ */
104
108
  export function splitSourceLines(source: string): string[] {
105
- return source.replace(/\r\n?/g, "\n").split("\n");
109
+ if (lastSplit?.source === source) return lastSplit.lines;
110
+ const lines = source.split(/\r?\n/);
111
+ lastSplit = { source, lines };
112
+ return lines;
106
113
  }
114
+
115
+ /**
116
+ * Single-entry cache: range conversion calls this once per node on the same
117
+ * source, so re-splitting each time made extraction quadratic in file size.
118
+ * Callers must not mutate the returned array.
119
+ */
120
+ let lastSplit: { source: string; lines: string[] } | undefined;
@@ -331,8 +331,9 @@ export class StructuralWorkerClient {
331
331
  try {
332
332
  throwIfCodeRequestInterrupted(active.control);
333
333
  } catch (error) {
334
+ // Keep the chunk handshake alive so the Worker can send its terminal message
335
+ // instead of waiting for the hard stop.
334
336
  this.#interrupt(active, error);
335
- return;
336
337
  }
337
338
  active.chunks.push(Uint8Array.from(message.payload));
338
339
  active.nextSequence += 1;
@@ -433,7 +434,7 @@ export class StructuralWorkerClient {
433
434
  return;
434
435
  }
435
436
  const worker = this.#worker;
436
- if (this.#active !== request || !worker) return;
437
+ if (this.#active !== request || !worker || request.hardStopTimer) return;
437
438
  Atomics.store(request.cancellationFlag, 0, 1);
438
439
  if (
439
440
  !this.#send(worker, {
@@ -4,7 +4,9 @@ import type { GrammarId, SourceRange } from "./types.ts";
4
4
 
5
5
  /** Return whether a parsed tree contains an explicit or recovered syntax error. */
6
6
  export function hasSyntaxErrors(root: SyntaxNodeLike): boolean {
7
+ // web-tree-sitter's hasError already covers ERROR and missing descendants.
7
8
  if (root.hasError === true) return true;
9
+ if (root.hasError === false) return false;
8
10
  if (root.type === "ERROR" || root.isMissing === true) return true;
9
11
  return (root.children ?? []).some(hasSyntaxErrors);
10
12
  }