MCPcopy Create free account
hub / github.com/modem-dev/hunk / buildSplitRows

Function buildSplitRows

src/ui/diff/pierre.ts:772–895  ·  view source on GitHub ↗
(
  file: DiffFile,
  highlighted: HighlightedDiffCode | null,
  theme: AppTheme,
)

Source from the content-addressed store, hash-verified

770
771/** Expand Pierre metadata into the flat split-view row stream consumed by the renderer. */
772export function buildSplitRows(
773 file: DiffFile,
774 highlighted: HighlightedDiffCode | null,
775 theme: AppTheme,
776): DiffRow[] {
777 const rows: DiffRow[] = [];
778 const deletionLines = highlighted?.deletionLines ?? [];
779 const additionLines = highlighted?.additionLines ?? [];
780
781 for (const [hunkIndex, hunk] of file.metadata.hunks.entries()) {
782 if (hunk.collapsedBefore > 0) {
783 rows.push({
784 type: "collapsed",
785 key: `${file.id}:collapsed:${hunkIndex}`,
786 fileId: file.id,
787 hunkIndex,
788 text: collapsedRowText(hunk.collapsedBefore),
789 position: "before",
790 ...leadingCollapsedRanges(hunk),
791 });
792 }
793
794 rows.push({
795 type: "hunk-header",
796 key: `${file.id}:header:${hunkIndex}`,
797 fileId: file.id,
798 hunkIndex,
799 text: formatHunkHeader(hunk),
800 });
801
802 let deletionLineIndex = hunk.deletionLineIndex;
803 let additionLineIndex = hunk.additionLineIndex;
804 let deletionLineNumber = hunk.deletionStart;
805 let additionLineNumber = hunk.additionStart;
806
807 for (const content of hunk.hunkContent) {
808 if (content.type === "context") {
809 for (let offset = 0; offset < content.lines; offset += 1) {
810 rows.push({
811 type: "split-line",
812 key: `${file.id}:split:${hunkIndex}:context:${deletionLineIndex + offset}:${additionLineIndex + offset}`,
813 fileId: file.id,
814 hunkIndex,
815 left: makeSplitCell(
816 "context",
817 deletionLineNumber + offset,
818 file.metadata.deletionLines[deletionLineIndex + offset],
819 deletionLines[deletionLineIndex + offset],
820 theme,
821 ),
822 right: makeSplitCell(
823 "context",
824 additionLineNumber + offset,
825 file.metadata.additionLines[additionLineIndex + offset],
826 additionLines[additionLineIndex + offset],
827 theme,
828 ),
829 });

Callers 8

renderStaticFileFunction · 0.90
buildBaseRowsFunction · 0.90
pierre.test.tsFile · 0.90
HunkDiffBodyFunction · 0.90
measureScenarioFunction · 0.90
memory.tsFile · 0.90

Calls 6

formatHunkHeaderFunction · 0.90
collapsedRowTextFunction · 0.85
leadingCollapsedRangesFunction · 0.85
makeSplitCellFunction · 0.85
trailingCollapsedLinesFunction · 0.85
trailingCollapsedRangesFunction · 0.85

Tested by

no test coverage detected