diff --git a/packages/amazonq/.changes/next-release/Bug Fix-93c75b36-50c8-480b-a289-cc1d209bfe5b.json b/packages/amazonq/.changes/next-release/Bug Fix-93c75b36-50c8-480b-a289-cc1d209bfe5b.json new file mode 100644 index 000000000..65b526b54 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-93c75b36-50c8-480b-a289-cc1d209bfe5b.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Inline chat: reset the accept/reject state (code lenses and Enter shortcut) when the file being edited is deleted, so the IDE no longer gets stuck" +} diff --git a/packages/amazonq/src/inlineChat/controller/inlineChatController.ts b/packages/amazonq/src/inlineChat/controller/inlineChatController.ts index 98b0fc7c6..fd5a932ab 100644 --- a/packages/amazonq/src/inlineChat/controller/inlineChatController.ts +++ b/packages/amazonq/src/inlineChat/controller/inlineChatController.ts @@ -52,6 +52,28 @@ export class InlineChatController { this.computeDiffAndRenderOnEditor = Experiments.instance.get('amazonqLSPInlineChat', false) ? this.computeDiffAndRenderOnEditorLSP.bind(this) : this.computeDiffAndRenderOnEditorLocal.bind(this) + + // If the file backing an active inline task is deleted, the task can no longer be + // accepted or rejected (its editor is gone), which would otherwise leave the + // accept/reject code lenses and the Enter-key shortcut context stuck until the IDE + // window is reopened. Clean up the inline task when its document is deleted. + context.subscriptions.push( + vscode.workspace.onDidDeleteFiles(async (event) => { + for (const uri of event.files) { + await this.cancelActiveTaskForDeletedDocument(uri) + } + }) + ) + } + + /** + * Resets the inline chat state if the currently active task's document was deleted, + * so the code lenses and the Enter-key shortcut context do not get stuck. + */ + private async cancelActiveTaskForDeletedDocument(uri: vscode.Uri): Promise { + if (this.task?.isActiveState() === true && this.task.document.uri.toString() === uri.toString()) { + await this.handleError() + } } public async createTask(