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

Method sectionRangesOf

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

Source from the content-addressed store, hash-verified

7086 * window it renders, not as the body it elides.
7087 */
7088 const sectionRangesOf = (c: { start: number; end: number }): ExploreLineRange[] => {
7089 // Plain source for [start, end], except each oversize spine method inside
7090 // it, which renders as its window. Context padding goes on the outer edges
7091 // of PLAIN source only: padding past a windowed method would add lines
7092 // after a tail that was elided.
7093 const spans: Array<{ range: ExploreLineRange; plain: boolean }> = [];
7094 let cursor = c.start;
7095 for (const g of oversizeSpine) {
7096 if (g.start < cursor || g.start < c.start || g.end > c.end) continue;
7097 if (g.start > cursor) spans.push({ range: { start: cursor, end: g.start - 1 }, plain: true });
7098 for (const w of spineWindowOf(g)) spans.push({ range: w, plain: false });
7099 cursor = g.end + 1;
7100 }
7101 if (cursor <= c.end) spans.push({ range: { start: cursor, end: c.end }, plain: true });
7102 const first = spans[0];
7103 const last = spans[spans.length - 1];
7104 if (first?.plain) first.range.start = Math.max(1, first.range.start - contextPadding);
7105 if (last?.plain) last.range.end = Math.min(fileLines.length, last.range.end + contextPadding);
7106 // Spans that touch in the file are one block, not two parts with a gap
7107 // marker between adjacent lines.
7108 const merged: ExploreLineRange[] = [];
7109 for (const { range } of spans) {
7110 const prev = merged[merged.length - 1];
7111 if (prev && range.start <= prev.end + 1) prev.end = Math.max(prev.end, range.end);
7112 else merged.push({ ...range });
7113 }
7114 return merged;
7115 };
7116 const buildSection = (c: { start: number; end: number }): SectionPart[] =>
7117 sectionRangesOf(c).map((r) => ({ range: r, text: renderSpan(r) }));
7118

Callers

nothing calls this directly

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected