Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Let Enter invoke auto completion more consistently"
}
12 changes: 6 additions & 6 deletions packages/amazonq/src/app/inline/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
return []
}

const isAutoTrigger = context.triggerKind === InlineCompletionTriggerKind.Automatic
if (isAutoTrigger && !CodeSuggestionsState.instance.isSuggestionsEnabled()) {
// return early when suggestions are disabled with auto trigger
return []
}

// yield event loop to let the document listen catch updates
await sleep(1)
// prevent user deletion invoking auto trigger
Expand All @@ -254,12 +260,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
try {
const t0 = performance.now()
vsCodeState.isRecommendationsActive = true
const isAutoTrigger = context.triggerKind === InlineCompletionTriggerKind.Automatic
if (isAutoTrigger && !CodeSuggestionsState.instance.isSuggestionsEnabled()) {
// return early when suggestions are disabled with auto trigger
return []
}

// handling previous session
const prevSession = this.sessionManager.getActiveSession()
const prevSessionId = prevSession?.sessionId
Expand Down
19 changes: 19 additions & 0 deletions packages/amazonq/src/app/inline/documentEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class DocumentEventListener {
this.lastDocumentChangeEventMap.clear()
}
this.lastDocumentChangeEventMap.set(e.document.uri.fsPath, { event: e, timestamp: performance.now() })
// The VS Code provideInlineCompletionCallback may not trigger when Enter is pressed, especially in Python files
// manually make this trigger. In case of duplicate, the provideInlineCompletionCallback is already debounced
if (this.isEnter(e) && vscode.window.activeTextEditor) {
void vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
}
}
})
}
Expand All @@ -47,4 +52,18 @@ export class DocumentEventListener {
this.documentChangeListener.dispose()
}
}

private isEnter(e: vscode.TextDocumentChangeEvent): boolean {
if (e.contentChanges.length !== 1) {
return false
}
const str = e.contentChanges[0].text
if (str.length === 0) {
return false
}
return (
(str.startsWith('\r\n') && str.substring(2).trim() === '') ||
(str[0] === '\n' && str.substring(1).trim() === '')
)
}
}
Loading