Spaces:
Running
Running
File size: 1,179 Bytes
c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
export function numberTrace(content: string, maxLineLength = 120): string[] {
// The backend processor (TraceLineNumberProcessor) numbers lines **after**
// splitting any line longer than `maxLineLength` into chunks and indenting
// continuation chunks with two leading spaces. To keep `raw_*_ref` mappings
// consistent, we reproduce that exact behaviour here.
const originalLines = content.split("\n");
const processed: string[] = [];
for (const line of originalLines) {
if (maxLineLength && line.length > maxLineLength) {
const chunks = [] as string[];
for (let i = 0; i < line.length; i += maxLineLength) {
chunks.push(line.slice(i, i + maxLineLength));
}
if (chunks.length) {
// First chunk as-is
processed.push(chunks[0]!);
// Subsequent chunks get two-space indent so downstream logic can treat
// them as "continuation" lines (see isContinuation in the visualizer).
for (const chunk of chunks.slice(1)) {
processed.push(" " + chunk);
}
}
} else {
processed.push(line);
}
}
return processed.map((ln, idx) => `<L${idx + 1}> ${ln}`);
}
|