From e862899315144c02298a6a517069e70f5d198810 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 9 May 2022 00:44:06 +0800 Subject: [PATCH] fix(completion): trigger CompleteDone without TextChangedI TextChangedI possible not fired with empty word. --- src/__tests__/completion/language.test.ts | 16 ++++++++++++++++ src/completion/index.ts | 4 ++-- src/completion/util.ts | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/__tests__/completion/language.test.ts b/src/__tests__/completion/language.test.ts index 2f7eb211fd8..1f0d5b48193 100644 --- a/src/__tests__/completion/language.test.ts +++ b/src/__tests__/completion/language.test.ts @@ -232,6 +232,22 @@ describe('language source', () => { await helper.waitFor('getline', ['.'], 'foo') }) + it('should applyEdits for empty word', async () => { + let provider: CompletionItemProvider = { + provideCompletionItems: async (): Promise => [{ + label: '', + filterText: '!', + textEdit: { range: Range.create(0, 0, 0, 1), newText: 'foo' }, + data: { word: '' } + }] + } + disposables.push(languages.registerCompletionItemProvider('edits', 'edit', null, provider, ['!'])) + await nvim.input('i!') + await helper.waitPopup() + await helper.selectCompleteItem(0) + await helper.waitFor('getline', ['.'], 'foo') + }) + it('should provide word when textEdit after startcol', async () => { // some LS would send textEdit after first character, // need fix the word from newText diff --git a/src/completion/index.ts b/src/completion/index.ts index b71f1971052..033a0995b27 100644 --- a/src/completion/index.ts +++ b/src/completion/index.ts @@ -389,8 +389,8 @@ export class Completion implements Disposable { if (!resolvedItem) return this.mru.add(input, resolvedItem) let insertChange = await waitTextChangedI() - if (!insertChange) return - if (insertChange.lnum != opt.linenr || insertChange.pre !== byteSlice(opt.line, 0, opt.col) + item.word) return + if (typeof insertChange === 'string') return + if (insertChange && (insertChange.lnum != opt.linenr || insertChange.pre !== byteSlice(opt.line, 0, opt.col) + item.word)) return let res = await events.race(['InsertCharPre', 'CursorMovedI'], 20) if (res) return let source = new CancellationTokenSource() diff --git a/src/completion/util.ts b/src/completion/util.ts index 3a195be5197..0b4e6b12d78 100644 --- a/src/completion/util.ts +++ b/src/completion/util.ts @@ -9,9 +9,9 @@ export async function waitInsertEvent(): Promise { return res?.name } -export async function waitTextChangedI(): Promise { - let res = await events.race(['InsertCharPre', 'CursorMoved', 'InsertLeave', 'TextChangedI'], 300) - if (!res || res.name !== 'TextChangedI') return +export async function waitTextChangedI(): Promise { + let res = await events.race(['InsertCharPre', 'CursorMoved', 'InsertLeave', 'TextChangedI'], 100) + if (!res || res.name !== 'TextChangedI') return res ? res.name : undefined return res.args[1] as InsertChange }