@mrclrchtr/supi-code-intelligence 10.0.0 → 11.0.1

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 (138) hide show
  1. package/README.md +77 -21
  2. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/LICENSE +21 -0
  3. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/README.md +743 -0
  4. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/index.js +17 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/constants.js +184 -0
  6. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/parse.js +1425 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/picomatch.js +361 -0
  8. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/scan.js +403 -0
  9. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/utils.js +72 -0
  10. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/package.json +83 -0
  11. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/posix.js +3 -0
  12. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +4 -1
  13. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +11 -0
  14. package/node_modules/@mrclrchtr/supi-code-runtime/src/file-associations.ts +190 -0
  15. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +22 -0
  16. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  17. package/node_modules/@mrclrchtr/supi-lsp/README.md +88 -2
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/LICENSE +21 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/README.md +743 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/index.js +17 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/constants.js +184 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/parse.js +1425 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/picomatch.js +361 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/scan.js +403 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/utils.js +72 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/package.json +83 -0
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/posix.js +3 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +4 -1
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +11 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/file-associations.ts +190 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +22 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  33. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  34. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +1 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +3 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +6 -4
  37. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-request-enrollment.ts +66 -22
  38. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-barrier.ts +37 -5
  39. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +136 -43
  40. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +261 -22
  41. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +13 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-discovery.ts +151 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-normalizer.ts +97 -129
  44. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-protocol.ts +132 -0
  45. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +8 -1
  46. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +7 -20
  47. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +172 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +14 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/src/utils.ts +12 -11
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +63 -17
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/LICENSE +21 -0
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/README.md +743 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/index.js +17 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/constants.js +184 -0
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/parse.js +1425 -0
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/picomatch.js +361 -0
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/scan.js +403 -0
  58. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/lib/utils.js +72 -0
  59. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/package.json +83 -0
  60. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/picomatch/posix.js +3 -0
  61. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +4 -1
  62. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +11 -0
  63. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/file-associations.ts +190 -0
  64. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +22 -0
  65. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  66. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  67. package/node_modules/@mrclrchtr/supi-tree-sitter/src/language.ts +16 -10
  68. package/node_modules/@mrclrchtr/supi-tree-sitter/src/operation-support.ts +13 -6
  69. package/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +19 -1
  70. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime-controller.ts +18 -4
  71. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +10 -3
  72. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +17 -2
  73. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-process.ts +22 -5
  74. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-protocol.ts +36 -1
  75. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +73 -0
  76. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-node.ts +4 -0
  77. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +15 -9
  78. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +24 -15
  79. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +8 -1
  80. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/imports.ts +233 -7
  81. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/node-at.ts +7 -3
  82. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/outline-expansion.ts +78 -0
  83. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/outline-jvm.ts +25 -4
  84. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/outline-nested.ts +390 -0
  85. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/outline.ts +49 -28
  86. package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +16 -0
  87. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/process-host.mjs +61 -24
  88. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +44 -10
  89. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/service.ts +13 -9
  90. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/worker-main.ts +15 -2
  91. package/node_modules/ignore/README.md +61 -6
  92. package/node_modules/ignore/index.d.ts +55 -20
  93. package/node_modules/ignore/index.js +93 -67
  94. package/node_modules/ignore/legacy.js +109 -85
  95. package/node_modules/ignore/package.json +1 -1
  96. package/package.json +5 -5
  97. package/src/analysis/refactor/apply.ts +35 -14
  98. package/src/analysis/relations/callees.ts +9 -2
  99. package/src/analysis/relations/implementations.ts +7 -2
  100. package/src/analysis/search/pattern-analysis.ts +90 -12
  101. package/src/analysis/search/pattern.ts +1 -0
  102. package/src/analysis/target/anchored-structural.ts +1 -0
  103. package/src/analysis/target/discovery.ts +29 -0
  104. package/src/analysis/target/file.ts +19 -9
  105. package/src/analysis/target/types.ts +5 -0
  106. package/src/config.ts +46 -7
  107. package/src/session/graph/collect.ts +2 -2
  108. package/src/session/graph-types.ts +6 -0
  109. package/src/session/inspect/collect.ts +35 -20
  110. package/src/session/inspect-types.ts +9 -2
  111. package/src/session/orientation/collect.ts +90 -18
  112. package/src/session/orientation/context-sections.ts +22 -1
  113. package/src/session/orientation/gather.ts +46 -6
  114. package/src/session/orientation-types.ts +7 -1
  115. package/src/session/refactor-plans.ts +17 -0
  116. package/src/session/refactor-workflow.ts +13 -6
  117. package/src/session/target-store.ts +5 -0
  118. package/src/session/target-workflow.ts +3 -0
  119. package/src/substrate/workspace-provider-host.ts +22 -2
  120. package/src/tool/code_find/markdown.ts +17 -4
  121. package/src/tool/code_find/result.ts +17 -3
  122. package/src/tool/code_graph/details.ts +2 -0
  123. package/src/tool/code_graph/display.ts +1 -0
  124. package/src/tool/code_graph/format.ts +1 -0
  125. package/src/tool/code_graph/result.ts +32 -6
  126. package/src/tool/code_inspect/markdown.ts +15 -1
  127. package/src/tool/code_inspect/result.ts +11 -0
  128. package/src/tool/code_orientation/result.ts +4 -2
  129. package/src/tool/code_resolve/markdown.ts +34 -14
  130. package/src/tool/code_resolve/result.ts +7 -3
  131. package/src/tool/result/types.ts +20 -2
  132. package/src/ui/tui/display.ts +2 -1
  133. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/LICENSE-MIT +0 -21
  134. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/README.md +0 -501
  135. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/index.d.ts +0 -81
  136. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/index.js +0 -1566
  137. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/legacy.js +0 -1346
  138. package/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/package.json +0 -93
