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

Function processLimitedSizeGroup

core/nextEdit/diff/diff.ts:365–416  ·  view source on GitHub ↗

* Process a changed area with a limited group size.

(
  diffLines: DiffLine[],
  start: number,
  end: number,
  maxGroupSize: number,
  offset: number,
)

Source from the content-addressed store, hash-verified

363 * Process a changed area with a limited group size.
364 */
365function processLimitedSizeGroup(
366 diffLines: DiffLine[],
367 start: number,
368 end: number,
369 maxGroupSize: number,
370 offset: number,
371): DiffGroup {
372 // Calculate the starting line in old content.
373 let oldContentLineStart = countOldContentLines(diffLines, 0, start - 1);
374
375 // Track how many lines we have left in our group size budget.
376 let remainingGroupSize = maxGroupSize;
377 let currentLine = start;
378 const lines: DiffLine[] = [];
379
380 // Process lines until we hit our size limit or reach the end.
381 while (currentLine <= end && remainingGroupSize > 0) {
382 // Add current line to results if we haven't seen it yet.
383 if (
384 lines.length === 0 ||
385 (lines.length > 0 &&
386 lines[lines.length - 1].line !== diffLines[currentLine].line)
387 ) {
388 lines.push(diffLines[currentLine]);
389 }
390
391 if (diffLines[currentLine].type === "old") {
392 currentLine++;
393 } else if (diffLines[currentLine].type === "same") {
394 remainingGroupSize--;
395 currentLine++;
396 } else if (diffLines[currentLine].type === "new") {
397 remainingGroupSize--;
398 currentLine++;
399 }
400 }
401
402 // Adjust for the last increment.
403 currentLine--;
404
405 // Calculate the end line in old content.
406 let oldContentLineEnd =
407 oldContentLineStart +
408 countOldContentLines(diffLines, start, currentLine) -
409 1;
410
411 return {
412 startLine: oldContentLineStart + offset,
413 endLine: oldContentLineEnd + offset,
414 lines,
415 };
416}
417
418/**
419 * Process a changed area with flexible sizing.

Callers 1

groupDiffLinesFunction · 0.85

Calls 2

countOldContentLinesFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected