Skip to content

fix: reset inline chat state when the edited file is deleted#144

Draft
laileni-aws wants to merge 1 commit into
aws:mainfrom
laileni-aws:fix/inline-chat-cleanup-on-file-delete
Draft

fix: reset inline chat state when the edited file is deleted#144
laileni-aws wants to merge 1 commit into
aws:mainfrom
laileni-aws:fix/inline-chat-cleanup-on-file-delete

Conversation

@laileni-aws

Copy link
Copy Markdown
Contributor

Problem

If a file is deleted while an inline chat suggestion is still pending (e.g. you select the whole file, start inline chat, then delete the file before/while the response is generated), the IDE gets stuck:

  • the Accept/Reject code lenses stay on top of files, and
  • the Enter key is disabled (the inline‑chat accept shortcut context stays enabled).

The only workaround is to reopen the IDE window.

Root cause

InlineChatController sets TaskState.WaitingForDecision and enables the context key amazonq.inline.codelensShortcutEnabled (which binds Enter to "accept"). Accept/Reject only clean up via reset() once the user acts — but acceptAllChanges/rejectAllChanges early‑return when they can't find an editor for the task's document. When the file is deleted, there is no editor, so reset() never runs and the lenses + Enter‑shortcut context remain stuck.

Fix

Register a vscode.workspace.onDidDeleteFiles listener in the controller. When the deleted file backs the currently active inline task, run the existing handleError() cleanup path, which clears the code lenses (updateLenses → empty) and calls reset() (which unsets amazonq.inline.codelensShortcutEnabled and clears the task). This restores the IDE without needing to reopen the window.

Testing / verification

  • The change is a minimal lifecycle listener that reuses the controller's existing handleError() cleanup path.
  • Verified via type-check and the repository CI (full compile + unit/integration test matrix).
  • Note: I did not add a dedicated unit test for InlineChatController — constructing it requires a live language client and streaming dependencies that aren't practical to instantiate in isolation. The fix is intentionally small and delegates to the already‑exercised handleError() path. Reviewer visual confirmation of the exact repro (delete file mid‑generation) is welcome.

If a file is deleted while an inline chat suggestion is pending, the
task can never be accepted or rejected (its editor is gone). This left
the accept/reject code lenses on screen and the Enter-key shortcut
context enabled, effectively disabling Enter across the IDE until the
window was reopened.

Listen for file deletions and, when the deleted file backs the active
inline task, run the existing error-cleanup path to clear the lenses
and reset the shortcut context.
@laileni-aws
laileni-aws force-pushed the fix/inline-chat-cleanup-on-file-delete branch from e37f701 to 5e532dc Compare July 15, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant