Elffuss BraidHub

kikocis/continue public

feat: dont use underlying apply logic
Changesetbdaaa3ef81c40dd8ab364230f708629a423624a93f44123e968261e75bbd0090
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-26 18:51 -07:00
CommitterPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-26 18:51 -07:00
Parents097f2f6b8351

Browse the files at this changeset

3 files changed

modified core/index.d.ts +1 −0
@@ -1297,6 +1297,7 @@
12971297 filepath?: string;
12981298 text: string;
12991299 toolCallId?: string;
1300+ isSearchAndReplace?: boolean;
13001301 }
13011302
13021303 export interface RangeInFileWithContents {
modified extensions/vscode/src/apply/ApplyManager.ts +24 −7
@@ -4,6 +4,8 @@
44 import * as vscode from "vscode";
55
66 import { ApplyToFilePayload } from "core";
7+import { myersDiff } from "core/diff/myers";
8+import { generateLines } from "core/diff/util";
79 import { ApplyAbortManager } from "core/edit/applyAbortManager";
810 import { VerticalDiffManager } from "../diff/vertical/manager";
911 import { VsCodeIde } from "../VsCodeIde";
@@ -25,6 +27,7 @@
2527 filepath,
2628 text,
2729 toolCallId,
30+ isSearchAndReplace,
2831 }: ApplyToFilePayload) {
2932 await this.webviewProtocol.request("updateApplyState", {
3033 streamId,
@@ -43,16 +46,30 @@
4346 return;
4447 }
4548
46- // Regular apply logic
4749 const hasExistingDocument = !!activeTextEditor.document.getText().trim();
4850
4951 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+ }
5673 } else {
5774 await this.handleEmptyDocument(
5875 activeTextEditor,
modified gui/src/util/clientTools/searchReplaceImpl.ts +8 −6
@@ -1,6 +1,7 @@
11 import { findSearchMatch } from "core/edit/searchAndReplace/findSearchMatch";
22 import { parseAllSearchReplaceBlocks } from "core/edit/searchAndReplace/parseSearchReplaceBlock";
33 import { resolveRelativePathInDir } from "core/util/ideUtils";
4+import { v4 as uuid } from "uuid";
45 import { ClientToolImpl } from "./callClientTool";
56
67 export const searchReplaceToolImpl: ClientToolImpl = async (
@@ -10,10 +11,7 @@
1011 ) => {
1112 const { filepath, diff } = args;
1213
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();
1715
1816 // Resolve the file path
1917 const resolvedFilepath = await resolveRelativePathInDir(
@@ -58,11 +56,15 @@
5856 }
5957
6058 // 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
6162 await extras.ideMessenger.request("applyToFile", {
63+ streamId,
64+ toolCallId,
6265 text: currentContent,
63- streamId: extras.streamId,
6466 filepath: resolvedFilepath,
65- toolCallId,
67+ isSearchAndReplace: true,
6668 });
6769
6870 // Return success - applyToFile will handle the completion state