MCPcopy
hub / github.com/continuedev/continue / getSmartCollapsedChunks

Function getSmartCollapsedChunks

core/indexing/chunk/code.ts:213–244  ·  view source on GitHub ↗
(
  node: SyntaxNode,
  code: string,
  maxChunkSize: number,
  root = true,
)

Source from the content-addressed store, hash-verified

211}
212
213async 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
246export async function* codeChunker(
247 filepath: string,

Callers 1

codeChunkerFunction · 0.85

Calls 1

maybeYieldChunkFunction · 0.85

Tested by

no test coverage detected