@@ -11,44 +11,63 @@ if (
11
11
  throw new Error("Structural Worker process received invalid startup data");
12
12
  }
13
13
 
14
- const worker = new Worker(new URL("./bootstrap.mjs", import.meta.url), {
15
- execArgv: [],
16
- workerData: { cwd, generation },
17
- });
18
14
  const cancellationFlags = new Map();
15
+ let worker = null;
19
16
  let closing = false;
20
17
  let workerExited = false;
21
18
 
22
- worker.on("message", (message) => {
23
- if (message.kind === "terminal") cancellationFlags.delete(message.requestId);
24
- send({ channel: "supi-tree-sitter-worker", message });
25
- });
26
- worker.on("error", (error) => {
27
- send(
28
- {
29
- channel: "supi-tree-sitter-worker",
30
- message: { kind: "worker-error", message: error.message },
31
- },
32
- () => stopWorker(1),
33
- );
34
- });
35
- worker.on("exit", (code) => {
36
- workerExited = true;
37
- cancellationFlags.clear();
38
- process.exitCode = code === 0 ? 1 : code;
39
- disconnect();
40
- });
41
-
42
19
  process.on("message", (value) => {
43
20
  if (!isParentChannel(value)) {
44
21
  stopWorker(1);
45
22
  return;
46
23
  }
24
+ if (!worker) {
25
+ if (!isInitialization(value.message)) {
26
+ stopWorker(1);
27
+ return;
28
+ }
29
+ startWorker(value.message);
30
+ return;
31
+ }
32
+ if (value.message.kind === "initialize") {
33
+ stopWorker(1);
34
+ return;
35
+ }
47
36
  forwardToWorker(value.message);
48
37
  });
49
38
  process.on("disconnect", () => stopWorker());
50
39
  if (!process.connected) stopWorker();
51
40
 
