feat: dont use underlying apply logic

This commit is contained in:
Patrick Erichsen 2025-06-26 18:51:53 -07:00
parent 4d195cea7c
commit 0e7709d85e
3 changed files with 34 additions and 14 deletions

1
core/index.d.ts vendored
View file

@ -1297,6 +1297,7 @@ export interface ApplyToFilePayload {
filepath?: string;
text: string;
toolCallId?: string;
isSearchAndReplace?: boolean;
}
export interface RangeInFileWithContents {

View file

@ -4,6 +4,8 @@ import { getUriPathBasename } from "core/util/uri";
import * as vscode from "vscode";
import { ApplyToFilePayload } from "core";
import { myersDiff } from "core/diff/myers";
import { generateLines } from "core/diff/util";
import { ApplyAbortManager } from "core/edit/applyAbortManager";
import { VerticalDiffManager } from "../diff/vertical/manager";
import { VsCodeIde } from "../VsCodeIde";
@ -25,6 +27,7 @@ export class ApplyManager {
filepath,
text,
toolCallId,
isSearchAndReplace,
}: ApplyToFilePayload) {
await this.webviewProtocol.request("updateApplyState", {
streamId,
@ -43,16 +46,30 @@ export class ApplyManager {
return;
}
// Regular apply logic
const hasExistingDocument = !!activeTextEditor.document.getText().trim();
if (hasExistingDocument) {
await this.handleExistingDocument(
activeTextEditor,
text,
streamId,
toolCallId,
);
// Currently `isSearchAndReplace` will always provide a full file rewrite
// as the contents of `text`, so we can just instantly apply
if (isSearchAndReplace) {
const diffLinesGenerator = generateLines(
myersDiff(activeTextEditor.document.getText(), text),
);
await this.verticalDiffManager.streamDiffLines(
diffLinesGenerator,
true,
streamId,
toolCallId,
);
} else {
await this.handleExistingDocument(
activeTextEditor,
text,
streamId,
toolCallId,
);
}
} else {
await this.handleEmptyDocument(
activeTextEditor,

View file

@ -1,6 +1,7 @@
import { findSearchMatch } from "core/edit/searchAndReplace/findSearchMatch";
import { parseAllSearchReplaceBlocks } from "core/edit/searchAndReplace/parseSearchReplaceBlock";
import { resolveRelativePathInDir } from "core/util/ideUtils";
import { v4 as uuid } from "uuid";
import { ClientToolImpl } from "./callClientTool";
export const searchReplaceToolImpl: ClientToolImpl = async (
@ -10,10 +11,7 @@ export const searchReplaceToolImpl: ClientToolImpl = async (
) => {
const { filepath, diff } = args;
// Check if we have a streamId from a pre-existing apply state
if (!extras.streamId) {
throw new Error("Invalid apply state - no streamId available");
}
const streamId = uuid();
// Resolve the file path
const resolvedFilepath = await resolveRelativePathInDir(
@ -58,11 +56,15 @@ export const searchReplaceToolImpl: ClientToolImpl = async (
}
// Single applyToFile call with all accumulated changes
// This works becaues of our logic in `applyCodeBlock` that determines
// that the full file rewrite here can be applied instantly, so the diff
// lines are just st
await extras.ideMessenger.request("applyToFile", {
text: currentContent,
streamId: extras.streamId,
filepath: resolvedFilepath,
streamId,
toolCallId,
text: currentContent,
filepath: resolvedFilepath,
isSearchAndReplace: true,
});
// Return success - applyToFile will handle the completion state