From 53e467c211f370ca4f38fadece02ec664efbf8da Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 19 Jan 2024 15:14:39 +0100 Subject: [PATCH] fix https://github.com/microsoft/vscode-copilot/issues/315 --- .../browser/inlineChatController.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index 2318b0bdd06..9c89e11d7ba 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -106,6 +106,7 @@ export class InlineChatController implements IEditorContribution { private _historyCandidate: string = ''; private _historyUpdate: (prompt: string) => void; + private _isDisposed: boolean = false; private readonly _store = new DisposableStore(); private readonly _zone: Lazy; private readonly _ctxHasActiveRequest: IContextKey; @@ -189,12 +190,15 @@ export class InlineChatController implements IEditorContribution { }; } - dispose(): void { - if (this._session) { - this._inlineChatSessionService.releaseSession(this._session); + async dispose(): Promise { + if (this._currentRun) { + this._messages.fire((this._session?.lastExchange + ? Message.PAUSE_SESSION + : Message.CANCEL_SESSION) + ); } - this._strategy?.dispose(); this._store.dispose(); + this._isDisposed = true; this._log('DISPOSED controller'); } @@ -262,7 +266,7 @@ export class InlineChatController implements IEditorContribution { protected async _nextState(state: State, options: InlineChatRunOptions): Promise { let nextState: State | void = state; - while (nextState) { + while (nextState && !this._isDisposed) { this._log('setState to ', nextState); nextState = await this[nextState](options); } @@ -457,20 +461,20 @@ export class InlineChatController implements IEditorContribution { store.dispose(); } - this._zone.value.widget.selectAll(false); if (message & (Message.CANCEL_INPUT | Message.CANCEL_SESSION)) { return State.CANCEL; } - if (message & Message.ACCEPT_SESSION) { - return State.ACCEPT; - } - if (message & Message.PAUSE_SESSION) { return State.PAUSE; } + if (message & Message.ACCEPT_SESSION) { + this._zone.value.widget.selectAll(false); + return State.ACCEPT; + } + if (message & Message.RERUN_INPUT && this._session.lastExchange) { const { lastExchange } = this._session; if (options.withIntentDetection === undefined) { // @ulugbekna: if we're re-running with intent detection turned off, no need to update `attempt` #