Elffuss BraidHub

kikocis/continue public

2b258fb0da42 · 1.4 KiBRawPermalink
1import { Core } from "core/core";
2import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
3import { VsCodeIde } from "../VsCodeIde";
4import { VerticalDiffManager } from "./vertical/manager";
5
6export async function processDiff(
7 action: "accept" | "reject",
8 sidebar: ContinueGUIWebviewViewProvider,
9 ide: VsCodeIde,
10 core: Core,
11 verticalDiffManager: VerticalDiffManager,
12 newFileUri?: string,
13 streamId?: string,
14 toolCallId?: string,
15) {
16 let newOrCurrentUri = newFileUri;
17 if (!newOrCurrentUri) {
18 const currentFile = await ide.getCurrentFile();
19 newOrCurrentUri = currentFile?.path;
20 }
21 if (!newOrCurrentUri) {
22 console.warn(
23 `No file provided or current file open while attempting to resolve diff`,
24 );
25 return;
26 }
27
28 await ide.openFile(newOrCurrentUri);
29
30 // Clear vertical diffs depending on action
31 verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
32 if (action === "reject") {
33 // this is so that IDE reject diff command can also cancel apply
34 core.invoke("cancelApply", undefined);
35 }
36
37 if (streamId) {
38 const fileContent = await ide.readFile(newOrCurrentUri);
39
40 await sidebar.webviewProtocol.request("updateApplyState", {
41 fileContent,
42 filepath: newOrCurrentUri,
43 streamId,
44 status: "closed",
45 numDiffs: 0,
46 toolCallId,
47 });
48 }
49
50 // Save the file
51 await ide.saveFile(newOrCurrentUri);
52}