MCPcopy Create free account
hub / github.com/block/buzz / getDiffLines

Function getDiffLines

desktop/src/features/agents/ui/agentSessionFileEditDiff.ts:103–142  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

101}
102
103function getDiffLines(text: string): FileEditDiffLine[] {
104 const rawLines = text.split(/\r?\n/);
105 const hasUnifiedDiff = rawLines.some((line) =>
106 /^(diff --git|--- |\+\+\+ |@@)/.test(line),
107 );
108 const lines: FileEditDiffLine[] = [];
109 let inUnifiedDiff = false;
110
111 for (const rawLine of rawLines) {
112 const shikiKind = getShikiDiffKind(rawLine);
113 if (shikiKind) {
114 lines.push({
115 kind: shikiKind,
116 text: rawLine.replace(
117 shikiKind === "add" ? SHIKI_ADD_RE : SHIKI_REMOVE_RE,
118 "",
119 ),
120 });
121 continue;
122 }
123
124 if (hasUnifiedDiff && !inUnifiedDiff) {
125 if (!/^(diff --git|--- |\+\+\+ |@@)/.test(rawLine)) {
126 continue;
127 }
128 inUnifiedDiff = true;
129 }
130
131 if (hasUnifiedDiff) {
132 lines.push(classifyUnifiedDiffLine(rawLine));
133 continue;
134 }
135
136 lines.push({ kind: "context", text: rawLine });
137 }
138
139 return trimTrailingEmptyContextLines(
140 lines.filter((line) => line.text.length > 0 || line.kind !== "meta"),
141 );
142}
143
144function trimTrailingEmptyContextLines(
145 lines: FileEditDiffLine[],

Callers 1

buildFileEditDiffFunction · 0.85

Calls 4

getShikiDiffKindFunction · 0.85
classifyUnifiedDiffLineFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected