Skip to content

Commit 54dbec8

Browse files
authored
fix(amazonq): correct the isAutoTrigger boolean flag (#7787)
## Problem There is a bug in VS Code inline completion API, when hitting Enter, the context.triggerKind is Invoke (0) when hitting other keystrokes, the context.triggerKind is Automatic (1) we should only mark option + C as manual trigger Invoke(0) ## Solution Use timestamp to decide what is manual trigger and what is auto trigger. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a41fde3 commit 54dbec8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
262262
return []
263263
}
264264

265-
const isAutoTrigger = context.triggerKind === InlineCompletionTriggerKind.Automatic
265+
// there is a bug in VS Code, when hitting Enter, the context.triggerKind is Invoke (0)
266+
// when hitting other keystrokes, the context.triggerKind is Automatic (1)
267+
// we only mark option + C as manual trigger
268+
// this is a workaround since the inlineSuggest.trigger command take no params
269+
const isAutoTrigger = performance.now() - vsCodeState.lastManualTriggerTime > 50
266270
if (isAutoTrigger && !CodeSuggestionsState.instance.isSuggestionsEnabled()) {
267271
// return early when suggestions are disabled with auto trigger
268272
return []
@@ -355,7 +359,10 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
355359
this.languageClient,
356360
document,
357361
position,
358-
context,
362+
{
363+
triggerKind: isAutoTrigger ? 1 : 0,
364+
selectedCompletionInfo: context.selectedCompletionInfo,
365+
},
359366
token,
360367
isAutoTrigger,
361368
getAllRecommendationsOptions,

packages/amazonq/src/lsp/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CodeWhispererSettings,
2424
getSelectedCustomization,
2525
TelemetryHelper,
26+
vsCodeState,
2627
} from 'aws-core-vscode/codewhisperer'
2728
import {
2829
Settings,
@@ -366,6 +367,7 @@ async function onLanguageServerReady(
366367
sessionManager.checkInlineSuggestionVisibility()
367368
}),
368369
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
370+
vsCodeState.lastManualTriggerTime = performance.now()
369371
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
370372
}),
371373
Commands.register('aws.amazonq.refreshAnnotation', async (forceProceed: boolean) => {

packages/core/src/codewhisperer/models/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ interface VsCodeState {
4242
lastUserModificationTime: number
4343

4444
isFreeTierLimitReached: boolean
45+
46+
lastManualTriggerTime: number
4547
}
4648

4749
export const vsCodeState: VsCodeState = {
@@ -52,6 +54,7 @@ export const vsCodeState: VsCodeState = {
5254
isRecommendationsActive: false,
5355
lastUserModificationTime: 0,
5456
isFreeTierLimitReached: false,
57+
lastManualTriggerTime: 0,
5558
}
5659

5760
export interface CodeWhispererConfig {

0 commit comments

Comments
 (0)