@singapore-editor/tree-sitter 0.1.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 (40) hide show
  1. package/README.md +32 -0
  2. package/dist/assets/__vite-browser-external-CMrW8369.js +9 -0
  3. package/dist/assets/__vite-browser-external-CMrW8369.js.map +1 -0
  4. package/dist/assets/treeSitter.worker-D1ozCaGZ.js +5698 -0
  5. package/dist/assets/treeSitter.worker-D1ozCaGZ.js.map +1 -0
  6. package/dist/index.d.ts +34 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +143 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/session.d.ts +89 -0
  11. package/dist/session.d.ts.map +1 -0
  12. package/dist/session.js +437 -0
  13. package/dist/session.js.map +1 -0
  14. package/dist/structuralSelection.d.ts +37 -0
  15. package/dist/structuralSelection.d.ts.map +1 -0
  16. package/dist/structuralSelection.js +139 -0
  17. package/dist/structuralSelection.js.map +1 -0
  18. package/dist/treeSitter/markdown.d.ts +12 -0
  19. package/dist/treeSitter/markdown.d.ts.map +1 -0
  20. package/dist/treeSitter/registry.d.ts +56 -0
  21. package/dist/treeSitter/registry.d.ts.map +1 -0
  22. package/dist/treeSitter/registry.js +144 -0
  23. package/dist/treeSitter/registry.js.map +1 -0
  24. package/dist/treeSitter/source.d.ts +42 -0
  25. package/dist/treeSitter/source.d.ts.map +1 -0
  26. package/dist/treeSitter/source.js +175 -0
  27. package/dist/treeSitter/source.js.map +1 -0
  28. package/dist/treeSitter/sourceChunkRetention.d.ts +30 -0
  29. package/dist/treeSitter/sourceChunkRetention.d.ts.map +1 -0
  30. package/dist/treeSitter/sourceChunkRetention.js +76 -0
  31. package/dist/treeSitter/sourceChunkRetention.js.map +1 -0
  32. package/dist/treeSitter/treeSitter.worker.d.ts +64 -0
  33. package/dist/treeSitter/treeSitter.worker.d.ts.map +1 -0
  34. package/dist/treeSitter/types.d.ts +198 -0
  35. package/dist/treeSitter/types.d.ts.map +1 -0
  36. package/dist/treeSitter/workerClient.d.ts +133 -0
  37. package/dist/treeSitter/workerClient.d.ts.map +1 -0
  38. package/dist/treeSitter/workerClient.js +420 -0
  39. package/dist/treeSitter/workerClient.js.map +1 -0
  40. package/package.json +50 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","names":[],"sources":["../../src/treeSitter/source.ts"],"sourcesContent":["import type { PieceTableSnapshot } from '@singapore-editor/core/document'\nimport { debugPieceTable, type PieceBufferId } from '@singapore-editor/core/debug'\nimport { forEachBufferSpan } from '@singapore-editor/core/debug'\n\ntype TreeSitterSourcePieceSpan = {\n readonly chunkId: string\n readonly start: number\n readonly length: number\n}\n\ntype TreeSitterSourceChunkPayload = {\n readonly chunkId: string\n readonly text: string\n}\n\nexport type TreeSitterSourceDescriptor = {\n readonly length: number\n readonly pieces: readonly TreeSitterSourcePieceSpan[]\n readonly chunks: readonly TreeSitterSourceChunkPayload[]\n}\n\nexport type TreeSitterSourceDescriptorOptions = {\n readonly sentChunkLengths?: ReadonlyMap<string, number>\n}\n\ntype ResolvedTreeSitterSourceChunk = {\n readonly text: string\n readonly length: number\n}\n\nexport type TreeSitterSourceCache = Map<string, Map<string, ResolvedTreeSitterSourceChunk>>\n\ntype TreeSitterInputChunk = {\n readonly start: number\n readonly end: number\n readonly chunkStart: number\n readonly source: ResolvedTreeSitterSourceChunk\n}\n\nexport type TreeSitterPieceTableInput = {\n readonly length: number\n readonly chunks: readonly TreeSitterInputChunk[]\n lastChunkIndex?: number\n}\n\nconst SOURCE_CHUNK_SIZE = 16 * 1024\n// web-tree-sitter copies parser callback text into a fixed 10KB UTF-16 buffer.\nconst PARSER_READ_BATCH_CODE_UNITS = 4096\nconst sourceOwners = new WeakMap<object, number>()\nlet nextSourceOwner = 1\n\nexport const createTreeSitterSourceDescriptor = (\n snapshot: PieceTableSnapshot,\n options: TreeSitterSourceDescriptorOptions = {},\n): TreeSitterSourceDescriptor => {\n const pieces: TreeSitterSourcePieceSpan[] = []\n const chunks: TreeSitterSourceChunkPayload[] = []\n const emittedChunkIds = new Set<string>()\n\n for (const piece of debugPieceTable(snapshot)) {\n if (!piece.visible) continue\n appendPieceSpans(snapshot, piece.buffer, piece.start, piece.length, {\n pieces,\n chunks,\n emittedChunkIds,\n sentChunkLengths: options.sentChunkLengths,\n })\n }\n\n return {\n length: snapshot.length,\n pieces,\n chunks,\n }\n}\n\nexport const resolveTreeSitterSourceDescriptor = (\n cache: TreeSitterSourceCache,\n documentId: string,\n descriptor: TreeSitterSourceDescriptor,\n): TreeSitterPieceTableInput => {\n const documentCache = ensureDocumentSourceCache(cache, documentId)\n const chunks = resolveDescriptorChunks(documentCache, descriptor)\n // The client forgets the same chunks when it builds the descriptor, so both sides stay in step.\n keepReferencedChunks(documentCache, descriptor)\n return {\n length: descriptor.length,\n chunks,\n }\n}\n\nexport const disposeTreeSitterSourceDocument = (\n cache: TreeSitterSourceCache,\n documentId: string,\n): void => {\n cache.delete(documentId)\n}\n\nexport const clearTreeSitterSourceCache = (cache: TreeSitterSourceCache): void => {\n cache.clear()\n}\n\nexport const readTreeSitterPieceTableInput = (\n input: TreeSitterPieceTableInput,\n index: number,\n): string | undefined => {\n if (index < 0 || index >= input.length) return undefined\n\n const chunk = findChunkContainingWithCursor(input, index)\n if (!chunk) return undefined\n\n const sourceStart = chunk.chunkStart + index - chunk.start\n const sourceEnd = chunk.chunkStart + chunk.end - chunk.start\n const readEnd = safeParserReadEnd(\n chunk.source,\n sourceStart,\n Math.min(sourceEnd, sourceStart + PARSER_READ_BATCH_CODE_UNITS),\n sourceEnd,\n )\n return readResolvedChunkText(chunk.source, sourceStart, readEnd)\n}\n\nexport const readTreeSitterInputRange = (\n input: TreeSitterPieceTableInput,\n startIndex: number,\n endIndex: number,\n): string => {\n if (endIndex <= startIndex) return ''\n\n const chunks: string[] = []\n for (const chunk of input.chunks) {\n if (chunk.end <= startIndex) continue\n if (chunk.start >= endIndex) break\n\n const start = Math.max(startIndex, chunk.start) - chunk.start\n const end = Math.min(endIndex, chunk.end) - chunk.start\n chunks.push(\n readResolvedChunkText(chunk.source, chunk.chunkStart + start, chunk.chunkStart + end),\n )\n }\n\n return chunks.join('')\n}\n\ntype PieceSpanBuilder = {\n readonly pieces: TreeSitterSourcePieceSpan[]\n readonly chunks: TreeSitterSourceChunkPayload[]\n readonly emittedChunkIds: Set<string>\n readonly sentChunkLengths?: ReadonlyMap<string, number>\n}\n\nconst appendPieceSpans = (\n snapshot: PieceTableSnapshot,\n bufferId: PieceBufferId,\n start: number,\n length: number,\n builder: PieceSpanBuilder,\n): void => {\n forEachBufferSpan(snapshot.buffers, bufferId, start, start + length, (text, from, to, owner) => {\n appendSourceSpans(text, owner, from, to, builder)\n })\n}\n\nconst appendSourceSpans = (\n text: string,\n owner: object,\n start: number,\n end: number,\n builder: PieceSpanBuilder,\n): void => {\n let offset = start\n\n while (offset < end) {\n const chunkStart = Math.floor(offset / SOURCE_CHUNK_SIZE) * SOURCE_CHUNK_SIZE\n const chunkLength = Math.min(text.length - chunkStart, SOURCE_CHUNK_SIZE)\n const spanStart = offset - chunkStart\n const spanLength = Math.min(end - offset, chunkLength - spanStart)\n const chunkId = sourceChunkId(owner, chunkStart)\n\n builder.pieces.push({ chunkId, start: spanStart, length: spanLength })\n appendChunkPayload(text, chunkId, chunkStart, chunkLength, builder)\n offset += spanLength\n }\n}\n\nconst appendChunkPayload = (\n text: string,\n chunkId: string,\n chunkStart: number,\n chunkLength: number,\n builder: PieceSpanBuilder,\n): void => {\n // Physical owners survive append-only growth; forks and copied survivors get new owners.\n if (builder.sentChunkLengths?.get(chunkId) === chunkLength) return\n if (builder.emittedChunkIds.has(chunkId)) return\n\n builder.emittedChunkIds.add(chunkId)\n builder.chunks.push({ chunkId, text: text.slice(chunkStart, chunkStart + chunkLength) })\n}\n\nconst sourceChunkId = (owner: object, chunkStart: number): string => {\n let id = sourceOwners.get(owner)\n if (id === undefined) {\n id = nextSourceOwner++\n sourceOwners.set(owner, id)\n }\n return `${id}:${chunkStart}`\n}\n\nconst ensureDocumentSourceCache = (\n cache: TreeSitterSourceCache,\n documentId: string,\n): Map<string, ResolvedTreeSitterSourceChunk> => {\n const existing = cache.get(documentId)\n if (existing) return existing\n\n const documentCache = new Map<string, ResolvedTreeSitterSourceChunk>()\n cache.set(documentId, documentCache)\n return documentCache\n}\n\nconst resolveDescriptorChunks = (\n cache: Map<string, ResolvedTreeSitterSourceChunk>,\n descriptor: TreeSitterSourceDescriptor,\n): TreeSitterInputChunk[] => {\n cacheChunkPayloads(cache, descriptor.chunks)\n\n const chunks: TreeSitterInputChunk[] = []\n let documentOffset = 0\n for (const piece of descriptor.pieces) {\n const source = cache.get(piece.chunkId)\n if (!source) throw new Error(`Tree-sitter source chunk \"${piece.chunkId}\" is missing`)\n\n chunks.push({\n start: documentOffset,\n end: documentOffset + piece.length,\n chunkStart: piece.start,\n source,\n })\n documentOffset += piece.length\n }\n\n if (documentOffset !== descriptor.length) throw new Error('Tree-sitter source length mismatch')\n return chunks\n}\n\nconst keepReferencedChunks = (\n cache: Map<string, ResolvedTreeSitterSourceChunk>,\n descriptor: TreeSitterSourceDescriptor,\n): void => {\n const referenced = new Set(descriptor.pieces.map((piece) => piece.chunkId))\n for (const chunkId of cache.keys()) {\n if (!referenced.has(chunkId)) cache.delete(chunkId)\n }\n}\n\nconst cacheChunkPayloads = (\n cache: Map<string, ResolvedTreeSitterSourceChunk>,\n chunks: readonly TreeSitterSourceChunkPayload[],\n): void => {\n for (const chunk of chunks)\n cache.set(chunk.chunkId, { text: chunk.text, length: chunk.text.length })\n}\n\nconst readResolvedChunkText = (\n chunk: ResolvedTreeSitterSourceChunk,\n start: number,\n end: number,\n): string => chunk.text.slice(start, end)\n\nconst safeParserReadEnd = (\n chunk: ResolvedTreeSitterSourceChunk,\n start: number,\n end: number,\n maxEnd: number,\n): number => {\n if (end >= maxEnd || end <= start) return end\n\n const lastCodeUnit = readResolvedChunkCodeUnit(chunk, end - 1)\n if (!isHighSurrogate(lastCodeUnit)) return end\n return Math.max(start + 1, end - 1)\n}\n\nconst readResolvedChunkCodeUnit = (chunk: ResolvedTreeSitterSourceChunk, index: number): number =>\n chunk.text.charCodeAt(index)\n\nconst isHighSurrogate = (codeUnit: number): boolean => codeUnit >= 0xd800 && codeUnit <= 0xdbff\n\nconst findChunkContaining = (\n chunks: readonly TreeSitterInputChunk[],\n index: number,\n): TreeSitterInputChunk | null => {\n let low = 0\n let high = chunks.length - 1\n\n while (low <= high) {\n const middle = Math.floor((low + high) / 2)\n const chunk = chunks[middle]\n if (!chunk) return null\n\n if (index < chunk.start) {\n high = middle - 1\n continue\n }\n\n if (index >= chunk.end) {\n low = middle + 1\n continue\n }\n\n return chunk\n }\n\n return null\n}\n\nconst findChunkContainingWithCursor = (\n input: TreeSitterPieceTableInput,\n index: number,\n): TreeSitterInputChunk | null => {\n const cachedIndex = input.lastChunkIndex\n const cached = cachedIndex === undefined ? null : input.chunks[cachedIndex]\n if (cached && index >= cached.start && index < cached.end) return cached\n\n if (cachedIndex !== undefined) {\n const next = input.chunks[cachedIndex + 1]\n if (next && index >= next.start && index < next.end) {\n input.lastChunkIndex = cachedIndex + 1\n return next\n }\n }\n\n const chunk = findChunkContaining(input.chunks, index)\n if (chunk) input.lastChunkIndex = input.chunks.indexOf(chunk)\n return chunk\n}\n"],"mappings":";;AA6CA,IAAM,oBAAoB;AAE1B,IAAM,+BAA+B;AACrC,IAAM,+BAAe,IAAI,QAAwB;AACjD,IAAI,kBAAkB;AAEtB,IAAa,oCACX,UACA,UAA6C,CAAC,MACf;CAC/B,MAAM,SAAsC,CAAC;CAC7C,MAAM,SAAyC,CAAC;CAChD,MAAM,kCAAkB,IAAI,IAAY;CAExC,KAAK,MAAM,SAAS,gBAAgB,QAAQ,GAAG;EAC7C,IAAI,CAAC,MAAM,SAAS;EACpB,iBAAiB,UAAU,MAAM,QAAQ,MAAM,OAAO,MAAM,QAAQ;GAClE;GACA;GACA;GACA,kBAAkB,QAAQ;EA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IAAI,CAAC,OAAO,OAAO;EAEnB,IAAI,QAAQ,MAAM,OAAO;GACvB,OAAO,SAAS;GAChB;EACF;EAEA,IAAI,SAAS,MAAM,KAAK;GACtB,MAAM,SAAS;GACf;EACF;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,IAAM,iCACJ,OACA,UACgC;CAChC,MAAM,cAAc,MAAM;CAC1B,MAAM,SAAS,gBAAgB,KAAA,IAAY,OAAO,MAAM,OAAO;CAC/D,IAAI,UAAU,SAAS,OAAO,SAAS,QAAQ,OAAO,KAAK,OAAO;CAElE,IAAI,gBAAgB,KAAA,GAAW;EAC7B,MAAM,OAAO,MAAM,OAAO,cAAc;EACxC,IAAI,QAAQ,SAAS,KAAK,SAAS,QAAQ,KAAK,KAAK;GACnD,MAAM,iBAAiB,cAAc;GACrC,OAAO;EACT;CACF;CAEA,MAAM,QAAQ,oBAAoB,MAAM,QAAQ,KAAK;CACrD,IAAI,OAAO,MAAM,iBAAiB,MAAM,OAAO,QAAQ,KAAK;CAC5D,OAAO;AACT"}