41
+ function startWorker(initialization) {
42
+ worker = new Worker(new URL("./bootstrap.mjs", import.meta.url), {
43
+ execArgv: [],
44
+ workerData: {
45
+ cwd,
46
+ generation,
47
+ fileAssociations: initialization.fileAssociations,
48
+ },
49
+ });
50
+ worker.on("message", (message) => {
51
+ if (message.kind === "terminal") cancellationFlags.delete(message.requestId);
52
+ send({ channel: "supi-tree-sitter-worker", message });
53
+ });
54
+ worker.on("error", (error) => {
55
+ send(
56
+ {
57
+ channel: "supi-tree-sitter-worker",
58
+ message: { kind: "worker-error", message: error.message },
59
+ },
60
+ () => stopWorker(1),
61
+ );
62
+ });
63
+ worker.on("exit", (code) => {
64
+ workerExited = true;
65
+ cancellationFlags.clear();
66
+ process.exitCode = code === 0 ? 1 : code;
67
+ disconnect();
68
+ });
69
+ }
70
+
52
71
  function forwardToWorker(message) {
53
72
  if (!message || typeof message !== "object") {
54
73
  throw new Error("Structural Worker process received an invalid message");
@@ -70,6 +89,20 @@ function forwardToWorker(message) {
70
89
  worker.postMessage(message);
71
90
  }
72
91
 
92
+ function isInitialization(value) {
93
+ return (
94
+ value !== null &&
95
+ typeof value === "object" &&
96
+ !Array.isArray(value) &&
97
+ Object.keys(value).length === 5 &&
98
+ value.kind === "initialize" &&
99
+ value.version === 1 &&
100
+ value.generation === generation &&
101
+ value.cwd === cwd &&
102
+ Array.isArray(value.fileAssociations)
103
+ );
104
+ }
105
+
73
106
  function isParentChannel(value) {
74
107
  return (
75
108
  value !== null &&
@@ -105,5 +138,9 @@ function stopWorker(exitCode) {
105
138
  closing = true;
106
139
  if (exitCode !== undefined) process.exitCode = exitCode;
107
140
  cancellationFlags.clear();
141
+ if (!worker) {
142
+ disconnect();
143
+ return;
144
+ }
108
145
  void worker.terminate().finally(disconnect);
109
146
  }
@@ -2,6 +2,7 @@
2
2
  // Tree-sitter runtime — parser management, parse, and query services.
3
3
 
4
4
  import * as path from "node:path";
5
+ import type { CFamilyFileAssociationResolver } from "@mrclrchtr/supi-code-runtime/api";
5
6
  import { resolveToolPath } from "@mrclrchtr/supi-core/path";
6
7
  import type { Language, Parser, Tree } from "web-tree-sitter";
7
8
  import { detectGrammar, resolveGrammarWasmPath } from "../language.ts";
@@ -12,6 +13,11 @@ import {
12
13
  type StructuralTimingEvent,
13
14
  startStructuralTiming,
14
15
  } from "../session/structural-timing.ts";
16
+ import {
17
+ collectSyntaxErrorRanges,
18
+ hasSyntaxErrors,
19
+ withSyntaxCompleteness,
20
+ } from "../syntax-errors.ts";
15
21
  import type { GrammarId, QueryCapture, TreeSitterResult } from "../types.ts";
16
22
  import {
17
23
  ParsedFileReadError,
@@ -39,6 +45,7 @@ interface ParserEntry {
39
45
  const QUERY_PARSED_FILE = Symbol("query-parsed-file");
40
46
 
41
47
  interface ParsedQueryInput {
48
+ readonly file: string;
42
49
  readonly grammarId: GrammarId;
43
50
  readonly tree: Tree;
44
51
  readonly source: string;
@@ -66,8 +73,14 @@ export class TreeSitterRuntime {
66
73
  constructor(
67
74
  private cwd: string,
68
75
  private onTiming?: (event: StructuralTimingEvent) => void,
76
+ private readonly fileAssociations?: CFamilyFileAssociationResolver,
69
77
  ) {}
70
78
 
79
+ /** Resolve one file's grammar under this runtime's immutable association snapshot. */
80
+ getGrammarForFile(filePath: string): GrammarId | undefined {
81
+ return detectGrammar(filePath, this.fileAssociations);
82
+ }
83
+
71
84
  /** Ensure web-tree-sitter Parser is initialized. */
72
85
  private async ensureParserInit(): Promise<typeof import("web-tree-sitter")> {
73
86
  this.assertActive();
@@ -152,15 +165,21 @@ export class TreeSitterRuntime {
152
165
  filePath: string,
153
166
  control?: StructuralRequestControl,
154
167
  ): Promise<
155
- TreeSitterResult<{
156
- tree: Tree;
157
- source: string;
158
- resolvedPath: string;
159
- grammarId: GrammarId;
160
- }>
168
+ | {
169
+ kind: "success";
170
+ data: {
171
+ tree: Tree;
172
+ source: string;
173
+ resolvedPath: string;
174
+ grammarId: GrammarId;
175
+ hasSyntaxErrors: boolean;
176
+ errorRanges: ReturnType<typeof collectSyntaxErrorRanges>;
177
+ };
178
+ }
179
+ | Exclude<TreeSitterResult<never>, { kind: "success" | "partial" }>
161
180
  > {
162
181
  const resolvedPath = resolveToolPath(this.cwd, filePath);
163
- const grammarId = detectGrammar(filePath);
182
+ const grammarId = detectGrammar(filePath, this.fileAssociations);
164
183
  if (!grammarId) {
165
184
  return {
166
185
  kind: "unsupported-language",
@@ -230,6 +249,8 @@ export class TreeSitterRuntime {
230
249
  source: parsed.source,
231
250
  resolvedPath: parsed.resolvedPath,
232
251
  grammarId: parsed.grammarId,
252
+ hasSyntaxErrors: hasSyntaxErrors(parsed.tree.rootNode),
253
+ errorRanges: collectSyntaxErrorRanges(parsed.tree.rootNode, parsed.source),
233
254
  },
234
255
  };
235
256
  } catch (err: unknown) {
@@ -281,7 +302,14 @@ export class TreeSitterRuntime {
281
302
 
282
303
  const { grammarId, tree, source } = parseResult.data;
283
304
  try {
284
- return await this[QUERY_PARSED_FILE]({ grammarId, tree, source, queryString, control });
305
+ return await this[QUERY_PARSED_FILE]({
306
+ file: filePath,
307
+ grammarId,
308
+ tree,
309
+ source,
310
+ queryString,
311
+ control,
312
+ });
285
313
  } finally {
286
314
  tree.delete();
287
315
  }
@@ -289,7 +317,7 @@ export class TreeSitterRuntime {
289
317
 
290
318
  /** Execute a query against one caller-owned parsed tree without parsing again. */
291
319
  async [QUERY_PARSED_FILE](input: ParsedQueryInput): Promise<TreeSitterResult<QueryCapture[]>> {
292
- const { grammarId, tree, source, queryString, control } = input;
320
+ const { file, grammarId, tree, source, queryString, control } = input;
293
321
  const validation = validateQueryString(queryString);
294
322
  if (validation) return validation;
295
323
 
@@ -344,7 +372,13 @@ export class TreeSitterRuntime {
344
372
  cache: execution.cache,
345
373
  finalPhase: "query-execution",
346
374
  });
347
- return { kind: "success", data: execution.data };
375
+ return withSyntaxCompleteness({
376
+ data: execution.data,
377
+ file,
378
+ root: tree.rootNode,
379
+ source,
380
+ grammarId,
381
+ });
348
382
  } catch (err: unknown) {
349
383
  if (isStructuralRequestInterruption(err, control)) {
350
384
  finishStructuralTiming(timer, {
@@ -1,6 +1,6 @@
1
- import { detectGrammar } from "../language.ts";
2
1
  import { supportsGrammarOperation } from "../operation-support.ts";
3
2
  import type { StructuralWorkerOperation } from "../session/structural-worker-protocol.ts";
3
+ import { withSyntaxCompleteness } from "../syntax-errors.ts";
4
4
  import { extractCallSites } from "../tool/call-sites.ts";
5
5
  import { lookupCalleesAt } from "../tool/callees.ts";
6
6
  import { extractExports } from "../tool/exports.ts";
@@ -68,16 +68,19 @@ export class StructuralWorkerService {
68
68
  file: string,
69
69
  control: StructuralRequestControl,
70
70
  ): Promise<TreeSitterResult<unknown>> {
71
- const unsupported = unsupportedOperation(file, "outline");
71
+ const unsupported = unsupportedOperation(this.runtime, file, "outline");
72
72
  if (unsupported) return unsupported;
73
73
  const result = await this.runtime.parseFile(file, control);
74
74
  if (result.kind !== "success") return result;
75
75
  try {
76
76
  throwIfStructuralRequestInterrupted(control);
77
- return {
78
- kind: "success",
79
- data: extractOutline(result.data.tree.rootNode, result.data.source),
80
- };
77
+ return withSyntaxCompleteness({
78
+ data: extractOutline(result.data.tree.rootNode, result.data.source, result.data.grammarId),
79
+ file,
80
+ root: result.data.tree.rootNode,
81
+ source: result.data.source,
82
+ grammarId: result.data.grammarId,
83
+ });
81
84
  } finally {
82
85
  result.data.tree.delete();
83
86
  }
@@ -87,7 +90,7 @@ export class StructuralWorkerService {
87
90
  file: string,
88
91
  control: StructuralRequestControl,
89
92
  ): Promise<TreeSitterResult<unknown>> {
90
- const unsupported = unsupportedOperation(file, "imports");
93
+ const unsupported = unsupportedOperation(this.runtime, file, "imports");
91
94
  return unsupported ?? extractImports(this.runtime, file, control);
92
95
  }
93
96
 
@@ -95,16 +98,17 @@ export class StructuralWorkerService {
95
98
  file: string,
96
99
  control: StructuralRequestControl,
97
100
  ): Promise<TreeSitterResult<unknown>> {
98
- const unsupported = unsupportedOperation(file, "exports");
101
+ const unsupported = unsupportedOperation(this.runtime, file, "exports");
99
102
  return unsupported ?? extractExports(this.runtime, file, control);
100
103
  }
101
104
  }
102
105
 
103
106
  function unsupportedOperation(
107
+ runtime: TreeSitterRuntime,
104
108
  file: string,
105
109
  operation: "outline" | "imports" | "exports",
106
110
  ): TreeSitterResult<never> | null {
107
- const grammarId = detectGrammar(file);
111
+ const grammarId = runtime.getGrammarForFile(file);
108
112
  if (!grammarId || supportsGrammarOperation(grammarId, operation)) return null;
109
113
  return {
110
114
  kind: "unsupported-language",
@@ -1,5 +1,9 @@
1
1
  import type { MessagePort } from "node:worker_threads";
2
- import { isCodeRequestDeadlineError } from "@mrclrchtr/supi-code-runtime/api";
2
+ import {
3
+ type CFamilyFileAssociationRule,
4
+ createCFamilyFileAssociationResolver,
5
+ isCodeRequestDeadlineError,
6
+ } from "@mrclrchtr/supi-code-runtime/api";
3
7
  import type { StructuralTimingEvent } from "../session/structural-timing.ts";
4
8
  import { assertStructuralProtocolMessageSize } from "../session/structural-worker-message-size.ts";
5
9
  import {
@@ -18,6 +22,7 @@ import { StructuralWorkerService } from "./service.ts";
18
22
  interface WorkerBootstrapData {
19
23
  readonly cwd: string;
20
24
  readonly generation: number;
25
+ readonly fileAssociations?: readonly CFamilyFileAssociationRule[];
21
26
  }
22
27
 
23
28
  interface ActiveWorkerRequest {
@@ -36,7 +41,15 @@ export async function runStructuralWorker(
36
41
  parentPort: MessagePort,
37
42
  workerData: WorkerBootstrapData,
38
43
  ): Promise<void> {
39
- const runtime = new TreeSitterRuntime(workerData.cwd, (event) => forwardObservation(event));
44
+ const associationResolver = createCFamilyFileAssociationResolver(
45
+ workerData.cwd,
46
+ workerData.fileAssociations ?? [],
47
+ );
48
+ const runtime = new TreeSitterRuntime(
49
+ workerData.cwd,
50
+ (event) => forwardObservation(event),
51
+ associationResolver,
52
+ );
40
53
  const service = new StructuralWorkerService(runtime);
41
54
  let active: ActiveWorkerRequest | null = null;
42
55
 
@@ -173,6 +173,29 @@ ig.ignores(path.join('./abc')) // path.join('./abc') -> 'abc'
173
173
 
174
174
  In other words, each `Pathname` here should be a relative path to the directory of the gitignore rules.
175
175
 
176
+ A `.` or `..` component anywhere else in a `Pathname` is outside the
177
+ convention as well, though no error is thrown for it: the check reads how the
178
+ path starts, so that it costs nothing on a hot path. `path.relative()` never
179
+ produces such a component, and one that carries it is not matched the way
180
+ `git` matches it — `git` drops the component from the path first, `ignore`
181
+ matches the path as it was given.
182
+
183
+ ```js
184
+ // path.relative('/', '/a/./b') -> 'a/b'
185
+
186
+ // Right
187
+ ignore().add('a/b').ignores('a/b') // true
188
+
189
+ // Outside the convention: git matches 'a/b' here and so says true
190
+ ignore().add('a/b').ignores('a/./b') // false
191
+
192
+ // Outside the convention: git matches 'a' here and so says false
193
+ ignore().add('a/.').ignores('a/.') // true
194
+ ```
195
+
196
+ A rule that matches an ancestor still agrees, since the component makes no
197
+ difference to it: `add('a').ignores('a/./b')` is `true` either way.
198
+
176
199
  Suppose the dir structure is:
177
200
 
178
201
  ```
@@ -265,7 +288,8 @@ Returns `TestResult`
265
288
  // Since 5.0.0
266
289
  interface TestResult {
267
290
  ignored: boolean
268
- // true if the `pathname` is finally unignored by some negative pattern
291
+ // true if a negative pattern matched the `pathname` itself, and no parent
292
+ // directory of it is ignored -- see "When both are false" below
269
293
  unignored: boolean
270
294
  // The `IgnoreRule` which ignores the pathname
271
295
  rule?: IgnoreRule
@@ -283,8 +307,39 @@ interface IgnoreRule {
283
307
  ```
284
308
 
285
309
  - `{ignored: true, unignored: false}`: the `pathname` is ignored
286
- - `{ignored: false, unignored: true}`: the `pathname` is unignored
287
- - `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.
310
+ - `{ignored: false, unignored: true}`: a negative pattern matched the `pathname` itself
311
+ - `{ignored: false, unignored: false}`: no rule matched the `pathname` itself, and no parent directory of it is ignored
312
+
313
+ ### When both are `false`
314
+
315
+ `{ignored: false, unignored: false}` covers two different situations:
316
+
317
+ - no rule matched the `pathname`, nor any of its parent directories, or
318
+ - no rule matched the `pathname` itself, but one of its parent directories is unignored by a negative pattern: the `pathname` is unignored **indirectly**.
319
+
320
+ `unignored` stays `false` in the second case because only `ignored` passes down from a parent directory. A `pathname` whose parent directory is ignored is ignored as well — git never re-includes a file whose parent directory is excluded — but one whose parent directory is unignored is decided on its own, by the rules that match the `pathname` itself.
321
+
322
+ ```js
323
+ const ig2 = ignore().add([
324
+ 'foo*',
325
+ '!foobar'
326
+ ])
327
+
328
+ // The directory `foobar/` is unignored directly, by `!foobar`
329
+ ig2.test('foobar/') // {ignored: false, unignored: true}
330
+
331
+ // No rule matches `foobar/x.js` itself. It is not ignored only because its
332
+ // parent directory `foobar/` is not, so it is unignored indirectly
333
+ ig2.test('foobar/x.js') // {ignored: false, unignored: false}
334
+ ```
335
+
336
+ To tell the two situations apart, test the parent directories of the `pathname`, each with a trailing slash: the `pathname` is unignored indirectly if any of them is `unignored`.
337
+
338
+ ```js
339
+ ['foobar/'].some(dir => ig2.test(dir).unignored) // true
340
+ ```
341
+
342
+ `unignored` is meant for packages that implement their own caching mechanism upon `node-ignore`. To simply tell whether a `pathname` is ignored, use `.ignores()` or check `TestResult::ignored`.
288
343
 
289
344
  ## .checkIgnore(target: string): TestResult
290
345
 
@@ -294,7 +349,7 @@ Debugs gitignore / exclude files, which is equivalent to `git check-ignore -v`.
294
349
 
295
350
  - **target** `string` the target to test.
296
351
 
297
- Returns `TestResult`
352
+ Returns `TestResult`, the same shape `.test()` returns, so `{ignored: false, unignored: false}` carries the [same two meanings](#when-both-are-false) here.
298
353
 
299
354
  ```js
300
355
  ig.add({
@@ -305,10 +360,10 @@ ig.add({
305
360
  const {
306
361
  ignored,
307
362
  rule
308
- } = checkIgnore('foo/')
363
+ } = ig.checkIgnore('foo/')
309
364
 
310
365
  if (ignored) {
311
- console.log(`.gitignore:${result}:${rule.mark}:${rule.pattern} foo/`)
366
+ console.log(`.gitignore:${rule.mark}:${rule.pattern} foo/`)
312
367
  }
313
368
 
314
369
  // .gitignore:60:foo/* foo/
@@ -1,27 +1,61 @@
1
- type Pathname = string
2
-
3
- interface IgnoreRule {
4
- pattern: string
5
- mark?: string
6
- negative: boolean
7
- }
8
-
9
- interface TestResult {
10
- ignored: boolean
11
- unignored: boolean
12
- rule?: IgnoreRule
13
- }
14
-
15
- interface PatternParams {
16
- pattern: string
17
- mark?: string
18
- }
19
-
20
1
  /**
21
2
  * Creates new ignore manager.
22
3
  */
23
4
  declare function ignore(options?: ignore.Options): ignore.Ignore
24
5
  declare namespace ignore {
6
+ /**
7
+ * A path relative to the directory the rules belong to, as
8
+ * `path.relative()` returns it.
9
+ */
10
+ type Pathname = string
11
+
12
+ interface PatternParams {
13
+ pattern: string
14
+ /**
15
+ * Carried through to `IgnoreRule.mark`, for packages that build upon
16
+ * `ignore`.
17
+ */
18
+ mark?: string
19
+ }
20
+
21
+ interface IgnoreRule {
22
+ /**
23
+ * The original pattern.
24
+ */
25
+ pattern: string
26
+ /**
27
+ * Carried through from `PatternParams.mark`.
28
+ */
29
+ mark?: string
30
+ /**
31
+ * Whether the pattern is a negative one, such as `!foo`.
32
+ */
33
+ negative: boolean
34
+ }
35
+
36
+ interface TestResult {
37
+ /**
38
+ * Whether the pathname is ignored, by a rule or because a parent
39
+ * directory of it is.
40
+ */
41
+ ignored: boolean
42
+ /**
43
+ * True if a negative pattern matched the pathname itself, and no parent
44
+ * directory of it is ignored.
45
+ *
46
+ * Only `ignored` passes down from a parent directory, so a pathname that
47
+ * is not ignored only because a parent directory was unignored keeps
48
+ * this false, as does one no rule applies to at all. To tell those two
49
+ * apart, test the parent directories, each with a trailing slash.
50
+ */
51
+ unignored: boolean
52
+ /**
53
+ * The rule that ignores the pathname. Present exactly when `ignored` is
54
+ * true.
55
+ */
56
+ rule?: IgnoreRule
57
+ }
58
+
25
59
  interface Ignore {
26
60
  /**
27
61
  * Adds one or several rules to the current manager.
@@ -54,7 +88,8 @@ declare namespace ignore {
54
88
  ignores(pathname: Pathname): boolean
55
89
 
56
90
  /**
57
- * Returns whether pathname should be ignored or unignored
91
+ * Tests the pathname against the rules. `ignored` and `unignored` can
92
+ * both be false: see `TestResult.unignored` for the two cases.
58
93
  * @param {string} pathname a path to check
59
94
  * @returns TestResult
60
95
  */