| 7008 | * window it renders, not as the body it elides. |
| 7009 | */ |
| 7010 | const sectionRangesOf = (c: { start: number; end: number }): ExploreLineRange[] => { |
| 7011 | // Plain source for [start, end], except each oversize spine method inside |
| 7012 | // it, which renders as its window. Context padding goes on the outer edges |
| 7013 | // of PLAIN source only: padding past a windowed method would add lines |
| 7014 | // after a tail that was elided. |
| 7015 | const spans: Array<{ range: ExploreLineRange; plain: boolean }> = []; |
| 7016 | let cursor = c.start; |
| 7017 | for (const g of oversizeSpine) { |
| 7018 | if (g.start < cursor || g.start < c.start || g.end > c.end) continue; |
| 7019 | if (g.start > cursor) spans.push({ range: { start: cursor, end: g.start - 1 }, plain: true }); |
| 7020 | for (const w of spineWindowOf(g)) spans.push({ range: w, plain: false }); |
| 7021 | cursor = g.end + 1; |
| 7022 | } |
| 7023 | if (cursor <= c.end) spans.push({ range: { start: cursor, end: c.end }, plain: true }); |
| 7024 | const first = spans[0]; |
| 7025 | const last = spans[spans.length - 1]; |
| 7026 | if (first?.plain) first.range.start = Math.max(1, first.range.start - contextPadding); |
| 7027 | if (last?.plain) last.range.end = Math.min(fileLines.length, last.range.end + contextPadding); |
| 7028 | // Spans that touch in the file are one block, not two parts with a gap |
| 7029 | // marker between adjacent lines. |
| 7030 | const merged: ExploreLineRange[] = []; |
| 7031 | for (const { range } of spans) { |
| 7032 | const prev = merged[merged.length - 1]; |
| 7033 | if (prev && range.start <= prev.end + 1) prev.end = Math.max(prev.end, range.end); |
| 7034 | else merged.push({ ...range }); |
| 7035 | } |
| 7036 | return merged; |
| 7037 | }; |
| 7038 | const buildSection = (c: { start: number; end: number }): SectionPart[] => |
| 7039 | sectionRangesOf(c).map((r) => ({ range: r, text: renderSpan(r) })); |
| 7040 | |