( beforeContent: string, afterContent: string, filePath: string, contextLines: number, workspaceDir?: string, )
| 46 | }; |
| 47 | |
| 48 | const createUnifiedDiff = ( |
| 49 | beforeContent: string, |
| 50 | afterContent: string, |
| 51 | filePath: string, |
| 52 | contextLines: number, |
| 53 | workspaceDir?: string, |
| 54 | ) => { |
| 55 | const normalizedBefore = beforeContent.endsWith("\n") |
| 56 | ? beforeContent |
| 57 | : beforeContent + "\n"; |
| 58 | const normalizedAfter = afterContent.endsWith("\n") |
| 59 | ? afterContent |
| 60 | : afterContent + "\n"; |
| 61 | |
| 62 | // Use relative path if workspace directory is provided |
| 63 | let displayPath = filePath; |
| 64 | if (workspaceDir && filePath.startsWith(workspaceDir)) { |
| 65 | displayPath = filePath.slice(workspaceDir.length).replace(/^[\/]/, ""); |
| 66 | } else if (workspaceDir) { |
| 67 | // Fallback to just the basename if we can't determine relative path |
| 68 | displayPath = getUriPathBasename(filePath); |
| 69 | } |
| 70 | |
| 71 | const patch = createPatch( |
| 72 | displayPath, |
| 73 | normalizedBefore, |
| 74 | normalizedAfter, |
| 75 | undefined, |
| 76 | undefined, |
| 77 | { context: contextLines }, |
| 78 | ); |
| 79 | |
| 80 | return patch; |
| 81 | }; |
| 82 | |
| 83 | export const createBeforeAfterDiff = ( |
| 84 | beforeContent: string, |
no test coverage detected