Changesets · Branches · Tags · Compare
| Changeset | a368ad8eab5a12da76c63ad935694c934fe85fe0a38fa02cd5855b452b531da0 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-11 10:36 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-11 10:36 -07:00 |
| Parents | b83510677c39, 579705a4fd4b |
4 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
| @@ -1387,6 +1387,7 @@ | ||
| 1387 | 1387 | fileContent?: string; |
| 1388 | 1388 | originalFileContent?: string; |
| 1389 | 1389 | toolCallId?: string; |
| 1390 | + autoFormattingDiff?: string; | |
| 1390 | 1391 | } |
| 1391 | 1392 | |
| 1392 | 1393 | export interface StreamDiffLinesPayload { |
modified extensions/vscode/src/diff/processDiff.ts +38 −5
| @@ -1,8 +1,11 @@ | ||
| 1 | 1 | import { Core } from "core/core"; |
| 2 | 2 | import { DataLogger } from "core/data/log"; |
| 3 | +import { myersDiff } from "core/diff/myers"; | |
| 4 | + | |
| 3 | 5 | import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; |
| 4 | 6 | import { editOutcomeTracker } from "../extension/EditOutcomeTracker"; |
| 5 | 7 | import { VsCodeIde } from "../VsCodeIde"; |
| 8 | + | |
| 6 | 9 | import { VerticalDiffManager } from "./vertical/manager"; |
| 7 | 10 | |
| 8 | 11 | export async function processDiff( |
| @@ -42,7 +45,8 @@ | ||
| 42 | 45 | } |
| 43 | 46 | |
| 44 | 47 | if (streamId) { |
| 45 | - const fileContent = await ide.readFile(newOrCurrentUri); | |
| 48 | + // Capture file content before save to detect autoformatting | |
| 49 | + const preSaveContent = await ide.readFile(newOrCurrentUri); | |
| 46 | 50 | |
| 47 | 51 | // Record the edit outcome before updating the apply state |
| 48 | 52 | await editOutcomeTracker.recordEditOutcome( |
| @@ -51,16 +55,45 @@ | ||
| 51 | 55 | DataLogger.getInstance(), |
| 52 | 56 | ); |
| 53 | 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 | + | |
| 69 | + if (normalizedPreSave !== normalizedPostSave) { | |
| 70 | + // Auto-formatting was applied by the editor | |
| 71 | + const diffLines = myersDiff(preSaveContent, postSaveContent); | |
| 72 | + autoFormattingDiff = diffLines | |
| 73 | + .map((line) => { | |
| 74 | + switch (line.type) { | |
| 75 | + case "old": | |
| 76 | + return `-${line.line}`; | |
| 77 | + case "new": | |
| 78 | + return `+${line.line}`; | |
| 79 | + case "same": | |
| 80 | + return ` ${line.line}`; | |
| 81 | + } | |
| 82 | + }) | |
| 83 | + .join("\n"); | |
| 84 | + } | |
| 85 | + | |
| 54 | 86 | await sidebar.webviewProtocol.request("updateApplyState", { |
| 55 | - fileContent, | |
| 87 | + fileContent: postSaveContent, // Use post-save content | |
| 56 | 88 | filepath: newOrCurrentUri, |
| 57 | 89 | streamId, |
| 58 | 90 | status: "closed", |
| 59 | 91 | numDiffs: 0, |
| 60 | 92 | toolCallId, |
| 93 | + autoFormattingDiff, // Include autoformatting diff | |
| 61 | 94 | }); |
| 95 | + } else { | |
| 96 | + // Save the file even if no streamId | |
| 97 | + await ide.saveFile(newOrCurrentUri); | |
| 62 | 98 | } |
| 63 | - | |
| 64 | - // Save the file | |
| 65 | - await ide.saveFile(newOrCurrentUri); | |
| 66 | 99 | } |
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({ |
| @@ -125,7 +143,6 @@ | ||
| 125 | 143 | ); |
| 126 | 144 | } |
| 127 | 145 | } |
| 128 | - // TODO return output from edit tools so the model knows the result | |
| 129 | 146 | } |
| 130 | 147 | } |
| 131 | 148 | } |