@@ -0,0 +1,30 @@
1
+ import type { PieceTableSnapshot } from '@singapore-editor/core/document';
2
+ import { type TreeSitterSourceDescriptor } from './source';
3
+ export type TreeSitterSourceChunkRetentionSnapshot = {
4
+ readonly documents: number;
5
+ readonly sentChunks: number;
6
+ readonly sourceEpochs: number;
7
+ };
8
+ export type TreeSitterSourceChunkRequest = {
9
+ readonly documentId: string;
10
+ readonly source: TreeSitterSourceDescriptor;
11
+ readonly epoch: number;
12
+ };
13
+ export declare class TreeSitterSourceChunkRetention {
14
+ private readonly sentSourceChunkLengths;
15
+ private readonly sourceDocumentEpochs;
16
+ private readonly latestDescriptors;
17
+ createDescriptor(documentId: string, snapshot: PieceTableSnapshot): TreeSitterSourceDescriptor;
18
+ createRequest(documentId: string, source: TreeSitterSourceDescriptor): TreeSitterSourceChunkRequest;
19
+ markRequestSent(request: TreeSitterSourceChunkRequest | null): void;
20
+ invalidateDocument(documentId: string): void;
21
+ clear(): void;
22
+ inspect(): TreeSitterSourceChunkRetentionSnapshot;
23
+ private sourceChunkLengthsForDocument;
24
+ private canMarkRequestSent;
25
+ private currentSourceEpoch;
26
+ private hasDocumentState;
27
+ private documentCount;
28
+ private sentChunkCount;
29
+ }
30
+ //# sourceMappingURL=sourceChunkRetention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceChunkRetention.d.ts","sourceRoot":"","sources":["../../src/treeSitter/sourceChunkRetention.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAoC,KAAK,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAE5F,MAAM,MAAM,sCAAsC,GAAG;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAA;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,8BAA8B;IAIzC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAyC;IAChF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA4B;IAGjE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0D;IAErF,gBAAgB,CACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,kBAAkB,GAC3B,0BAA0B;IAWtB,aAAa,CAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,0BAA0B,GACjC,4BAA4B;IAQxB,eAAe,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI,GAAG,IAAI;IAUnE,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAQ5C,KAAK,IAAI,IAAI;IAMb,OAAO,IAAI,sCAAsC;IAQxD,OAAO,CAAC,6BAA6B;IAUrC,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,cAAc;CAKvB"}
@@ -0,0 +1,76 @@
1
+ import { createTreeSitterSourceDescriptor } from "./source.js";
2
+ //#region src/treeSitter/sourceChunkRetention.ts
3
+ var TreeSitterSourceChunkRetention = class {
4
+ sentSourceChunkLengths = /* @__PURE__ */ new Map();
5
+ sourceDocumentEpochs = /* @__PURE__ */ new Map();
6
+ latestDescriptors = /* @__PURE__ */ new Map();
7
+ createDescriptor(documentId, snapshot) {
8
+ const sent = this.sourceChunkLengthsForDocument(documentId);
9
+ const descriptor = createTreeSitterSourceDescriptor(snapshot, { sentChunkLengths: sent });
10
+ const referenced = new Set(descriptor.pieces.map((piece) => piece.chunkId));
11
+ for (const chunkId of sent.keys()) if (!referenced.has(chunkId)) sent.delete(chunkId);
12
+ this.latestDescriptors.set(documentId, descriptor.pieces);
13
+ return descriptor;
14
+ }
15
+ createRequest(documentId, source) {
16
+ return {
17
+ documentId,
18
+ source,
19
+ epoch: this.currentSourceEpoch(documentId)
20
+ };
21
+ }
22
+ markRequestSent(request) {
23
+ if (!request) return;
24
+ if (!this.canMarkRequestSent(request)) return;
25
+ const sent = this.sourceChunkLengthsForDocument(request.documentId);
26
+ for (const chunk of request.source.chunks) sent.set(chunk.chunkId, chunk.text.length);
27
+ }
28
+ invalidateDocument(documentId) {
29
+ if (!this.hasDocumentState(documentId)) return;
30
+ this.sentSourceChunkLengths.delete(documentId);
31
+ this.latestDescriptors.delete(documentId);
32
+ this.sourceDocumentEpochs.set(documentId, this.currentSourceEpoch(documentId) + 1);
33
+ }
34
+ clear() {
35
+ this.sentSourceChunkLengths.clear();
36
+ this.latestDescriptors.clear();
37
+ this.sourceDocumentEpochs.clear();
38
+ }
39
+ inspect() {
40
+ return {
41
+ documents: this.documentCount(),
42
+ sentChunks: this.sentChunkCount(),
43
+ sourceEpochs: this.sourceDocumentEpochs.size
44
+ };
45
+ }
46
+ sourceChunkLengthsForDocument(documentId) {
47
+ const existing = this.sentSourceChunkLengths.get(documentId);
48
+ if (existing) return existing;
49
+ const sent = /* @__PURE__ */ new Map();
50
+ this.sentSourceChunkLengths.set(documentId, sent);
51
+ return sent;
52
+ }
53
+ canMarkRequestSent(request) {
54
+ if (request.epoch !== this.currentSourceEpoch(request.documentId)) return false;
55
+ return this.latestDescriptors.get(request.documentId) === request.source.pieces;
56
+ }
57
+ currentSourceEpoch(documentId) {
58
+ return this.sourceDocumentEpochs.get(documentId) ?? 0;
59
+ }
60
+ hasDocumentState(documentId) {
61
+ if (this.sentSourceChunkLengths.has(documentId)) return true;
62
+ return this.sourceDocumentEpochs.has(documentId);
63
+ }
64
+ documentCount() {
65
+ return (/* @__PURE__ */ new Set([...this.sentSourceChunkLengths.keys(), ...this.sourceDocumentEpochs.keys()])).size;
66
+ }
67
+ sentChunkCount() {
68
+ let count = 0;
69
+ for (const chunks of this.sentSourceChunkLengths.values()) count += chunks.size;
70
+ return count;
71
+ }
72
+ };
73
+ //#endregion
74
+ export { TreeSitterSourceChunkRetention };
75
+
76
+ //# sourceMappingURL=sourceChunkRetention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceChunkRetention.js","names":[],"sources":["../../src/treeSitter/sourceChunkRetention.ts"],"sourcesContent":["import type { PieceTableSnapshot } from '@singapore-editor/core/document'\nimport { createTreeSitterSourceDescriptor, type TreeSitterSourceDescriptor } from './source'\n\nexport type TreeSitterSourceChunkRetentionSnapshot = {\n readonly documents: number\n readonly sentChunks: number\n readonly sourceEpochs: number\n}\n\nexport type TreeSitterSourceChunkRequest = {\n readonly documentId: string\n readonly source: TreeSitterSourceDescriptor\n readonly epoch: number\n}\n\nexport class TreeSitterSourceChunkRetention {\n // chunkId → sent length. Buffers are append-only, so a chunk id with an\n // unchanged length is byte-identical to what the worker already caches; a\n // longer length means the tail chunk grew and must be re-sent.\n private readonly sentSourceChunkLengths = new Map<string, Map<string, number>>()\n private readonly sourceDocumentEpochs = new Map<string, number>()\n // The worker keeps only the chunks of the last descriptor it received; see keepReferencedChunks.\n // Pieces identify a descriptor without pinning its payload text.\n private readonly latestDescriptors = new Map<string, TreeSitterSourceDescriptor['pieces']>()\n\n public createDescriptor(\n documentId: string,\n snapshot: PieceTableSnapshot,\n ): TreeSitterSourceDescriptor {\n const sent = this.sourceChunkLengthsForDocument(documentId)\n const descriptor = createTreeSitterSourceDescriptor(snapshot, { sentChunkLengths: sent })\n const referenced = new Set(descriptor.pieces.map((piece) => piece.chunkId))\n for (const chunkId of sent.keys()) {\n if (!referenced.has(chunkId)) sent.delete(chunkId)\n }\n this.latestDescriptors.set(documentId, descriptor.pieces)\n return descriptor\n }\n\n public createRequest(\n documentId: string,\n source: TreeSitterSourceDescriptor,\n ): TreeSitterSourceChunkRequest {\n return {\n documentId,\n source,\n epoch: this.currentSourceEpoch(documentId),\n }\n }\n\n public markRequestSent(request: TreeSitterSourceChunkRequest | null): void {\n if (!request) return\n if (!this.canMarkRequestSent(request)) return\n\n const sent = this.sourceChunkLengthsForDocument(request.documentId)\n for (const chunk of request.source.chunks) {\n sent.set(chunk.chunkId, chunk.text.length)\n }\n }\n\n public invalidateDocument(documentId: string): void {\n if (!this.hasDocumentState(documentId)) return\n\n this.sentSourceChunkLengths.delete(documentId)\n this.latestDescriptors.delete(documentId)\n this.sourceDocumentEpochs.set(documentId, this.currentSourceEpoch(documentId) + 1)\n }\n\n public clear(): void {\n this.sentSourceChunkLengths.clear()\n this.latestDescriptors.clear()\n this.sourceDocumentEpochs.clear()\n }\n\n public inspect(): TreeSitterSourceChunkRetentionSnapshot {\n return {\n documents: this.documentCount(),\n sentChunks: this.sentChunkCount(),\n sourceEpochs: this.sourceDocumentEpochs.size,\n }\n }\n\n private sourceChunkLengthsForDocument(documentId: string): Map<string, number> {\n const existing = this.sentSourceChunkLengths.get(documentId)\n if (existing) return existing\n\n const sent = new Map<string, number>()\n this.sentSourceChunkLengths.set(documentId, sent)\n return sent\n }\n\n // An older response may name chunks a newer descriptor has since told the worker to drop.\n private canMarkRequestSent(request: TreeSitterSourceChunkRequest): boolean {\n if (request.epoch !== this.currentSourceEpoch(request.documentId)) return false\n return this.latestDescriptors.get(request.documentId) === request.source.pieces\n }\n\n private currentSourceEpoch(documentId: string): number {\n return this.sourceDocumentEpochs.get(documentId) ?? 0\n }\n\n private hasDocumentState(documentId: string): boolean {\n if (this.sentSourceChunkLengths.has(documentId)) return true\n return this.sourceDocumentEpochs.has(documentId)\n }\n\n private documentCount(): number {\n return new Set([...this.sentSourceChunkLengths.keys(), ...this.sourceDocumentEpochs.keys()])\n .size\n }\n\n private sentChunkCount(): number {\n let count = 0\n for (const chunks of this.sentSourceChunkLengths.values()) count += chunks.size\n return count\n }\n}\n"],"mappings":";;AAeA,IAAa,iCAAb,MAA4C;CAI1C,yCAA0C,IAAI,IAAiC;CAC/E,uCAAwC,IAAI,IAAoB;CAGhE,oCAAqC,IAAI,IAAkD;CAE3F,iBACE,YACA,UAC4B;EAC5B,MAAM,OAAO,KAAK,8BAA8B,UAAU;EAC1D,MAAM,aAAa,iCAAiC,UAAU,EAAE,kBAAkB,KAAK,CAAC;EACxF,MAAM,aAAa,IAAI,IAAI,WAAW,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC;EAC1E,KAAK,MAAM,WAAW,KAAK,KAAK,GAC9B,IAAI,CAAC,WAAW,IAAI,OAAO,GAAG,KAAK,OAAO,OAAO;EAEnD,KAAK,kBAAkB,IAAI,YAAY,WAAW,MAAM;EACxD,OAAO;CACT;CAEA,cACE,YACA,QAC8B;EAC9B,OAAO;GACL;GACA;GACA,OAAO,KAAK,mBAAmB,UAAU;EAC3C;CACF;CAEA,gBAAuB,SAAoD;EACzE,IAAI,CAAC,SAAS;EACd,IAAI,CAAC,KAAK,mBAA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L;CAEA,iBAAiC;EAC/B,IAAI,QAAQ;EACZ,KAAK,MAAM,UAAU,KAAK,uBAAuB,OAAO,GAAG,SAAS,OAAO;EAC3E,OAAO;CACT;AACF"}
@@ -0,0 +1,64 @@
1
+ import { Language, Parser, Query, type Node, type Range as TreeSitterRange, type Tree } from 'web-tree-sitter';
2
+ import { MarkdownDocument } from 'tree-sitter-md';
3
+ import type { TreeSitterLanguageDescriptor } from './registry';
4
+ import { type TreeSitterSourceCache, type TreeSitterPieceTableInput } from './source';
5
+ import type { BracketInfo, TreeSitterCapture, TreeSitterDegradedState, TreeSitterEditRequest, TreeSitterError, TreeSitterLanguageId, TreeSitterParseRequest, TreeSitterParseResult, TreeSitterSyntaxRange } from './types';
6
+ type Runtime = {
7
+ readonly descriptor: TreeSitterLanguageDescriptor;
8
+ readonly language: Language;
9
+ readonly parser: Parser;
10
+ highlightQuery: Query | null;
11
+ foldQuery: Query | null;
12
+ injectionQuery: Query | null;
13
+ };
14
+ type LayerKind = 'root' | 'injection' | 'combined-injection';
15
+ type LayerKey = string;
16
+ type ParsedLayer = {
17
+ readonly id: string;
18
+ readonly key: LayerKey;
19
+ readonly kind: LayerKind;
20
+ readonly parentId: string | null;
21
+ readonly parentLanguageId: TreeSitterLanguageId | null;
22
+ readonly languageId: TreeSitterLanguageId;
23
+ readonly depth: number;
24
+ readonly tree: Tree;
25
+ readonly ranges: readonly TreeSitterRange[];
26
+ };
27
+ type ParsedDocument = {
28
+ readonly markdown?: MarkdownDocument;
29
+ readonly snapshotVersion: number;
30
+ readonly languageId: TreeSitterLanguageId;
31
+ readonly source: TreeSitterPieceTableInput;
32
+ readonly layers: readonly ParsedLayer[];
33
+ readonly degraded: readonly TreeSitterDegradedState[];
34
+ readonly missingLanguages: readonly string[];
35
+ readonly size: number;
36
+ lastUsed: number;
37
+ };
38
+ type CancellationContext = {
39
+ readonly startedAt: number;
40
+ readonly budgetMs: number;
41
+ readonly flag: Int32Array | null;
42
+ readonly measurements?: Map<string, number>;
43
+ readonly counts?: Map<string, number>;
44
+ };
45
+ export declare const __treeSitterWorkerInternalsForTests: {
46
+ applyTextEdit: (text: string, startIndex: number, oldEndIndex: number, insertedText: string) => string;
47
+ applyTextEdits: (text: string, edits: readonly TreeSitterEditRequest["edits"][number][]) => string;
48
+ collectBracket: (node: Node, bracketStack: {
49
+ char: string;
50
+ index: number;
51
+ }[]) => BracketInfo | null;
52
+ collectCaptures: (tree: Tree | null, runtime: Runtime, context: CancellationContext, range?: TreeSitterSyntaxRange) => TreeSitterCapture[];
53
+ collectError: (node: Node) => TreeSitterError | null;
54
+ collectTreeData: (tree: Tree | null, range?: TreeSitterSyntaxRange) => Pick<TreeSitterParseResult, "brackets" | "errors">;
55
+ appendItems: <T>(target: T[], items: readonly T[]) => void;
56
+ rangeSpan: (ranges: readonly TreeSitterRange[]) => Pick<TreeSitterRange, "startIndex" | "endIndex">;
57
+ resolveTreeSitterSourceDescriptor: (cache: TreeSitterSourceCache, documentId: string, descriptor: import("./source").TreeSitterSourceDescriptor) => TreeSitterPieceTableInput;
58
+ readTreeSitterPieceTableInput: (input: TreeSitterPieceTableInput, index: number) => string | undefined;
59
+ replaceCachedDocument: (documentId: string, snapshot: ParsedDocument) => void;
60
+ reusableParsedDocument: (request: TreeSitterParseRequest, source: TreeSitterPieceTableInput, context: CancellationContext) => Promise<ParsedDocument | null>;
61
+ disposeDocument: (runtimeSessionId: string) => void;
62
+ };
63
+ export {};
64
+ //# sourceMappingURL=treeSitter.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeSitter.worker.d.ts","sourceRoot":"","sources":["../../src/treeSitter/treeSitter.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,KAAK,IAAI,EACT,KAAK,KAAK,IAAI,eAAe,EAC7B,KAAK,IAAI,EAEV,MAAM,iBAAiB,CAAA;AAQxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;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IAAI,CAAC,qBAAqB,EAAE,UAAU,GAAG,QAAQ,CAAC;kBAikBhC,CAAC,UAAU,CAAC,EAAE,SAAS,SAAS,CAAC,EAAE,KAAG,IAAI;wBAvrBrD,SAAS,eAAe,EAAE,KACjC,IAAI,CAAC,eAAe,EAAE,YAAY,GAAG,UAAU,CAAC;;;wCAuYR,MAAM,YAAY,cAAc,KAAG,IAAI;sCA1gEvE,sBAAsB,UACvB,yBAAyB,WACxB,mBAAmB,KAC3B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;wCAooEU,MAAM,KAAG,IAAI;CA2TvD,CAAA"}
@@ -0,0 +1,198 @@
1
+ import type { TextEdit } from '@singapore-editor/core/document';
2
+ import type { EditorToken, PackedEditorTokens } from '@singapore-editor/core/syntax';
3
+ import type { TreeSitterLanguageDescriptor, TreeSitterLanguageId } from './registry';
4
+ import type { TreeSitterSourceDescriptor } from './source';
5
+ export type { TreeSitterLanguageId } from './registry';
6
+ export type TreeSitterCapture = {
7
+ readonly startIndex: number;
8
+ readonly endIndex: number;
9
+ readonly captureName: string;
10
+ readonly languageId?: TreeSitterLanguageId;
11
+ };
12
+ export type FoldRange = {
13
+ readonly startIndex: number;
14
+ readonly endIndex: number;
15
+ readonly startLine: number;
16
+ readonly endLine: number;
17
+ readonly type: string;
18
+ readonly languageId?: TreeSitterLanguageId;
19
+ };
20
+ export type BracketInfo = {
21
+ readonly index: number;
22
+ readonly char: string;
23
+ readonly depth: number;
24
+ };
25
+ export type TreeSitterError = {
26
+ readonly startIndex: number;
27
+ readonly endIndex: number;
28
+ readonly message: string;
29
+ readonly isMissing: boolean;
30
+ };
31
+ export type TreeSitterPoint = {
32
+ readonly row: number;
33
+ readonly column: number;
34
+ };
35
+ export type TreeSitterInputEdit = {
36
+ readonly startIndex: number;
37
+ readonly oldEndIndex: number;
38
+ readonly newEndIndex: number;
39
+ readonly startPosition: TreeSitterPoint;
40
+ readonly oldEndPosition: TreeSitterPoint;
41
+ readonly newEndPosition: TreeSitterPoint;
42
+ };
43
+ export type TreeSitterInjectionInfo = {
44
+ readonly parentLanguageId: TreeSitterLanguageId;
45
+ readonly languageId: TreeSitterLanguageId;
46
+ readonly startIndex: number;
47
+ readonly endIndex: number;
48
+ };
49
+ type TreeSitterTimingMeasurement = {
50
+ readonly name: string;
51
+ readonly durationMs: number;
52
+ };
53
+ export type TreeSitterDegradedState = {
54
+ readonly kind: 'optional-phase-failed' | 'injection-failed';
55
+ readonly phase: string;
56
+ readonly message: string;
57
+ };
58
+ export type TreeSitterParseResult = {
59
+ readonly documentId: string;
60
+ readonly snapshotVersion: number;
61
+ readonly languageId: TreeSitterLanguageId;
62
+ readonly captures: readonly TreeSitterCapture[];
63
+ readonly records?: {
64
+ readonly languageId: string;
65
+ readonly data: Uint32Array;
66
+ };
67
+ readonly folds: readonly FoldRange[];
68
+ readonly brackets: readonly BracketInfo[];
69
+ readonly errors: readonly TreeSitterError[];
70
+ readonly injections: readonly TreeSitterInjectionInfo[];
71
+ readonly degraded?: readonly TreeSitterDegradedState[];
72
+ readonly tokens?: readonly EditorToken[];
73
+ readonly tokensPacked?: PackedEditorTokens;
74
+ readonly statistics?: Readonly<Record<string, number>>;
75
+ readonly missingLanguages?: readonly string[];
76
+ readonly timings: readonly TreeSitterTimingMeasurement[];
77
+ };
78
+ export type TreeSitterSyntaxRange = {
79
+ readonly startIndex: number;
80
+ readonly endIndex: number;
81
+ };
82
+ export type TreeSitterParseAckResult = {
83
+ readonly documentId: string;
84
+ readonly snapshotVersion: number;
85
+ readonly languageId: TreeSitterLanguageId;
86
+ readonly status: 'parsed';
87
+ readonly changedRanges: readonly TreeSitterSyntaxRange[];
88
+ readonly degraded?: readonly TreeSitterDegradedState[];
89
+ readonly statistics?: Readonly<Record<string, number>>;
90
+ readonly missingLanguages?: readonly string[];
91
+ readonly timings: readonly TreeSitterTimingMeasurement[];
92
+ };
93
+ export type TreeSitterRangeResult = TreeSitterParseResult & {
94
+ readonly range: TreeSitterSyntaxRange;
95
+ };
96
+ type TreeSitterInitRequest = {
97
+ readonly type: 'init';
98
+ };
99
+ type TreeSitterRegisterLanguagesRequest = {
100
+ readonly type: 'registerLanguages';
101
+ readonly languages: readonly TreeSitterLanguageDescriptor[];
102
+ };
103
+ type TreeSitterWarmLanguagesRequest = {
104
+ readonly type: 'warmLanguages';
105
+ readonly languageIds: readonly TreeSitterLanguageId[];
106
+ };
107
+ export type TreeSitterParseRequest = {
108
+ readonly type: 'parse';
109
+ readonly documentId: string;
110
+ readonly runtimeSessionId: string;
111
+ readonly snapshotVersion: number;
112
+ readonly languageId: TreeSitterLanguageId;
113
+ readonly includeHighlights: boolean;
114
+ readonly includeCaptures?: boolean;
115
+ readonly resultMode?: 'full' | 'parseOnly';
116
+ readonly source: TreeSitterSourceDescriptor;
117
+ readonly generation: number;
118
+ readonly cancellationBuffer?: SharedArrayBuffer;
119
+ };
120
+ export type TreeSitterEditRequest = {
121
+ readonly type: 'edit';
122
+ readonly documentId: string;
123
+ readonly runtimeSessionId: string;
124
+ readonly previousSnapshotVersion: number;
125
+ readonly snapshotVersion: number;
126
+ readonly languageId: TreeSitterLanguageId;
127
+ readonly includeHighlights: boolean;
128
+ readonly includeCaptures?: boolean;
129
+ readonly resultMode?: 'full' | 'parseOnly';
130
+ readonly source: TreeSitterSourceDescriptor;
131
+ readonly edits: readonly TextEdit[];
132
+ readonly inputEdits: readonly TreeSitterInputEdit[];
133
+ readonly generation: number;
134
+ readonly cancellationBuffer?: SharedArrayBuffer;
135
+ };
136
+ export type TreeSitterRangeRequest = {
137
+ readonly type: 'queryRange';
138
+ readonly documentId: string;
139
+ readonly runtimeSessionId: string;
140
+ readonly snapshotVersion: number;
141
+ readonly languageId: TreeSitterLanguageId;
142
+ readonly includeHighlights: boolean;
143
+ readonly includeCaptures?: boolean;
144
+ readonly range: TreeSitterSyntaxRange;
145
+ readonly generation: number;
146
+ readonly cancellationBuffer?: SharedArrayBuffer;
147
+ };
148
+ export type TreeSitterSelectionRange = {
149
+ readonly startIndex: number;
150
+ readonly endIndex: number;
151
+ };
152
+ type TreeSitterSelectionAction = 'selectToken' | 'expand';
153
+ export type TreeSitterSelectionRequest = {
154
+ readonly type: 'selection';
155
+ readonly documentId: string;
156
+ readonly runtimeSessionId: string;
157
+ readonly snapshotVersion: number;
158
+ readonly languageId: TreeSitterLanguageId;
159
+ readonly action: TreeSitterSelectionAction;
160
+ readonly ranges: readonly TreeSitterSelectionRange[];
161
+ };
162
+ export type TreeSitterSelectionResult = {
163
+ readonly documentId: string;
164
+ readonly snapshotVersion: number;
165
+ readonly languageId: TreeSitterLanguageId;
166
+ readonly status: 'ok' | 'stale';
167
+ readonly ranges: readonly TreeSitterSelectionRange[];
168
+ };
169
+ type TreeSitterDisposeDocumentRequest = {
170
+ readonly type: 'disposeDocument';
171
+ readonly runtimeSessionId: string;
172
+ };
173
+ type TreeSitterRuntimeBarrierRequest = {
174
+ readonly type: 'runtimeBarrier';
175
+ readonly runtimeSessionId: string;
176
+ };
177
+ type TreeSitterIdleFenceRequest = {
178
+ readonly type: 'idleFence';
179
+ };
180
+ type TreeSitterDisposeRequest = {
181
+ readonly type: 'dispose';
182
+ };
183
+ export type TreeSitterWorkerRequestPayload = TreeSitterInitRequest | TreeSitterRegisterLanguagesRequest | TreeSitterWarmLanguagesRequest | TreeSitterParseRequest | TreeSitterEditRequest | TreeSitterRangeRequest | TreeSitterSelectionRequest | TreeSitterDisposeDocumentRequest | TreeSitterRuntimeBarrierRequest | TreeSitterIdleFenceRequest | TreeSitterDisposeRequest;
184
+ export type TreeSitterWorkerResult = TreeSitterParseResult | TreeSitterParseAckResult | TreeSitterRangeResult | TreeSitterSelectionResult | undefined;
185
+ export type TreeSitterWorkerRequest = {
186
+ readonly id: number;
187
+ readonly payload: TreeSitterWorkerRequestPayload;
188
+ };
189
+ export type TreeSitterWorkerResponse = {
190
+ readonly id: number;
191
+ readonly ok: true;
192
+ readonly result?: TreeSitterWorkerResult;
193
+ } | {
194
+ readonly id: number;
195
+ readon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CAAA;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;CAClC,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAC3B,CAAA;AAED,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,8BAA8B,GACtC,qBAAqB,GACrB,kCAAkC,GAClC,8BAA8B,GAC9B,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,0BAA0B,GAC1B,gCAAgC,GAChC,+BAA+B,GAC/B,0BAA0B,GAC1B,wBAAwB,CAAA;AAE5B,MAAM,MAAM,sBAAsB,GAC9B,qBAAqB,GACrB,wBAAwB,GACxB,qBAAqB,GACrB,yBAAyB,GACzB,SAAS,CAAA;AAEb,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,8BAA8B,CAAA;CACjD,CAAA;AAED,MAAM,MAAM,wBAAwB,GAChC;IACE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;IACjB,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAA;CACzC,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA"}
@@ -0,0 +1,133 @@
1
+ import type { TreeSitterLanguageDescriptor } from './registry';
2
+ import { type TreeSitterSourceChunkRetentionSnapshot } from './sourceChunkRetention';
3
+ import type { TreeSitterEditRequest, TreeSitterLanguageId, TreeSitterParseAckResult, TreeSitterParseResult, TreeSitterRangeResult, TreeSitterSelectionRequest, TreeSitterSelectionResult, TreeSitterSyntaxRange } from './types';
4
+ import type { PieceTableSnapshot } from '@singapore-editor/core/document';
5
+ export type TreeSitterParsePayload = {
6
+ readonly documentId: string;
7
+ readonly runtimeSessionId: string;
8
+ readonly snapshotVersion: number;
9
+ readonly languageId: TreeSitterLanguageId;
10
+ readonly includeHighlights?: boolean;
11
+ readonly includeCaptures?: boolean;
12
+ readonly resultMode?: 'full';
13
+ readonly snapshot: PieceTableSnapshot;
14
+ };
15
+ export type TreeSitterParseOnlyPayload = Omit<TreeSitterParsePayload, 'resultMode'> & {
16
+ readonly resultMode: 'parseOnly';
17
+ };
18
+ export type TreeSitterBackendParsePayload = TreeSitterParsePayload | TreeSitterParseOnlyPayload;
19
+ export type TreeSitterEditPayload = {
20
+ readonly documentId: string;
21
+ readonly runtimeSessionId: string;
22
+ readonly previousSnapshotVersion: number;
23
+ readonly snapshotVersion: number;
24
+ readonly languageId: TreeSitterLanguageId;
25
+ readonly includeHighlights: boolean;
26
+ readonly includeCaptures?: boolean;
27
+ readonly resultMode?: 'full';
28
+ readonly snapshot: PieceTableSnapshot;
29
+ readonly edits: readonly TreeSitterEditRequest['edits'][number][];
30
+ readonly inputEdits: readonly TreeSitterEditRequest['inputEdits'][number][];
31
+ };
32
+ export type TreeSitterEditOnlyPayload = Omit<TreeSitterEditPayload, 'resultMode'> & {
33
+ readonly resultMode: 'parseOnly';
34
+ };
35
+ export type TreeSitterBackendEditPayload = TreeSitterEditPayload | TreeSitterEditOnlyPayload;
36
+ export type TreeSitterRangePayload = {
37
+ readonly documentId: string;
38
+ readonly runtimeSessionId: string;
39
+ readonly snapshotVersion: number;
40
+ readonly languageId: TreeSitterLanguageId;
41
+ readonly includeHighlights?: boolean;
42
+ readonly includeCaptures?: boolean;
43
+ readonly range: TreeSitterSyntaxRange;
44
+ };
45
+ export type TreeSitterSelectionPayload = Omit<TreeSitterSelectionRequest, 'type'>;
46
+ export type TreeSitterWorkerLifecycleState = 'idle' | 'initializing' | 'ready' | 'disposing' | 'disposed' | 'crashed';
47
+ export type TreeSitterWorkerCacheSnapshot = {
48
+ readonly registeredLanguages: number;
49
+ readonly sourceChunks: TreeSitterSourceChunkRetentionSnapshot;
50
+ };
51
+ export type TreeSitterWorkerOwnerSnapshot = {
52
+ readonly lifecycle: TreeSitterWorkerLifecycleState;
53
+ readonly pendingRequests: number;
54
+ readonly workerGeneration: number;
55
+ readonly cache: TreeSitterWorkerCacheSnapshot;
56
+ readonly lastError: string | null;
57
+ };
58
+ export type TreeSitterBackend = {
59
+ registerLanguages(languages: readonly TreeSitterLanguageDescriptor[]): Promise<void>;
60
+ /** Starts the worker, then registers and compiles `languages` ahead of their first document. */
61
+ warmLanguages?(languages: readonly TreeSitterLanguageDescriptor[]): Promise<void>;
62
+ parse(payload: TreeSitterBackendParsePayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
63
+ edit(payload: TreeSitterBackendEditPayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
64
+ queryRange?(payload: TreeSitterRangePayload): Promise<TreeSitterRangeResult | undefined>;
65
+ select(payload: TreeSitterSelectionPayload): Promise<TreeSitterSelectionResult | undefined>;
66
+ disposeDocument(runtimeSessionId: string): void;
67
+ awaitRuntimeSessionIdle?(runtimeSessionId: string): Promise<void>;
68
+ awaitIdleFence?(): Promise<void>;
69
+ dispose?(): Promise<void>;
70
+ };
71
+ export declare const canUseTreeSitterWorker: () => boolean;
72
+ export declare class TreeSitterWorkerClient implements TreeSitterBackend {
73
+ private worker;
74
+ private disposeTask;
75
+ private nextRequestId;
76
+ private nextGeneration;
77
+ private workerGeneration;
78
+ private lifecycle;
79
+ private lastError;
80
+ private initPromise;
81
+ private readonly pendingRequests;
82
+ private readonly clientTasks;
83
+ private readonly runtimeTasks;
84
+ private readonly sourceChunkRetention;
85
+ private readonly registeredLanguages;
86
+ private readonly warmedLanguages;
87
+ inspect(): TreeSitterWorkerOwnerSnapshot;
88
+ registerLanguages(languages: readonly TreeSitterLanguageDescriptor[]): Promise<void>;
89
+ private finishRegisterLanguages;
90
+ warmLanguages(languages: readonly TreeSitterLanguageDescriptor[]): Promise<void>;
91
+ private finishWarmLanguages;
92
+ parse(payload: TreeSitterParseOnlyPayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
93
+ parse(payload: TreeSitterParsePayload): Promise<TreeSitterParseResult | undefined>;
94
+ parse(payload: TreeSitterBackendParsePayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
95
+ private finishParse;
96
+ edit(payload: TreeSitterEditOnlyPayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
97
+ edit(payload: TreeSitterEditPayload): Promise<TreeSitterParseResult | undefined>;
98
+ edit(payload: TreeSitterBackendEditPayload): Promise<TreeSitterParseResult | TreeSitterParseAckResult | undefined>;
99
+ private finishEdit;
100
+ queryRange(payload: TreeSitterRangePayload): Promise<TreeSitterRangeResult | undefined>;
101
+ private finishQueryRange;
102
+ select(payload: TreeSitterSelectionPayload): Promise<TreeSitterSelectionResult | undefined>;
103
+ private finishSelect;
104
+ disposeDocument(runtimeSessionId: string): void;
105
+ awaitRuntimeSessionIdle(runtimeSessionId: string): Promise<void>;
106
+ awaitIdleFence(): Promise<void>;
107
+ dispose(): Promise<void>;
108
+ private finishDispose;
109
+ private getWorker;
110
+ private ensureWorkerReady;
111
+ private postRequest;
112
+ private postDocumentRequest;
113
+ private postRangeRequest;
114
+ private cancelPreviousDocumentRequests;
115
+ private cancelPreviousRangeRequests;
116
+ private cancelRuntimeRequests;
117
+ private createCancellationFlag;
118
+ private withCancellation;
119
+ private handleWorkerMessage;
120
+ private handleWorkerError;
121
+ private rejectPendingRequests;
122
+ private shouldRegisterLanguageWithWorker;
123
+ private unregisteredLanguages;
124
+ private createSourceDescriptor;
125
+ private sourceRequestForPayload;
126
+ private trackClientTask;
127
+ private trackRuntimeTask;
128
+ private awaitClientTasks;
129
+ private awaitRuntimeTasks;
130
+ private clearRetainedState;
131
+ }
132
+ export declare const createTreeSitterWorkerBackend: () => TreeSitterB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