MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / computeEditsFromContents

Function computeEditsFromContents

src/hooks/useDiffInIDE.ts:170–200  ·  view source on GitHub ↗
(
  filePath: string,
  oldContent: string,
  newContent: string,
  editMode: 'single' | 'multiple',
)

Source from the content-addressed store, hash-verified

168 * to apply any edits the user may have made to the new contents.
169 */
170export function computeEditsFromContents(
171 filePath: string,
172 oldContent: string,
173 newContent: string,
174 editMode: 'single' | 'multiple',
175): FileEdit[] {
176 // Use unformatted patches, otherwise the edits will be formatted.
177 const singleHunk = editMode === 'single'
178 const patch = getPatchFromContents({
179 filePath,
180 oldContent,
181 newContent,
182 singleHunk,
183 })
184
185 if (patch.length === 0) {
186 return []
187 }
188
189 // For single edit mode, verify we only got one hunk
190 if (singleHunk && patch.length > 1) {
191 logError(
192 new Error(
193 `Unexpected number of hunks: ${patch.length}. Expected 1 hunk.`,
194 ),
195 )
196 }
197
198 // Re-compute the edits to match the patch
199 return getEditsForPatch(patch)
200}
201
202/**
203 * Done if:

Callers 1

showDiffFunction · 0.85

Calls 3

getPatchFromContentsFunction · 0.85
getEditsForPatchFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected