From 95c242366837af60e5df3dc9a50346294d8f2d2a Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 27 May 2024 16:14:22 +0200 Subject: [PATCH] fix https://github.com/microsoft/vscode/issues/213563 --- .../browser/inlineChatController.ts | 12 ++----- .../test/browser/inlineChatController.test.ts | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index a90b7ba2e088c..7ccb6a71164bb 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -439,15 +439,9 @@ export class InlineChatController implements IEditorContribution { } }); } else if (e.kind === 'removeRequest') { - // TODO@jrieken this currently is buggy when removing not the very last request/response - // if (this._session!.lastExchange?.response instanceof ReplyResponse) { - // try { - // this._session!.hunkData.ignoreTextModelNChanges = true; - // await this._strategy!.undoChanges(this._session!.lastExchange.response.modelAltVersionId); - // } finally { - // this._session!.hunkData.ignoreTextModelNChanges = false; - // } - // } + // TODO@jrieken this is buggy/weird when having code changes from multiple turns because + // logically they are all the same hunks + this._strategy?.cancel(); } })); diff --git a/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts b/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts index b49aa79793dee..f88d7a9904249 100644 --- a/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts +++ b/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts @@ -60,6 +60,7 @@ import { ChatVariablesService } from 'vs/workbench/contrib/chat/browser/chatVari import { ICommandService } from 'vs/platform/commands/common/commands'; import { TestCommandService } from 'vs/editor/test/browser/editorTestServices'; import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; +import { RerunAction } from 'vs/workbench/contrib/inlineChat/browser/inlineChatActions'; suite('InteractiveChatController', function () { @@ -458,4 +459,39 @@ suite('InteractiveChatController', function () { assert.ok(model.getValue().includes('MANUAL')); }); + + test('re-run should discard pending edits', async function () { + + let count = 1; + + store.add(chatAgentService.registerDynamicAgent({ + id: 'testEditorAgent2', + ...agentData + }, { + async invoke(request, progress, history, token) { + progress({ kind: 'textEdit', uri: model.uri, edits: [{ range: new Range(1, 1, 1, 1), text: request.message + (count++) }] }); + return {}; + }, + })); + + ctrl = instaService.createInstance(TestController, editor); + const rerun = new RerunAction(); + + model.setValue(''); + + const p = ctrl.waitFor([...TestController.INIT_SEQUENCE, State.SHOW_REQUEST, State.SHOW_RESPONSE, State.WAIT_FOR_INPUT]); + const r = ctrl.run({ message: 'PROMPT_', autoSend: true }); + await p; + + assert.strictEqual(model.getValue(), 'PROMPT_1'); + + const p2 = ctrl.waitFor([State.SHOW_REQUEST, State.SHOW_RESPONSE, State.WAIT_FOR_INPUT]); + await instaService.invokeFunction(rerun.runInlineChatCommand, ctrl, editor); + + await p2; + + assert.strictEqual(model.getValue(), 'PROMPT_2'); + ctrl.finishExistingSession(); + await r; + }); });