Skip to content

Commit 2cc561a

Browse files
committed
fix: sometimes Enter does not auto trigger
1 parent 68adf18 commit 2cc561a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

server/aws-lsp-codewhisperer/src/language-server/inline-completion/auto-trigger/autoTrigger.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ describe('Auto Trigger', async () => {
119119
assert.strictEqual(getAutoTriggerType(createContentChange('\n')), 'Enter')
120120
assert.strictEqual(getAutoTriggerType(createContentChange('\r\n')), 'Enter')
121121
assert.strictEqual(getAutoTriggerType(createContentChange('\n ')), 'Enter')
122+
const changes = [{ text: '\n ' }, { text: '' }]
123+
assert.strictEqual(getAutoTriggerType(changes), 'Enter')
122124
})
123125

124126
it('should return undefined for tab changes', () => {

server/aws-lsp-codewhisperer/src/language-server/inline-completion/auto-trigger/autoTrigger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ function isTabKey(str: string): boolean {
110110
export const getAutoTriggerType = (
111111
contentChanges: TextDocumentContentChangeEvent[]
112112
): CodewhispererAutomatedTriggerType | undefined => {
113-
if (contentChanges.length !== 1) {
113+
if (contentChanges.length < 1 || contentChanges.length > 2) {
114114
// Won't trigger cwspr on multi-line changes
115115
// event.contentChanges.length will be 2 when user press Enter key multiple times
116+
// in certain cases, first contentChange item is valid, 2nd is empty string
116117
return undefined
117118
}
118119
const changedText = contentChanges[0].text

0 commit comments

Comments
 (0)