MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / formatWithLineNumbers

Function formatWithLineNumbers

src/integrations/misc/indentation-reader.ts:230–247  ·  view source on GitHub ↗
(lines: LineRecord[], maxLineLength: number = MAX_LINE_LENGTH)

Source from the content-addressed store, hash-verified

228 * Format lines with line numbers, applying truncation to long lines.
229 */
230export 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.

Callers 3

readWithIndentationFunction · 0.85
readWithSliceFunction · 0.85

Calls 1

StringInterface · 0.50

Tested by

no test coverage detected