Skip to content

Commit 958db88

Browse files
authored
fix(amazonq): "rejectCodeSuggestion not found" after ctrl-z aws#5482
Problem: "aws.amazonq.rejectCodeSuggestion not found" error by doing below steps: 1. Install VSCodeVim 2. Trigger a code suggestion from Amazon Q. 3. Press tab to accept it. 4. Press Ctrl + Z to revoke the acceptance, then you will see the inline suggestion shown again. 5. Press Esc to reject it, then you will see `aws.amazonq.rejectCodeSuggestion` not found. In fact this is reproducible even without Vim. The root cause is the `Ctrl + Z` reverted the editor states and brought back the inline suggestions while the command override subscriptions were not brought back. During testing, I reproduced the `crashing` issue using Vim. 1. Install VSCodeVim. 2. Trigger a Q suggestion. 3. Press left or right arrow, then the suggestion does not navigate to next, previous suggestion, instead the cursor moves. After this, I am not getting code suggestions unless after sometime or certain conditions. The root cause to this is: Vim override the left right keybindings https://github.com/VSCodeVim/Vim/blob/89cf2d0356966303dc1bac7ce40eaef167d44088/package.json#L123 The keybinding override was somehow ranked as a higher priority item than Q left right navigation buttons. Before the fix, you can change the keybinding of `editor.action.inlineSuggest.showNext` to something not like right arrow key to avoid such keybinding conflict. You can also change keybinding of `extension.vim_right` (when VSCodeVim is installed) to avoid such conflict which caused crashing . I was able to make Q working after fixing these keybinding conflict. Solution: Test case 1: Trigger suggestion, accept it, ctrl +z, saw same suggestion, press Esc, suggestion disappears. The error command not found is not thrown. In this case, user can also reject it by keep typing to ignore it. Test case 2: Install Vim. Trigger suggestion, accept it, ctrl +z, saw same suggestion, press Esc, suggestion disappears. The error command not found is not thrown. In this case, user can also reject it by keep typing to ignore it. . Test case 3: Install Vim. Trigger suggestion, press left or right, the navigation is still not working(because Vim overrides the left right keys with highest priority), however, there is no crash anymore and user can still accept or reject the inline suggestion. Test case 4: Install Q and other code suggestion extensions, with this change, the key bindings are always under our extension, so when their suggestion shows, it triggers our command which breaks their experience.
1 parent 5b855a0 commit 958db88

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Fix bug when undo inline suggestion causes command not found"
4+
}

packages/core/src/codewhisperer/activation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ export async function activate(context: ExtContext): Promise<void> {
454454
}
455455

456456
async function setSubscriptionsforInlineCompletion() {
457+
RecommendationHandler.instance.subscribeSuggestionCommands()
457458
/**
458459
* Automated trigger
459460
*/

packages/core/src/codewhisperer/service/recommendationHandler.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ const nextCommand = Commands.declare('editor.action.inlineSuggest.showNext', ()
5959
})
6060

6161
const rejectCommand = Commands.declare('aws.amazonq.rejectCodeSuggestion', () => async () => {
62+
if (!isCloud9('any')) {
63+
await vscode.commands.executeCommand('editor.action.inlineSuggest.hide')
64+
}
6265
RecommendationHandler.instance.reportUserDecisions(-1)
63-
6466
await Commands.tryExecute('aws.amazonq.refreshAnnotation')
6567
})
6668

@@ -455,7 +457,6 @@ export class RecommendationHandler {
455457
this.clearRecommendations()
456458
this.disposeInlineCompletion()
457459
await vscode.commands.executeCommand('aws.amazonq.refreshStatusBar')
458-
this.disposeCommandOverrides()
459460
// fix a regression that requires user to hit Esc twice to clear inline ghost text
460461
// because disposing a provider does not clear the UX
461462
if (isVscHavingRegressionInlineCompletionApi()) {
@@ -668,8 +669,6 @@ export class RecommendationHandler {
668669
})
669670
this.reportUserDecisions(-1)
670671
} else if (session.recommendations.length > 0) {
671-
this.subscribeSuggestionCommands()
672-
// await this.startRejectionTimer(editor)
673672
await this.showRecommendation(0, true)
674673
}
675674
}

0 commit comments

Comments
 (0)