@mrclrchtr/supi-tree-sitter 3.2.0 → 4.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 (55) hide show
  1. package/README.md +4 -0
  2. package/node_modules/@mrclrchtr/supi-code-runtime/README.md +8 -0
  3. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +2 -4
  4. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +0 -4
  5. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +3 -2
  6. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +0 -4
  7. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/llm.ts +0 -10
  8. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +19 -15
  9. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +2 -2
  10. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +10 -1
  11. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +19 -29
  12. package/node_modules/@mrclrchtr/supi-code-runtime/src/index.ts +7 -1
  13. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +42 -0
  14. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +15 -10
  15. package/node_modules/@mrclrchtr/supi-core/package.json +2 -4
  16. package/node_modules/@mrclrchtr/supi-core/src/api.ts +0 -4
  17. package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +3 -2
  18. package/node_modules/@mrclrchtr/supi-core/src/index.ts +0 -4
  19. package/node_modules/@mrclrchtr/supi-core/src/llm.ts +0 -10
  20. package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +19 -15
  21. package/package.json +4 -21
  22. package/resources/grammars/bash/tree-sitter-bash.wasm +0 -0
  23. package/resources/grammars/bash/tree-sitter-bash.wasm.json +2 -2
  24. package/resources/grammars/c/tree-sitter-c.wasm +0 -0
  25. package/resources/grammars/c/tree-sitter-c.wasm.json +2 -2
  26. package/resources/grammars/go/tree-sitter-go.wasm +0 -0
  27. package/resources/grammars/go/tree-sitter-go.wasm.json +2 -2
  28. package/resources/grammars/javascript/tree-sitter-javascript.wasm +0 -0
  29. package/resources/grammars/javascript/tree-sitter-javascript.wasm.json +2 -2
  30. package/resources/grammars/kotlin/tree-sitter-kotlin.wasm +0 -0
  31. package/resources/grammars/kotlin/tree-sitter-kotlin.wasm.json +2 -2
  32. package/resources/grammars/python/tree-sitter-python.wasm +0 -0
  33. package/resources/grammars/python/tree-sitter-python.wasm.json +2 -2
  34. package/resources/grammars/r/tree-sitter-r.wasm +0 -0
  35. package/resources/grammars/r/tree-sitter-r.wasm.json +2 -2
  36. package/resources/grammars/rust/tree-sitter-rust.wasm.json +1 -1
  37. package/resources/grammars/sql/tree-sitter-sql.wasm +0 -0
  38. package/resources/grammars/sql/tree-sitter-sql.wasm.json +3 -3
  39. package/scripts/generate-kotlin-wasm.mjs +6 -0
  40. package/scripts/generate-sql-wasm.mjs +18 -4
  41. package/scripts/vendor-wasm.mjs +17 -1
  42. package/src/api.ts +2 -0
  43. package/src/coordinates.ts +20 -41
  44. package/src/index.ts +2 -0
  45. package/src/language.ts +7 -0
  46. package/src/operation-support.ts +40 -0
  47. package/src/session/session.ts +9 -7
  48. package/src/tool/call-sites.ts +6 -1
  49. package/src/tool/callees.ts +76 -37
  50. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +0 -31
  51. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/substrate-types.ts +0 -11
  52. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/types.ts +0 -2
  53. package/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +0 -31
  54. package/node_modules/@mrclrchtr/supi-core/src/substrate-types.ts +0 -11
  55. package/node_modules/@mrclrchtr/supi-core/src/types.ts +0 -2
