MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / sectionRangesOf

Method sectionRangesOf

src/mcp/tools.ts:7066–7093  ·  view source on GitHub ↗
(c: { start: number; end: number })

Source from the content-addressed store, hash-verified

7064 * window it renders, not as the body it elides.
7065 */
7066 const sectionRangesOf = (c: { start: number; end: number }): ExploreLineRange[] => {
7067 // Plain source for [start, end], except each oversize spine method inside
7068 // it, which renders as its window. Context padding goes on the outer edges
7069 // of PLAIN source only: padding past a windowed method would add lines
7070 // after a tail that was elided.
7071 const spans: Array<{ range: ExploreLineRange; plain: boolean }> = [];
7072 let cursor = c.start;
7073 for (const g of oversizeSpine) {
7074 if (g.start < cursor || g.start < c.start || g.end > c.end) continue;
7075 if (g.start > cursor) spans.push({ range: { start: cursor, end: g.start - 1 }, plain: true });
7076 for (const w of spineWindowOf(g)) spans.push({ range: w, plain: false });
7077 cursor = g.end + 1;
7078 }
7079 if (cursor <= c.end) spans.push({ range: { start: cursor, end: c.end }, plain: true });
7080 const first = spans[0];
7081 const last = spans[spans.length - 1];
7082 if (first?.plain) first.range.start = Math.max(1, first.range.start - contextPadding);
7083 if (last?.plain) last.range.end = Math.min(fileLines.length, last.range.end + contextPadding);
7084 // Spans that touch in the file are one block, not two parts with a gap
7085 // marker between adjacent lines.
7086 const merged: ExploreLineRange[] = [];
7087 for (const { range } of spans) {
7088 const prev = merged[merged.length - 1];
7089 if (prev && range.start <= prev.end + 1) prev.end = Math.max(prev.end, range.end);
7090 else merged.push({ ...range });
7091 }
7092 return merged;
7093 };
7094 const buildSection = (c: { start: number; end: number }): SectionPart[] =>
7095 sectionRangesOf(c).map((r) => ({ range: r, text: renderSpan(r) }));
7096

Callers

nothing calls this directly

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected