MCPcopy
hub / github.com/continuedev/continue / processDiff

Function processDiff

extensions/vscode/src/diff/processDiff.ts:11–99  ·  view source on GitHub ↗
(
  action: "accept" | "reject",
  sidebar: ContinueGUIWebviewViewProvider,
  ide: VsCodeIde,
  core: Core,
  verticalDiffManager: VerticalDiffManager,
  newFileUri?: string,
  streamId?: string,
  toolCallId?: string,
)

Source from the content-addressed store, hash-verified

9import { VerticalDiffManager } from "./vertical/manager";
10
11export async function processDiff(
12 action: "accept" | "reject",
13 sidebar: ContinueGUIWebviewViewProvider,
14 ide: VsCodeIde,
15 core: Core,
16 verticalDiffManager: VerticalDiffManager,
17 newFileUri?: string,
18 streamId?: string,
19 toolCallId?: string,
20) {
21 let newOrCurrentUri = newFileUri;
22 if (!newOrCurrentUri) {
23 const currentFile = await ide.getCurrentFile();
24 newOrCurrentUri = currentFile?.path;
25 }
26 if (!newOrCurrentUri) {
27 console.warn(
28 `No file provided or current file open while attempting to resolve diff`,
29 );
30 return;
31 }
32
33 await ide.openFile(newOrCurrentUri);
34
35 // If streamId is not provided, try to get it from the VerticalDiffManager
36 if (!streamId) {
37 streamId = verticalDiffManager.getStreamIdForFile(newOrCurrentUri);
38 }
39
40 // Clear vertical diffs depending on action
41 verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
42 if (action === "reject") {
43 // this is so that IDE reject diff command can also cancel apply
44 core.invoke("cancelApply", undefined);
45 }
46
47 if (streamId) {
48 // Capture file content before save to detect autoformatting
49 const preSaveContent = await ide.readFile(newOrCurrentUri);
50
51 // Record the edit outcome before updating the apply state
52 await editOutcomeTracker.recordEditOutcome(
53 streamId,
54 action === "accept",
55 DataLogger.getInstance(),
56 );
57
58 // Save the file
59 await ide.saveFile(newOrCurrentUri);
60
61 // Capture file content after save to detect autoformatting
62 const postSaveContent = await ide.readFile(newOrCurrentUri);
63
64 // Detect autoformatting by comparing normalized content
65 let autoFormattingDiff: string | undefined;
66 const normalizedPreSave = preSaveContent.trim();
67 const normalizedPostSave = postSaveContent.trim();
68

Callers 1

getCommandsMapFunction · 0.90

Calls 12

myersDiffFunction · 0.90
warnMethod · 0.80
getStreamIdForFileMethod · 0.80
clearForfileUriMethod · 0.80
recordEditOutcomeMethod · 0.80
getCurrentFileMethod · 0.65
openFileMethod · 0.65
invokeMethod · 0.65
readFileMethod · 0.65
saveFileMethod · 0.65
requestMethod · 0.65
getInstanceMethod · 0.45

Tested by

no test coverage detected