Skip to content

Commit f21392b

Browse files
authored
Stop progressive text edits when overall operation is done (or cancelled). Only undo unwanted changes after that. (microsoft#196558)
fixes microsoft/vscode-copilot#2296
1 parent 500e680 commit f21392b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ export class InlineChatController implements IEditorContribution {
553553
const markdownContents = new MarkdownString('', { supportThemeIcons: true, supportHtml: true, isTrusted: false });
554554

555555
const progressiveEditsAvgDuration = new MovingAverage();
556+
const progressiveEditsCts = new CancellationTokenSource(requestCts.token);
556557
const progressiveEditsClock = StopWatch.create();
557558
const progressiveEditsQueue = new Queue();
558559
let round = 0;
@@ -574,10 +575,11 @@ export class InlineChatController implements IEditorContribution {
574575
this._zone.value.widget.updateSlashCommandUsed(data.slashCommand);
575576
}
576577
}
577-
if (data.edits) {
578+
if (data.edits?.length) {
578579
if (!request.live) {
579580
throw new Error('Progress in NOT supported in non-live mode');
580581
}
582+
console.log(JSON.stringify(data.edits, undefined, 2));
581583
progressEdits.push(data.edits);
582584
progressiveEditsAvgDuration.update(progressiveEditsClock.elapsed());
583585
progressiveEditsClock.reset();
@@ -588,7 +590,7 @@ export class InlineChatController implements IEditorContribution {
588590
// become infinitely fast
589591
await this._makeChanges(data.edits!, data.editsShouldBeInstant
590592
? undefined
591-
: { duration: progressiveEditsAvgDuration.value, round: round++, token: requestCts.token }
593+
: { duration: progressiveEditsAvgDuration.value, round: round++, token: progressiveEditsCts.token }
592594
);
593595
this._showWidget(false);
594596
});
@@ -638,14 +640,15 @@ export class InlineChatController implements IEditorContribution {
638640
this._log('request took', requestClock.elapsed(), this._activeSession.provider.debugName);
639641
}
640642

641-
if (request.live && !(response instanceof EditResponse)) {
642-
this._strategy?.undoChanges(modelAltVersionIdNow);
643-
}
644-
643+
progressiveEditsCts.dispose(true);
645644
requestCts.dispose();
646645
msgListener.dispose();
647646
typeListener.dispose();
648647

648+
if (request.live && !(response instanceof EditResponse)) {
649+
this._strategy?.undoChanges(modelAltVersionIdNow);
650+
}
651+
649652
this._activeSession.addExchange(new SessionExchange(this._activeSession.lastInput, response));
650653

651654
if (message & Message.CANCEL_SESSION) {

0 commit comments

Comments
 (0)