Skip to content

Commit

Permalink
fix(completion): trigger CompleteDone without TextChangedI
Browse files Browse the repository at this point in the history
TextChangedI possible not fired with empty word.
  • Loading branch information
chemzqm committed May 8, 2022
1 parent e820875 commit e862899
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/completion/language.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompletionItem[]> => [{
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
Expand Down
4 changes: 2 additions & 2 deletions src/completion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/completion/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export async function waitInsertEvent(): Promise<string | undefined> {
return res?.name
}

export async function waitTextChangedI(): Promise<InsertChange | undefined> {
let res = await events.race(['InsertCharPre', 'CursorMoved', 'InsertLeave', 'TextChangedI'], 300)
if (!res || res.name !== 'TextChangedI') return
export async function waitTextChangedI(): Promise<InsertChange | string | undefined> {
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
}

Expand Down

0 comments on commit e862899

Please sign in to comment.