Changesets · Branches · Tags · Compare
| Changeset | 9c134d8c1202e7aa8d2bee46f77b25bd2ee2d36bb495ca1ff0ea95ce76d3b44d |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-09-09 11:11 -07:00 |
| Committer | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-09-09 11:11 -07:00 |
| Parents | 825624809c09 |
5 files changed
modified core/config/types.ts +1 −0
| @@ -1061,6 +1061,7 @@ | ||
| 1061 | 1061 | filepath?: string; |
| 1062 | 1062 | fileContent?: string; |
| 1063 | 1063 | originalFileContent?: string; |
| 1064 | + autoFormattingDiff?: string; | |
| 1064 | 1065 | } |
| 1065 | 1066 | |
| 1066 | 1067 | export interface RangeInFileWithContents { |
modified core/index.d.ts +1 −0
| @@ -1382,6 +1382,7 @@ | ||
| 1382 | 1382 | fileContent?: string; |
| 1383 | 1383 | originalFileContent?: string; |
| 1384 | 1384 | toolCallId?: string; |
| 1385 | + autoFormattingDiff?: string; | |
| 1385 | 1386 | } |
| 1386 | 1387 | |
| 1387 | 1388 | export interface StreamDiffLinesPayload { |
modified extensions/vscode/src/diff/processDiff.ts +29 −5
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | import { Core } from "core/core"; |
| 2 | 2 | import { DataLogger } from "core/data/log"; |
| 3 | + | |
| 3 | 4 | import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; |
| 4 | 5 | import { editOutcomeTracker } from "../extension/EditOutcomeTracker"; |
| 6 | +import { createPrettyPatch, normalizeContent } from "../util/diffUtils"; | |
| 5 | 7 | import { VsCodeIde } from "../VsCodeIde"; |
| 6 | 8 | import { VerticalDiffManager } from "./vertical/manager"; |
| 7 | 9 | |
| @@ -42,7 +44,8 @@ | ||
| 42 | 44 | } |
| 43 | 45 | |
| 44 | 46 | if (streamId) { |
| 45 | - const fileContent = await ide.readFile(newOrCurrentUri); | |
| 47 | + // Capture file content before save to detect autoformatting | |
| 48 | + const preSaveContent = await ide.readFile(newOrCurrentUri); | |
| 46 | 49 | |
| 47 | 50 | // Record the edit outcome before updating the apply state |
| 48 | 51 | await editOutcomeTracker.recordEditOutcome( |
| @@ -51,16 +54,37 @@ | ||
| 51 | 54 | DataLogger.getInstance(), |
| 52 | 55 | ); |
| 53 | 56 | |
| 57 | + // Save the file | |
| 58 | + await ide.saveFile(newOrCurrentUri); | |
| 59 | + | |
| 60 | + // Capture file content after save to detect autoformatting | |
| 61 | + const postSaveContent = await ide.readFile(newOrCurrentUri); | |
| 62 | + | |
| 63 | + // Detect autoformatting by comparing normalized content | |
| 64 | + let autoFormattingDiff: string | undefined; | |
| 65 | + const normalizedPreSave = normalizeContent(preSaveContent); | |
| 66 | + const normalizedPostSave = normalizeContent(postSaveContent); | |
| 67 | + | |
| 68 | + if (normalizedPreSave !== normalizedPostSave) { | |
| 69 | + // Auto-formatting was applied by the editor | |
| 70 | + autoFormattingDiff = createPrettyPatch( | |
| 71 | + newOrCurrentUri, | |
| 72 | + preSaveContent, | |
| 73 | + postSaveContent, | |
| 74 | + ); | |
| 75 | + } | |
| 76 | + | |
| 54 | 77 | await sidebar.webviewProtocol.request("updateApplyState", { |
| 55 | - fileContent, | |
| 78 | + fileContent: postSaveContent, // Use post-save content | |
| 56 | 79 | filepath: newOrCurrentUri, |
| 57 | 80 | streamId, |
| 58 | 81 | status: "closed", |
| 59 | 82 | numDiffs: 0, |
| 60 | 83 | toolCallId, |
| 84 | + autoFormattingDiff, // Include autoformatting diff | |
| 61 | 85 | }); |
| 86 | + } else { | |
| 87 | + // Save the file even if no streamId | |
| 88 | + await ide.saveFile(newOrCurrentUri); | |
| 62 | 89 | } |
| 63 | - | |
| 64 | - // Save the file | |
| 65 | - await ide.saveFile(newOrCurrentUri); | |
| 66 | 90 | } |
added extensions/vscode/src/util/diffUtils.ts +41 −0
| @@ -0,0 +1,41 @@ | ||
| 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 | +} | |
| No newline at the end of the file |
modified gui/src/redux/thunks/handleApplyStateUpdate.ts +18 −1
| @@ -83,6 +83,24 @@ | ||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | if (accepted) { |
| 86 | + // Add autoformatting diff to tool output if present | |
| 87 | + if (applyState.autoFormattingDiff) { | |
| 88 | + dispatch( | |
| 89 | + updateToolCallOutput({ | |
| 90 | + toolCallId: applyState.toolCallId, | |
| 91 | + contextItems: [ | |
| 92 | + { | |
| 93 | + icon: "info", | |
| 94 | + name: "Auto-formatting Applied", | |
| 95 | + description: "Editor auto-formatting changes", | |
| 96 | + content: `Along with your edits, the editor applied the following auto-formatting:\n\n${applyState.autoFormattingDiff}\n\n(Note: Pay close attention to changes such as single quotes being converted to double quotes, semicolons being removed or added, long lines being broken into multiple lines, adjusting indentation style, adding/removing trailing commas, etc. This will help you ensure future SEARCH/REPLACE operations to this file are accurate.)`, | |
| 97 | + hidden: false, | |
| 98 | + }, | |
| 99 | + ], | |
| 100 | + }), | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + | |
| 86 | 104 | if (toolCallState.status !== "errored") { |
| 87 | 105 | dispatch( |
| 88 | 106 | acceptToolCall({ |
| @@ -98,7 +116,6 @@ | ||
| 98 | 116 | ); |
| 99 | 117 | } |
| 100 | 118 | } |
| 101 | - // TODO return output from edit tools so the model knows the result | |
| 102 | 119 | } |
| 103 | 120 | } |
| 104 | 121 | } |