Changesets · Branches · Tags · Compare
| Changeset | bdaaa3ef81c40dd8ab364230f708629a423624a93f44123e968261e75bbd0090 |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-26 18:51 -07:00 |
| Committer | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-26 18:51 -07:00 |
| Parents | 097f2f6b8351 |
3 files changed
modified core/index.d.ts +1 −0
| @@ -1297,6 +1297,7 @@ | ||
| 1297 | 1297 | filepath?: string; |
| 1298 | 1298 | text: string; |
| 1299 | 1299 | toolCallId?: string; |
| 1300 | + isSearchAndReplace?: boolean; | |
| 1300 | 1301 | } |
| 1301 | 1302 | |
| 1302 | 1303 | export interface RangeInFileWithContents { |
modified extensions/vscode/src/apply/ApplyManager.ts +24 −7
| @@ -4,6 +4,8 @@ | ||
| 4 | 4 | import * as vscode from "vscode"; |
| 5 | 5 | |
| 6 | 6 | import { ApplyToFilePayload } from "core"; |
| 7 | +import { myersDiff } from "core/diff/myers"; | |
| 8 | +import { generateLines } from "core/diff/util"; | |
| 7 | 9 | import { ApplyAbortManager } from "core/edit/applyAbortManager"; |
| 8 | 10 | import { VerticalDiffManager } from "../diff/vertical/manager"; |
| 9 | 11 | import { VsCodeIde } from "../VsCodeIde"; |
| @@ -25,6 +27,7 @@ | ||
| 25 | 27 | filepath, |
| 26 | 28 | text, |
| 27 | 29 | toolCallId, |
| 30 | + isSearchAndReplace, | |
| 28 | 31 | }: ApplyToFilePayload) { |
| 29 | 32 | await this.webviewProtocol.request("updateApplyState", { |
| 30 | 33 | streamId, |
| @@ -43,16 +46,30 @@ | ||
| 43 | 46 | return; |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | - // Regular apply logic | |
| 47 | 49 | const hasExistingDocument = !!activeTextEditor.document.getText().trim(); |
| 48 | 50 | |
| 49 | 51 | if (hasExistingDocument) { |
| 50 | - await this.handleExistingDocument( | |
| 51 | - activeTextEditor, | |
| 52 | - text, | |
| 53 | - streamId, | |
| 54 | - toolCallId, | |
| 55 | - ); | |
| 52 | + // Currently `isSearchAndReplace` will always provide a full file rewrite | |
| 53 | + // as the contents of `text`, so we can just instantly apply | |
| 54 | + if (isSearchAndReplace) { | |
| 55 | + const diffLinesGenerator = generateLines( | |
| 56 | + myersDiff(activeTextEditor.document.getText(), text), | |
| 57 | + ); | |
| 58 | + | |
| 59 | + await this.verticalDiffManager.streamDiffLines( | |
| 60 | + diffLinesGenerator, | |
| 61 | + true, | |
| 62 | + streamId, | |
| 63 | + toolCallId, | |
| 64 | + ); | |
| 65 | + } else { | |
| 66 | + await this.handleExistingDocument( | |
| 67 | + activeTextEditor, | |
| 68 | + text, | |
| 69 | + streamId, | |
| 70 | + toolCallId, | |
| 71 | + ); | |
| 72 | + } | |
| 56 | 73 | } else { |
| 57 | 74 | await this.handleEmptyDocument( |
| 58 | 75 | activeTextEditor, |
modified gui/src/util/clientTools/searchReplaceImpl.ts +8 −6
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { findSearchMatch } from "core/edit/searchAndReplace/findSearchMatch"; |
| 2 | 2 | import { parseAllSearchReplaceBlocks } from "core/edit/searchAndReplace/parseSearchReplaceBlock"; |
| 3 | 3 | import { resolveRelativePathInDir } from "core/util/ideUtils"; |
| 4 | +import { v4 as uuid } from "uuid"; | |
| 4 | 5 | import { ClientToolImpl } from "./callClientTool"; |
| 5 | 6 | |
| 6 | 7 | export const searchReplaceToolImpl: ClientToolImpl = async ( |
| @@ -10,10 +11,7 @@ | ||
| 10 | 11 | ) => { |
| 11 | 12 | const { filepath, diff } = args; |
| 12 | 13 | |
| 13 | - // Check if we have a streamId from a pre-existing apply state | |
| 14 | - if (!extras.streamId) { | |
| 15 | - throw new Error("Invalid apply state - no streamId available"); | |
| 16 | - } | |
| 14 | + const streamId = uuid(); | |
| 17 | 15 | |
| 18 | 16 | // Resolve the file path |
| 19 | 17 | const resolvedFilepath = await resolveRelativePathInDir( |
| @@ -58,11 +56,15 @@ | ||
| 58 | 56 | } |
| 59 | 57 | |
| 60 | 58 | // Single applyToFile call with all accumulated changes |
| 59 | + // This works becaues of our logic in `applyCodeBlock` that determines | |
| 60 | + // that the full file rewrite here can be applied instantly, so the diff | |
| 61 | + // lines are just st | |
| 61 | 62 | await extras.ideMessenger.request("applyToFile", { |
| 63 | + streamId, | |
| 64 | + toolCallId, | |
| 62 | 65 | text: currentContent, |
| 63 | - streamId: extras.streamId, | |
| 64 | 66 | filepath: resolvedFilepath, |
| 65 | - toolCallId, | |
| 67 | + isSearchAndReplace: true, | |
| 66 | 68 | }); |
| 67 | 69 | |
| 68 | 70 | // Return success - applyToFile will handle the completion state |