Skip to content

Commit a1dc1f8

Browse files
committed
change to reject diffs approach rather than cancel apply approach
1 parent 8d8cf36 commit a1dc1f8

File tree

15 files changed

+111
-89
lines changed

15 files changed

+111
-89
lines changed

core/core.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
} from "./config/onboarding";
5454
import { createNewWorkspaceBlockFile } from "./config/workspace/workspaceBlocks";
5555
import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton";
56+
import { ApplyAbortManager } from "./edit/applyAbortManager";
5657
import { streamDiffLines } from "./edit/streamDiffLines";
5758
import { shouldIgnore } from "./indexing/shouldIgnore";
5859
import { walkDirCache } from "./indexing/walkDir";
@@ -61,7 +62,6 @@ import { LLMLogger } from "./llm/logger";
6162
import { llmStreamChat } from "./llm/streamChat";
6263
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
6364
import type { IMessenger, Message } from "./protocol/messenger";
64-
import { StreamAbortManager } from "./util/abortManager";
6565

6666
export class Core {
6767
configHandler: ConfigHandler;
@@ -509,6 +509,11 @@ export class Core {
509509
throw new Error("No model selected");
510510
}
511511

512+
const abortManager = ApplyAbortManager.getInstance();
513+
const abortController = abortManager.get(
514+
data.fileUri ?? "current-file-stream",
515+
); // not super important since currently cancelling apply will cancel all streams it's one file at a time
516+
512517
return streamDiffLines({
513518
highlighted: data.highlighted,
514519
prefix: data.prefix,
@@ -522,13 +527,13 @@ export class Core {
522527
language: data.language,
523528
onlyOneInsertion: false,
524529
overridePrompt: undefined,
525-
abortControllerId: data.fileUri ?? "current-file-stream", // not super important since currently cancelling apply will cancel all streams it's one file at a time
530+
abortController,
526531
});
527532
});
528533

529534
on("cancelApply", async (msg) => {
530-
const abortManager = StreamAbortManager.getInstance();
531-
abortManager.clear();
535+
const abortManager = ApplyAbortManager.getInstance();
536+
abortManager.clear(); // for now abort all streams
532537
});
533538

534539
on("completeOnboarding", this.handleCompleteOnboarding.bind(this));

