( action: "accept" | "reject", sidebar: ContinueGUIWebviewViewProvider, ide: VsCodeIde, core: Core, verticalDiffManager: VerticalDiffManager, newFileUri?: string, streamId?: string, toolCallId?: string, )
| 9 | import { VerticalDiffManager } from "./vertical/manager"; |
| 10 | |
| 11 | export async function processDiff( |
| 12 | action: "accept" | "reject", |
| 13 | sidebar: ContinueGUIWebviewViewProvider, |
| 14 | ide: VsCodeIde, |
| 15 | core: Core, |
| 16 | verticalDiffManager: VerticalDiffManager, |
| 17 | newFileUri?: string, |
| 18 | streamId?: string, |
| 19 | toolCallId?: string, |
| 20 | ) { |
| 21 | let newOrCurrentUri = newFileUri; |
| 22 | if (!newOrCurrentUri) { |
| 23 | const currentFile = await ide.getCurrentFile(); |
| 24 | newOrCurrentUri = currentFile?.path; |
| 25 | } |
| 26 | if (!newOrCurrentUri) { |
| 27 | console.warn( |
| 28 | `No file provided or current file open while attempting to resolve diff`, |
| 29 | ); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | await ide.openFile(newOrCurrentUri); |
| 34 | |
| 35 | // If streamId is not provided, try to get it from the VerticalDiffManager |
| 36 | if (!streamId) { |
| 37 | streamId = verticalDiffManager.getStreamIdForFile(newOrCurrentUri); |
| 38 | } |
| 39 | |
| 40 | // Clear vertical diffs depending on action |
| 41 | verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept"); |
| 42 | if (action === "reject") { |
| 43 | // this is so that IDE reject diff command can also cancel apply |
| 44 | core.invoke("cancelApply", undefined); |
| 45 | } |
| 46 | |
| 47 | if (streamId) { |
| 48 | // Capture file content before save to detect autoformatting |
| 49 | const preSaveContent = await ide.readFile(newOrCurrentUri); |
| 50 | |
| 51 | // Record the edit outcome before updating the apply state |
| 52 | await editOutcomeTracker.recordEditOutcome( |
| 53 | streamId, |
| 54 | action === "accept", |
| 55 | DataLogger.getInstance(), |
| 56 | ); |
| 57 | |
| 58 | // Save the file |
| 59 | await ide.saveFile(newOrCurrentUri); |
| 60 | |
| 61 | // Capture file content after save to detect autoformatting |
| 62 | const postSaveContent = await ide.readFile(newOrCurrentUri); |
| 63 | |
| 64 | // Detect autoformatting by comparing normalized content |
| 65 | let autoFormattingDiff: string | undefined; |
| 66 | const normalizedPreSave = preSaveContent.trim(); |
| 67 | const normalizedPostSave = postSaveContent.trim(); |
| 68 |
no test coverage detected