( content: string, offset: number = 0, limit: number = DEFAULT_LINE_LIMIT, )
| 432 | * @returns The extracted content with metadata |
| 433 | */ |
| 434 | export function readWithSlice( |
| 435 | content: string, |
| 436 | offset: number = 0, |
| 437 | limit: number = DEFAULT_LINE_LIMIT, |
| 438 | ): IndentationReadResult { |
| 439 | const lines = parseLines(content) |
| 440 | const totalLines = lines.length |
| 441 | |
| 442 | // Validate offset |
| 443 | if (offset < 0) offset = 0 |
| 444 | if (offset >= totalLines) { |
| 445 | return { |
| 446 | content: `Error: offset ${offset} is beyond file end (${totalLines} lines)`, |
| 447 | includedRanges: [], |
| 448 | totalLines, |
| 449 | returnedLines: 0, |
| 450 | wasTruncated: false, |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // Slice lines |
| 455 | const endIdx = Math.min(offset + limit, totalLines) |
| 456 | const selectedLines = lines.slice(offset, endIdx) |
| 457 | const wasTruncated = endIdx < totalLines |
| 458 | |
| 459 | // Format output |
| 460 | const formattedContent = formatWithLineNumbers(selectedLines) |
| 461 | |
| 462 | return { |
| 463 | content: formattedContent, |
| 464 | includedRanges: [[offset + 1, endIdx]], // 1-based |
| 465 | totalLines, |
| 466 | returnedLines: selectedLines.length, |
| 467 | wasTruncated, |
| 468 | } |
| 469 | } |
no test coverage detected