@@ -188,7 +188,7 @@ export async function lookupCalleesAt(
188
188
 
189
189
  try {
190
190
  const scopes = ENCLOSING_SCOPE_TYPES[grammarId];
191
- const tsPoint = tsPosition(line, character);
191
+ const tsPoint = { row: line - 1, column: character - 1 };
192
192
  const node = tree.rootNode.descendantForPosition(tsPoint);
193
193
 
194
194
  if (!node) {
@@ -222,13 +222,7 @@ export async function lookupCalleesAt(
222
222
  };
223
223
  }
224
224
 
225
- const callees = filterCalleeCaptures(
226
- queryResult.data,
227
- enclosingNode,
228
- scopes,
229
- tsPoint.row,
230
- depth,
231
- );
225
+ const callees = filterCalleeCaptures(queryResult.data, enclosingNode, scopes, tsPoint, depth);
232
226
 
233
227
  const enclosingRange = nodeToSourceRange(enclosingNode);
234
228
  const scopeName = extractScopeName(enclosingNode.type, enclosingNode.text);
@@ -250,47 +244,74 @@ export async function lookupCalleesAt(
250
244
  }
251
245
 
252
246
  /**
253
- * Recursively collect line ranges of inner function/method/callback scopes that
254
- * do not contain the anchor row. Captures from these ranges are excluded so
247
+ * Recursively collect inner function/method/callback scopes that do NOT
248
+ * contain the anchor point. Captures from these ranges are excluded so
255
249
  * nested calls are not attributed to the parent scope.
250
+ *
251
+ * Containment compares both row and column to handle same-line nested
252
+ * functions correctly.
256
253
  */
257
254
  function collectInnerScopes(
258
255
  node: {
259
256
  type: string;
260
257
  children: unknown[];
261
- startPosition: { row: number };
262
- endPosition: { row: number };
258
+ startPosition: { row: number; column: number };
259
+ endPosition: { row: number; column: number };
263
260
  } | null,
264
261
  scopeTypes: ReadonlySet<string>,
265
- anchorRow: number,
266
- ranges: Array<{ startRow: number; endRow: number }>,
262
+ anchor: { row: number; column: number },
263
+ ranges: Array<{
264
+ startRow: number;
265
+ startColumn: number;
266
+ endRow: number;
267
+ endColumn: number;
268
+ }>,
267
269
  ): void {
268
270
  if (!node) return;
269
271
  // biome-ignore lint/complexity/noForEach: safe iteration over node children
270
272
  (node.children ?? []).forEach((child) => {
271
273
  const childNode = child as {
272
274
  type: string;
273
- startPosition: { row: number };
274
- endPosition: { row: number };
275
+ startPosition: { row: number; column: number };
276
+ endPosition: { row: number; column: number };
275
277
  children: unknown[];
276
278
  };
277
279
  if (scopeTypes.has(childNode.type)) {
278
- // Exclude this inner scope if it does NOT contain the anchor
279
- if (!(childNode.startPosition.row <= anchorRow && childNode.endPosition.row >= anchorRow)) {
280
+ // Exclude this inner scope if it does NOT contain the anchor point.
281
+ const contains = containsPoint(childNode, anchor);
282
+ if (!contains) {
280
283
  ranges.push({
281
- startRow: childNode.startPosition.row + 1,
282
- endRow: childNode.endPosition.row + 1,
284
+ startRow: childNode.startPosition.row,
285
+ startColumn: childNode.startPosition.column,
286
+ endRow: childNode.endPosition.row,
287
+ endColumn: childNode.endPosition.column,
283
288
  });
284
289
  }
285
290
  // Still recurse into it for deeper nesting
286
- collectInnerScopes(childNode, scopeTypes, anchorRow, ranges);
291
+ collectInnerScopes(childNode, scopeTypes, anchor, ranges);
287
292
  } else {
288
293
  // Recurse into non-scope children to find deeper scopes
289
- collectInnerScopes(childNode, scopeTypes, anchorRow, ranges);
294
+ collectInnerScopes(childNode, scopeTypes, anchor, ranges);
290
295
  }
291
296
  });
292
297
  }
293
298
 
299
+ function containsPoint(
300
+ node: {
301
+ startPosition: { row: number; column: number };
302
+ endPosition: { row: number; column: number };
303
+ },
304
+ point: { row: number; column: number },
305
+ ): boolean {
306
+ const afterStart =
307
+ point.row > node.startPosition.row ||
308
+ (point.row === node.startPosition.row && point.column >= node.startPosition.column);
309
+ const beforeEnd =
310
+ point.row < node.endPosition.row ||
311
+ (point.row === node.endPosition.row && point.column <= node.endPosition.column);
312
+ return afterStart && beforeEnd;
313
+ }
314
+
294
315
  /**
295
316
  * Filter query captures to only those within the enclosing scope.
296
317
  * In `direct` depth, excludes captures that fall within inner nested
@@ -298,35 +319,57 @@ function collectInnerScopes(
298
319
  * enclosing scope are included regardless of nesting.
299
320
  */
300
321
  // biome-ignore lint/complexity/useMaxParams: filtering needs captures + node context + depth
322
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: filtering combines scope containment, column-aware inner-scope exclusion, and dedup in one cohesive pass
301
323
  function filterCalleeCaptures(
302
324
  captures: Array<{ range: SourceRange; text: string }>,
303
325
  // biome-ignore lint/suspicious/noExplicitAny: tree-sitter SyntaxNode is complex
304
326
  enclosingNode: any,
305
327
  scopeTypes: ReadonlySet<string>,
306
- anchorRow: number,
328
+ anchor: { row: number; column: number },
307
329
  depth: "direct" | "deep" = "direct",
308
330
  ): Array<{ name: string; range: SourceRange }> {
309
- const excludeRanges: Array<{ startRow: number; endRow: number }> = [];
331
+ const excludeRanges: Array<{
332
+ startRow: number;
333
+ startColumn: number;
334
+ endRow: number;
335
+ endColumn: number;
336
+ }> = [];
310
337
  if (depth === "direct") {
311
- collectInnerScopes(enclosingNode, scopeTypes, anchorRow, excludeRanges);
338
+ collectInnerScopes(enclosingNode, scopeTypes, anchor, excludeRanges);
312
339
  }
313
340
 
314
341
  const seen = new Set<string>();
315
342
  const callees: Array<{ name: string; range: SourceRange }> = [];
316
343
 
317
- const enclosingStartRow = enclosingNode.startPosition.row + 1;
318
- const enclosingEndRow = enclosingNode.endPosition.row + 1;
344
+ const enclosingStartRow = enclosingNode.startPosition.row;
345
+ const enclosingEndRow = enclosingNode.endPosition.row;
346
+ const enclosingStartColumn = enclosingNode.startPosition.column;
347
+ const enclosingEndColumn = enclosingNode.endPosition.column;
319
348
 
320
349
  for (const capture of captures) {
321
- // Only include captures within the enclosing scope
322
- if (capture.range.startLine < enclosingStartRow || capture.range.endLine > enclosingEndRow) {
350
+ // Only include captures within the enclosing scope, using columns
351
+ // for same-line containment.
352
+ const capStartLine = capture.range.startLine - 1;
353
+ const capEndLine = capture.range.endLine - 1;
354
+ const capStartChar = capture.range.startCharacter - 1;
355
+ const capEndChar = capture.range.endCharacter - 1;
356
+ if (capStartLine < enclosingStartRow || capEndLine > enclosingEndRow) {
357
+ continue;
358
+ }
359
+ if (capStartLine === enclosingStartRow && capStartChar < enclosingStartColumn) {
360
+ continue;
361
+ }
362
+ if (capEndLine === enclosingEndRow && capEndChar > enclosingEndColumn) {
323
363
  continue;
324
364
  }
325
365
 
326
- // In direct depth, exclude captures that fall within inner nested function scopes
366
+ // In direct depth, exclude captures within inner nested function scopes
327
367
  if (depth === "direct") {
328
368
  const isInInner = excludeRanges.some(
329
- (exc) => capture.range.startLine >= exc.startRow && capture.range.endLine <= exc.endRow,
369
+ (exc) =>
370
+ (capStartLine > exc.startRow ||
371
+ (capStartLine === exc.startRow && capStartChar >= exc.startColumn)) &&
372
+ (capEndLine < exc.endRow || (capEndLine === exc.endRow && capEndChar <= exc.endColumn)),
330
373
  );
331
374
  if (isInInner) continue;
332
375
  }
@@ -343,7 +386,8 @@ function filterCalleeCaptures(
343
386
 
344
387
  // ── Internal helpers ──────────────────────────────────────────────────
345
388
 
346
- /** Convert a tree-sitter node to a SourceRange. */
389
+ /** Convert a tree-sitter node to a SourceRange using the source text for
390
+ * UTF-16 column conversion. */
347
391
  function nodeToSourceRange(node: {
348
392
  startPosition: { row: number; column: number };
349
393
  endPosition: { row: number; column: number };
@@ -355,8 +399,3 @@ function nodeToSourceRange(node: {
355
399
  endCharacter: node.endPosition.column + 1,
356
400
  };
357
401
  }
358
-
359
- /** Convert 1-based position to tree-sitter 0-based point. */
360
- function tsPosition(line: number, character: number): { row: number; column: number } {
361
- return { row: line - 1, column: character - 1 };
362
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Abort controller/signal utility helpers.
3
- *
4
- * @module
5
- */
6
-
7
- /**
8
- * Combine a caller-provided abort controller with a generation timeout signal.
9
- *
10
- * Returns the combined signal and a cleanup function that removes both
11
- * event listeners. Callers must invoke cleanup in a `finally` block
12
- * to avoid listener leaks.
13
- */
14
- export function combineAbortSignals(
15
- abort: AbortController,
16
- timeoutMs: number,
17
- ): { signal: AbortSignal; cleanup: () => void } {
18
- const timeoutSignal = AbortSignal.timeout(timeoutMs);
19
- const combinedController = new AbortController();
20
- const onAbort = () => combinedController.abort();
21
- abort.signal.addEventListener("abort", onAbort, { once: true });
22
- timeoutSignal.addEventListener("abort", onAbort, { once: true });
23
-
24
- return {
25
- signal: combinedController.signal,
26
- cleanup: () => {
27
- abort.signal.removeEventListener("abort", onAbort);
28
- timeoutSignal.removeEventListener("abort", onAbort);
29
- },
30
- };
31
- }
@@ -1,11 +0,0 @@
1
- /** 0-based position used by LSP and code-intelligence internally. */
2
- export interface CodePosition {
3
- line: number;
4
- character: number;
5
- }
6
-
7
- /** Normalized location — flat replacement for LSP's nested Location/range shape. */
8
- export interface CodeLocation {
9
- uri: string;
10
- range: { start: CodePosition; end: CodePosition };
11
- }
@@ -1,2 +0,0 @@
1
- // supi-core types domain — shared substrate types (zero dependencies, pure types).
2
- export type { CodeLocation, CodePosition } from "./substrate-types.ts";
@@ -1,31 +0,0 @@
1
- /**
2
- * Abort controller/signal utility helpers.
3
- *
4
- * @module
5
- */
6
-
7
- /**
8
- * Combine a caller-provided abort controller with a generation timeout signal.
9
- *
10
- * Returns the combined signal and a cleanup function that removes both
11
- * event listeners. Callers must invoke cleanup in a `finally` block
12
- * to avoid listener leaks.
13
- */
14
- export function combineAbortSignals(
15
- abort: AbortController,
16
- timeoutMs: number,
17
- ): { signal: AbortSignal; cleanup: () => void } {
18
- const timeoutSignal = AbortSignal.timeout(timeoutMs);
19
- const combinedController = new AbortController();
20
- const onAbort = () => combinedController.abort();
21
- abort.signal.addEventListener("abort", onAbort, { once: true });
22
- timeoutSignal.addEventListener("abort", onAbort, { once: true });
23
-
24
- return {
25
- signal: combinedController.signal,
26
- cleanup: () => {
27
- abort.signal.removeEventListener("abort", onAbort);
28
- timeoutSignal.removeEventListener("abort", onAbort);
29
- },
30
- };
31
- }
@@ -1,11 +0,0 @@
1
- /** 0-based position used by LSP and code-intelligence internally. */
2
- export interface CodePosition {
3
- line: number;
4
- character: number;
5
- }
6
-
7
- /** Normalized location — flat replacement for LSP's nested Location/range shape. */
8
- export interface CodeLocation {
9
- uri: string;
10
- range: { start: CodePosition; end: CodePosition };
11
- }
@@ -1,2 +0,0 @@
1
- // supi-core types domain — shared substrate types (zero dependencies, pure types).
2
- export type { CodeLocation, CodePosition } from "./substrate-types.ts";