| 1 | import { myersDiff } from "core/diff/myers"; |
| 2 | |
| 3 | /** |
| 4 | * Creates a pretty patch diff string similar to unified diff format |
| 5 | * Uses Continue's existing myersDiff function for diff calculation |
| 6 | */ |
| 7 | export function createPrettyPatch( |
| 8 | filename: string = "file", |
| 9 | oldStr: string = "", |
| 10 | newStr: string = "", |
| 11 | ): string { |
| 12 | if (oldStr === newStr) { |
| 13 | return ""; |
| 14 | } |
| 15 | |
| 16 | const diffLines = myersDiff(oldStr, newStr); |
| 17 | const patchLines: string[] = []; |
| 18 | |
| 19 | for (const diffLine of diffLines) { |
| 20 | switch (diffLine.type) { |
| 21 | case "old": |
| 22 | patchLines.push(`-${diffLine.line}`); |
| 23 | break; |
| 24 | case "new": |
| 25 | patchLines.push(`+${diffLine.line}`); |
| 26 | break; |
| 27 | case "same": |
| 28 | patchLines.push(` ${diffLine.line}`); |
| 29 | break; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return patchLines.join("\n"); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Normalizes content by trimming whitespace for comparison |
| 38 | */ |
| 39 | export function normalizeContent(content: string): string { |
| 40 | return content.trim(); |
| 41 | } |