( node: SyntaxNode, code: string, maxChunkSize: number, root = true, )
| 191 | }; |
| 192 | |
| 193 | async function maybeYieldChunk( |
| 194 | node: SyntaxNode, |
| 195 | code: string, |
| 196 | maxChunkSize: number, |
| 197 | root = true, |
| 198 | ): Promise<ChunkWithoutID | undefined> { |
| 199 | // Keep entire text if not over size |
| 200 | if (root || node.type in collapsedNodeConstructors) { |
| 201 | const tokenCount = await countTokensAsync(node.text); |
| 202 | if (tokenCount < maxChunkSize) { |
| 203 | return { |
| 204 | content: node.text, |
| 205 | startLine: node.startPosition.row, |
| 206 | endLine: node.endPosition.row, |
| 207 | }; |
| 208 | } |
| 209 | } |
| 210 | return undefined; |
| 211 | } |
| 212 | |
| 213 | async function* getSmartCollapsedChunks( |
| 214 | node: SyntaxNode, |
no test coverage detected