( node: SyntaxNode, code: string, maxChunkSize: number, root = true, )
| 211 | } |
| 212 | |
| 213 | async function* getSmartCollapsedChunks( |
| 214 | node: SyntaxNode, |
| 215 | code: string, |
| 216 | maxChunkSize: number, |
| 217 | root = true, |
| 218 | ): AsyncGenerator<ChunkWithoutID> { |
| 219 | const chunk = await maybeYieldChunk(node, code, maxChunkSize, root); |
| 220 | if (chunk) { |
| 221 | yield chunk; |
| 222 | return; |
| 223 | } |
| 224 | // If a collapsed form is defined, use that |
| 225 | if (node.type in collapsedNodeConstructors) { |
| 226 | yield { |
| 227 | content: await collapsedNodeConstructors[node.type]( |
| 228 | node, |
| 229 | code, |
| 230 | maxChunkSize, |
| 231 | ), |
| 232 | startLine: node.startPosition.row, |
| 233 | endLine: node.endPosition.row, |
| 234 | }; |
| 235 | } |
| 236 | |
| 237 | // Recurse (because even if collapsed version was shown, want to show the children in full somewhere) |
| 238 | const generators = node.children.map((child) => |
| 239 | getSmartCollapsedChunks(child, code, maxChunkSize, false), |
| 240 | ); |
| 241 | for (const generator of generators) { |
| 242 | yield* generator; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | export async function* codeChunker( |
| 247 | filepath: string, |
no test coverage detected