| 381 | } |
| 382 | |
| 383 | function constructDiffFromReplacements( |
| 384 | replacements: ReplacementInput[], |
| 385 | ): string { |
| 386 | const lines: string[] = [] |
| 387 | |
| 388 | for (const replacement of replacements) { |
| 389 | const oldString = replacement.oldString ?? replacement.old ?? '' |
| 390 | const newString = replacement.newString ?? replacement.new ?? '' |
| 391 | |
| 392 | // Add old lines as removals |
| 393 | const oldLines = oldString.split('\n') |
| 394 | for (const line of oldLines) { |
| 395 | lines.push(`- ${line}`) |
| 396 | } |
| 397 | // Add new lines as additions |
| 398 | const newLines = newString.split('\n') |
| 399 | for (const line of newLines) { |
| 400 | lines.push(`+ ${line}`) |
| 401 | } |
| 402 | // Add separator between replacements if there are multiple |
| 403 | if (replacements.length > 1) { |
| 404 | lines.push('') |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return lines.join('\n') |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Construct a diff view from write_file content. |