Elffuss BraidHub

kikocis/continue public

dd35e28818ae · 1.9 KiBRawPermalink
1import { Core } from "core/core";
2import { DataLogger } from "core/data/log";
3import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
4import { editOutcomeTracker } from "../extension/EditOutcomeTracker";
5import { VsCodeIde } from "../VsCodeIde";
6import { VerticalDiffManager } from "./vertical/manager";
7
8export async function processDiff(
9 action: "accept" | "reject",
10 sidebar: ContinueGUIWebviewViewProvider,
11 ide: VsCodeIde,
12 core: Core,
13 verticalDiffManager: VerticalDiffManager,
14 newFileUri?: string,
15 streamId?: string,
16 toolCallId?: string,
17) {
18 let newOrCurrentUri = newFileUri;
19 if (!newOrCurrentUri) {
20 const currentFile = await ide.getCurrentFile();
21 newOrCurrentUri = currentFile?.path;
22 }
23 if (!newOrCurrentUri) {
24 console.warn(
25 `No file provided or current file open while attempting to resolve diff`,
26 );
27 return;
28 }
29
30 await ide.openFile(newOrCurrentUri);
31
32 // If streamId is not provided, try to get it from the VerticalDiffManager
33 if (!streamId) {
34 streamId = verticalDiffManager.getStreamIdForFile(newOrCurrentUri);
35 }
36
37 // Clear vertical diffs depending on action
38 verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
39 if (action === "reject") {
40 // this is so that IDE reject diff command can also cancel apply
41 core.invoke("cancelApply", undefined);
42 }
43
44 if (streamId) {
45 const fileContent = await ide.readFile(newOrCurrentUri);
46
47 // Record the edit outcome before updating the apply state
48 await editOutcomeTracker.recordEditOutcome(
49 streamId,
50 action === "accept",
51 DataLogger.getInstance(),
52 );
53
54 await sidebar.webviewProtocol.request("updateApplyState", {
55 fileContent,
56 filepath: newOrCurrentUri,
57 streamId,
58 status: "closed",
59 numDiffs: 0,
60 toolCallId,
61 });
62 }
63
64 // Save the file
65 await ide.saveFile(newOrCurrentUri);
66}