core/util/abortManager.ts renamed to core/edit/applyAbortManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
export class StreamAbortManager {
2-
private static instance: StreamAbortManager;
1+
export class ApplyAbortManager {
2+
private static instance: ApplyAbortManager;
33
private controllers: Map<string, AbortController>;
44

55
private constructor() {
66
this.controllers = new Map();
77
}
88

9-
public static getInstance(): StreamAbortManager {
10-
if (!StreamAbortManager.instance) {
11-
StreamAbortManager.instance = new StreamAbortManager();
9+
public static getInstance(): ApplyAbortManager {
10+
if (!ApplyAbortManager.instance) {
11+
ApplyAbortManager.instance = new ApplyAbortManager();
1212
}
13-
return StreamAbortManager.instance;
13+
return ApplyAbortManager.instance;
1414
}
1515

1616
public get(id: string): AbortController {

core/edit/recursiveStream.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function* recursiveStream(
6868
});
6969

7070
for await (const chunk of generator) {
71+
console.log(chunk);
7172
yield chunk;
7273
const rendered = renderChatMessage(chunk);
7374
buffer += rendered;

core/edit/streamDiffLines.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { streamDiff } from "../diff/streamDiff";
2020
import { streamLines } from "../diff/util";
2121
import { getSystemMessageWithRules } from "../llm/rules/getSystemMessageWithRules";
2222
import { gptEditPrompt } from "../llm/templates/edit";
23-
import { StreamAbortManager } from "../util/abortManager";
2423
import { findLast } from "../util/findLast";
2524
import { Telemetry } from "../util/posthog";
2625
import { recursiveStream } from "./recursiveStream";
@@ -64,7 +63,7 @@ export async function* streamDiffLines({
6463
highlighted,
6564
suffix,
6665
llm,
67-
abortControllerId,
66+
abortController,
6867
input,
6968
language,
7069
onlyOneInsertion,
@@ -75,15 +74,13 @@ export async function* streamDiffLines({
7574
highlighted: string;
7675
suffix: string;
7776
llm: ILLM;
78-
abortControllerId: string;
77+
abortController: AbortController;
7978
input: string;
8079
language: string | undefined;
8180
onlyOneInsertion: boolean;
8281
overridePrompt: ChatMessage[] | undefined;
8382
rulesToInclude: RuleWithSource[] | undefined;
8483
}): AsyncGenerator<DiffLine> {
85-
const abortManager = StreamAbortManager.getInstance();
86-
const abortController = abortManager.get(abortControllerId);
8784
void Telemetry.capture(
8885
"inlineEdit",
8986
{

core/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ export interface HighlightedCodePayload {
12631263
}
12641264

12651265
export interface AcceptOrRejectDiffPayload {
1266-
filepath: string;
1266+
filepath?: string;
12671267
streamId?: string;
12681268
}
12691269

core/llm/utils/extractPathsFromCodeBlocks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Extracts file paths from markdown code blocks
33
*/
44
export function extractPathsFromCodeBlocks(content: string): string[] {
5-
console.log("CONTENT", content);
6-
75
const paths: string[] = [];
86

97
// Match code block opening patterns:

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ data class StreamDiffLinesPayload(
249249
)
250250

251251
data class AcceptOrRejectDiffPayload(
252-
val filepath: String,
252+
val filepath: String? = null,
253253
val streamId: String? = null
254254
)
255255

extensions/vscode/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/vscode/src/apply/ApplyManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock";
33
import { getUriPathBasename } from "core/util/uri";
44
import * as vscode from "vscode";
55

6-
import { StreamAbortManager } from "core/util/abortManager";
6+
import { ApplyAbortManager } from "core/edit/applyAbortManager";
77
import { VerticalDiffManager } from "../diff/vertical/manager";
88
import { VsCodeIde } from "../VsCodeIde";
99
import { VsCodeWebviewProtocol } from "../webviewProtocol";
@@ -118,7 +118,7 @@ export class ApplyManager {
118118
}
119119

120120
const fileUri = editor.document.uri.toString();
121-
const abortManager = StreamAbortManager.getInstance();
121+
const abortManager = ApplyAbortManager.getInstance();
122122
const abortController = abortManager.get(fileUri);
123123

124124
const { isInstantApply, diffLinesGenerator } = await applyCodeBlock(

extensions/vscode/src/commands.ts

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from "./autocomplete/statusBar";
3636
import { ContinueConsoleWebviewViewProvider } from "./ContinueConsoleWebviewViewProvider";
3737
import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider";
38+
import { processDiff } from "./diff/processDiff";
3839
import { VerticalDiffManager } from "./diff/vertical/manager";
3940
import EditDecorationManager from "./quickEdit/EditDecorationManager";
4041
import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick";
@@ -93,56 +94,6 @@ function hideGUI() {
9394
}
9495
}
9596

96-
async function processDiff(
97-
action: "accept" | "reject",
98-
sidebar: ContinueGUIWebviewViewProvider,
99-
ide: VsCodeIde,
100-
core: Core,
101-
verticalDiffManager: VerticalDiffManager,
102-
newFileUri?: string,
103-
streamId?: string,
104-
toolCallId?: string,
105-
) {
106-
captureCommandTelemetry(`${action}Diff`);
107-
108-
const currentFile = await ide.getCurrentFile();
109-
110-
let newOrCurrentUri = newFileUri;
111-
if (!newOrCurrentUri) {
112-
newOrCurrentUri = currentFile?.path;
113-
}
114-
if (!newOrCurrentUri) {
115-
console.warn(
116-
`No file provided or current file open while attempting to resolve diff`,
117-
);
118-
return;
119-
}
120-
121-
await ide.openFile(newOrCurrentUri);
122-
123-
// Clear vertical diffs depending on action
124-
verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
125-
if (action === "reject") {
126-
core.invoke("cancelApply", undefined);
127-
}
128-
129-
if (streamId) {
130-
const fileContent = await ide.readFile(newOrCurrentUri);
131-
132-
await sidebar.webviewProtocol.request("updateApplyState", {
133-
fileContent,
134-
filepath: newOrCurrentUri,
135-
streamId,
136-
status: "closed",
137-
numDiffs: 0,
138-
toolCallId,
139-
});
140-
}
141-
142-
// Save the file
143-
await ide.saveFile(newOrCurrentUri);
144-
}
145-
14697
function waitForSidebarReady(
14798
sidebar: ContinueGUIWebviewViewProvider,
14899
timeout: number,
@@ -235,27 +186,31 @@ const getCommandsMap: (
235186
}
236187

237188
return {
238-
"continue.acceptDiff": async (newFileUri?: string, streamId?: string) =>
239-
processDiff(
189+
"continue.acceptDiff": async (newFileUri?: string, streamId?: string) => {
190+
captureCommandTelemetry("acceptDiff");
191+
void processDiff(
240192
"accept",
241193
sidebar,
242194
ide,
243195
core,
244196
verticalDiffManager,
245197
newFileUri,
246198
streamId,
247-
),
199+
);
200+
},
248201

249-
"continue.rejectDiff": async (newFileUri?: string, streamId?: string) =>
250-
processDiff(
202+
"continue.rejectDiff": async (newFileUri?: string, streamId?: string) => {
203+
captureCommandTelemetry("rejectDiff");
204+
void processDiff(
251205
"reject",
252206
sidebar,
253207
ide,
254208
core,
255209
verticalDiffManager,
256210
newFileUri,
257211
streamId,
258-
),
212+
);
213+
},
259214
"continue.acceptVerticalDiffBlock": (fileUri?: string, index?: number) => {
260215
captureCommandTelemetry("acceptVerticalDiffBlock");
261216
verticalDiffManager.acceptRejectVerticalDiffBlock(true, fileUri, index);

0 commit comments

Comments
 (0)