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

Function buildStackRows

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

Source from the content-addressed store, hash-verified

896
897/** Expand Pierre metadata into the flat stack-view row stream consumed by the renderer. */
898export function buildStackRows(
899 file: DiffFile,
900 highlighted: HighlightedDiffCode | null,
901 theme: AppTheme,
902): DiffRow[] {
903 const rows: DiffRow[] = [];
904 const deletionLines = highlighted?.deletionLines ?? [];
905 const additionLines = highlighted?.additionLines ?? [];
906
907 for (const [hunkIndex, hunk] of file.metadata.hunks.entries()) {
908 if (hunk.collapsedBefore > 0) {
909 rows.push({
910 type: "collapsed",
911 key: `${file.id}:stack:collapsed:${hunkIndex}`,
912 fileId: file.id,
913 hunkIndex,
914 text: collapsedRowText(hunk.collapsedBefore),
915 position: "before",
916 ...leadingCollapsedRanges(hunk),
917 });
918 }
919
920 rows.push({
921 type: "hunk-header",
922 key: `${file.id}:stack:header:${hunkIndex}`,
923 fileId: file.id,
924 hunkIndex,
925 text: formatHunkHeader(hunk),
926 });
927
928 let deletionLineIndex = hunk.deletionLineIndex;
929 let additionLineIndex = hunk.additionLineIndex;
930 let deletionLineNumber = hunk.deletionStart;
931 let additionLineNumber = hunk.additionStart;
932
933 for (const content of hunk.hunkContent) {
934 if (content.type === "context") {
935 for (let offset = 0; offset < content.lines; offset += 1) {
936 rows.push({
937 type: "stack-line",
938 key: `${file.id}:stack:${hunkIndex}:context:${deletionLineIndex + offset}:${additionLineIndex + offset}`,
939 fileId: file.id,
940 hunkIndex,
941 cell: makeStackCell(
942 "context",
943 deletionLineNumber + offset,
944 additionLineNumber + offset,
945 file.metadata.additionLines[additionLineIndex + offset],
946 additionLines[additionLineIndex + offset],
947 theme,
948 ),
949 });
950 }
951
952 deletionLineIndex += content.lines;
953 additionLineIndex += content.lines;
954 deletionLineNumber += content.lines;
955 additionLineNumber += content.lines;

Callers 6

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

Calls 6

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

Tested by

no test coverage detected