MCPcopy Index your code
hub / github.com/anomalyco/opencode / parseUpdateFileChunks

Function parseUpdateFileChunks

packages/opencode/src/patch/index.ts:103–155  ·  view source on GitHub ↗
(lines: string[], startIdx: number)

Source from the content-addressed store, hash-verified

101}
102
103function parseUpdateFileChunks(lines: string[], startIdx: number): { chunks: UpdateFileChunk[]; nextIdx: number } {
104 const chunks: UpdateFileChunk[] = []
105 let i = startIdx
106
107 while (i < lines.length && !lines[i].startsWith("***")) {
108 if (lines[i].startsWith("@@")) {
109 // Parse context line
110 const contextLine = lines[i].substring(2).trim()
111 i++
112
113 const oldLines: string[] = []
114 const newLines: string[] = []
115 let isEndOfFile = false
116
117 // Parse change lines
118 while (i < lines.length && !lines[i].startsWith("@@") && !lines[i].startsWith("***")) {
119 const changeLine = lines[i]
120
121 if (changeLine === "*** End of File") {
122 isEndOfFile = true
123 i++
124 break
125 }
126
127 if (changeLine.startsWith(" ")) {
128 // Keep line - appears in both old and new
129 const content = changeLine.substring(1)
130 oldLines.push(content)
131 newLines.push(content)
132 } else if (changeLine.startsWith("-")) {
133 // Remove line - only in old
134 oldLines.push(changeLine.substring(1))
135 } else if (changeLine.startsWith("+")) {
136 // Add line - only in new
137 newLines.push(changeLine.substring(1))
138 }
139
140 i++
141 }
142
143 chunks.push({
144 old_lines: oldLines,
145 new_lines: newLines,
146 change_context: contextLine || undefined,
147 is_end_of_file: isEndOfFile || undefined,
148 })
149 } else {
150 i++
151 }
152 }
153
154 return { chunks, nextIdx: i }
155}
156
157function parseAddFileContent(lines: string[], startIdx: number): { content: string; nextIdx: number } {
158 let content = ""

Callers 1

parsePatchFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected