(lines: LineRecord[], maxLineLength: number = MAX_LINE_LENGTH)
| 228 | * Format lines with line numbers, applying truncation to long lines. |
| 229 | */ |
| 230 | export function formatWithLineNumbers(lines: LineRecord[], maxLineLength: number = MAX_LINE_LENGTH): string { |
| 231 | if (lines.length === 0) return "" |
| 232 | const maxLineNumWidth = String(lines[lines.length - 1]?.lineNumber || 1).length |
| 233 | |
| 234 | return lines |
| 235 | .map((line) => { |
| 236 | const lineNum = String(line.lineNumber).padStart(maxLineNumWidth, " ") |
| 237 | let content = line.content |
| 238 | |
| 239 | // Truncate long lines |
| 240 | if (content.length > maxLineLength) { |
| 241 | content = content.substring(0, maxLineLength - 3) + "..." |
| 242 | } |
| 243 | |
| 244 | return `${lineNum} | ${content}` |
| 245 | }) |
| 246 | .join("\n") |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Convert a contiguous array of LineRecords into merged ranges for output. |
no test coverage detected