Skip to content

Commit 5a220d2

Browse files
committed
correct the auto trigger flag
1 parent f36023f commit 5a220d2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
255255
return []
256256
}
257257

258-
const isAutoTrigger = context.triggerKind === InlineCompletionTriggerKind.Automatic
258+
// there is a bug in VS Code, when hitting Enter, the context.triggerKind is Invoke (0)
259+
// when hitting other keystrokes, the context.triggerKind is Automatic (1)
260+
// we only mark option + C as manual trigger
261+
const isAutoTrigger = performance.now() - vsCodeState.lastManualTriggerTime > 50
259262
if (isAutoTrigger && !CodeSuggestionsState.instance.isSuggestionsEnabled()) {
260263
// return early when suggestions are disabled with auto trigger
261264
return []
@@ -348,7 +351,10 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
348351
this.languageClient,
349352
document,
350353
position,
351-
context,
354+
{
355+
triggerKind: isAutoTrigger ? 1 : 0,
356+
selectedCompletionInfo: context.selectedCompletionInfo,
357+
},
352358
token,
353359
isAutoTrigger,
354360
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,
@@ -365,6 +366,7 @@ async function onLanguageServerReady(
365366
sessionManager.checkInlineSuggestionVisibility()
366367
}),
367368
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
369+
vsCodeState.lastManualTriggerTime = performance.now()
368370
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
369371
}),
370372
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)