Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 52 additions & 28 deletions extensions/vscode/src/diff/processDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,40 @@ import { VsCodeIde } from "../VsCodeIde";

import { VerticalDiffManager } from "./vertical/manager";

export async function processDiff(
async function processSingleFileDiff(
action: "accept" | "reject",
sidebar: ContinueGUIWebviewViewProvider,
ide: VsCodeIde,
core: Core,
verticalDiffManager: VerticalDiffManager,
newFileUri?: string,
fileUri: string,
streamId?: string,
toolCallId?: string,
) {
let newOrCurrentUri = newFileUri;
if (!newOrCurrentUri) {
const currentFile = await ide.getCurrentFile();
newOrCurrentUri = currentFile?.path;
}
if (!newOrCurrentUri) {
console.warn(
`No file provided or current file open while attempting to resolve diff`,
);
return;
}

await ide.openFile(newOrCurrentUri);
await ide.openFile(fileUri);

// If streamId is not provided, try to get it from the VerticalDiffManager
if (!streamId) {
streamId = verticalDiffManager.getStreamIdForFile(newOrCurrentUri);
streamId = verticalDiffManager.getStreamIdForFile(fileUri);
}

// Clear vertical diffs depending on action
verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
if (action === "reject") {
// this is so that IDE reject diff command can also cancel apply
core.invoke("cancelApply", undefined);
}
verticalDiffManager.clearForfileUri(fileUri, action === "accept");

if (streamId) {
// Capture file content before save to detect autoformatting
const preSaveContent = await ide.readFile(newOrCurrentUri);
const preSaveContent = await ide.readFile(fileUri);

// Record the edit outcome before updating the apply state
await editOutcomeTracker.recordEditOutcome(
streamId,
action === "accept",
DataLogger.getInstance(),
);

// Save the file
await ide.saveFile(newOrCurrentUri);
await ide.saveFile(fileUri);

// Capture file content after save to detect autoformatting
const postSaveContent = await ide.readFile(newOrCurrentUri);
const postSaveContent = await ide.readFile(fileUri);

// Detect autoformatting by comparing normalized content
let autoFormattingDiff: string | undefined;
Expand All @@ -85,7 +67,7 @@ export async function processDiff(

await sidebar.webviewProtocol.request("updateApplyState", {
fileContent: postSaveContent, // Use post-save content
filepath: newOrCurrentUri,
filepath: fileUri,
streamId,
status: "closed",
numDiffs: 0,
Expand All @@ -94,6 +76,48 @@ export async function processDiff(
});
} else {
// Save the file even if no streamId
await ide.saveFile(newOrCurrentUri);
await ide.saveFile(fileUri);
}
}

export async function processDiff(
action: "accept" | "reject",
sidebar: ContinueGUIWebviewViewProvider,
ide: VsCodeIde,
core: Core,
verticalDiffManager: VerticalDiffManager,
newFileUri?: string,
streamId?: string,
toolCallId?: string,
) {
if (action === "reject") {
core.invoke("cancelApply", undefined);
}

let fileUriToProcess = newFileUri;

if (!fileUriToProcess) {
const allFilesWithDiffs = verticalDiffManager.getAllFilesWithDiffs();
if (allFilesWithDiffs.length > 0) {
fileUriToProcess = allFilesWithDiffs[0].fileUri;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Multi-diff acceptance is no longer implemented: the code now selects only the first file from getAllFilesWithDiffs and processes a single diff, which contradicts the PR objective to accept multiple diffs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/vscode/src/diff/processDiff.ts, line 102:

<comment>Multi-diff acceptance is no longer implemented: the code now selects only the first file from getAllFilesWithDiffs and processes a single diff, which contradicts the PR objective to accept multiple diffs.</comment>

<file context>
@@ -94,31 +94,30 @@ export async function processDiff(
+  if (!fileUriToProcess) {
+    const allFilesWithDiffs = verticalDiffManager.getAllFilesWithDiffs();
+    if (allFilesWithDiffs.length > 0) {
+      fileUriToProcess = allFilesWithDiffs[0].fileUri;
+      streamId = allFilesWithDiffs[0].streamId;
+    }
</file context>
Fix with Cubic

streamId = allFilesWithDiffs[0].streamId;
}
}

if (!fileUriToProcess) {
console.warn(
`No file provided or current file open while attempting to resolve diff`,
);
return;
}

await processSingleFileDiff(
action,
sidebar,
ide,
verticalDiffManager,
fileUriToProcess,
streamId,
toolCallId,
);
}
25 changes: 20 additions & 5 deletions extensions/vscode/src/diff/vertical/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class VerticalDiffManager {
return this.fileUriToHandler.get(fileUri)?.streamId;
}

getAllFilesWithDiffs(): Array<{
fileUri: string;
streamId: string | undefined;
}> {
return Array.from(this.fileUriToHandler.entries()).map(
([fileUri, handler]) => ({
fileUri,
streamId: handler.streamId,
}),
);
}

// Creates a listener for document changes by user.
private enableDocumentChangeListener(): vscode.Disposable | undefined {
if (this.userChangeListener) {
Expand Down Expand Up @@ -144,16 +156,19 @@ export class VerticalDiffManager {

this.disableDocumentChangeListener();

const hasRemainingDiffs = this.fileUriToHandler.size > 0;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The global document change listener is always disposed in clearForfileUri even when other file diffs remain, so multi-file diff tracking stops for remaining files. The listener should only be disabled when no diffs remain.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/vscode/src/diff/vertical/manager.ts, line 159:

<comment>The global document change listener is always disposed in clearForfileUri even when other file diffs remain, so multi-file diff tracking stops for remaining files. The listener should only be disabled when no diffs remain.</comment>

<file context>
@@ -156,16 +156,19 @@ export class VerticalDiffManager {
 
     this.disableDocumentChangeListener();
 
+    const hasRemainingDiffs = this.fileUriToHandler.size > 0;
     void vscode.commands.executeCommand(
       "setContext",
</file context>
Fix with Cubic

void vscode.commands.executeCommand(
"setContext",
"continue.diffVisible",
false,
hasRemainingDiffs,
);

void this.webviewProtocol.request(
"focusContinueInputWithoutClear",
undefined,
);
if (!hasRemainingDiffs) {
void this.webviewProtocol.request(
"focusContinueInputWithoutClear",
undefined,
);
}
}

async acceptRejectVerticalDiffBlock(
Expand Down
Loading