diff --git a/autoload/coc/pum.vim b/autoload/coc/pum.vim index e7384b04300..be0e052edb5 100644 --- a/autoload/coc/pum.vim +++ b/autoload/coc/pum.vim @@ -65,7 +65,7 @@ function! coc#pum#close(...) abort endif call s:close_pum() if !get(a:, 2, 0) - call coc#rpc#notify('CompleteStop', [kind]) + call coc#rpc#request('CompleteStop', [kind]) endif endif return '' @@ -115,7 +115,7 @@ function! coc#pum#_insert() abort endif doautocmd TextChangedI call s:close_pum() - call coc#rpc#notify('CompleteStop', ['']) + call coc#rpc#request('CompleteStop', ['']) endif return '' endfunction diff --git a/src/attach.ts b/src/attach.ts index cceb75bfd76..3fb11df4aae 100644 --- a/src/attach.ts +++ b/src/attach.ts @@ -99,7 +99,11 @@ export default (opts: Attach, requestApi = false): Plugin => { timing.start(method) try { events.requesting = true - if (method == 'CocAutocmd') { + if (method == 'CompleteStop') { + logger.trace('Event: ', method, ...args) + await events.fire(method, args) + resp.send(undefined) + } else if (method == 'CocAutocmd') { logger.trace('Request autocmd:', ...args) await events.fire(args[0], args.slice(1)) resp.send(undefined) diff --git a/src/completion/index.ts b/src/completion/index.ts index d4af488d578..aee3774fe98 100644 --- a/src/completion/index.ts +++ b/src/completion/index.ts @@ -66,8 +66,8 @@ export class Completion implements Disposable { events.on('CursorMovedI', () => { clearTimeout(this.triggerTimer) }, null, this.disposables) - events.on('CompleteStop', kind => { - this.stop(false, kind) + events.on('CompleteStop', async kind => { + await this.stopAwaitable(false, kind) }, null, this.disposables) events.on('InsertEnter', this.onInsertEnter, this, this.disposables) events.on('TextChangedI', this.onTextChangedI, this, this.disposables) @@ -360,6 +360,10 @@ export class Completion implements Disposable { } public stop(close: boolean, kind: CompleteFinishKind = CompleteFinishKind.Normal): void { + void this.stopAwaitable(close, kind) + } + + public async stopAwaitable(close: boolean, kind: CompleteFinishKind = CompleteFinishKind.Normal): Promise { let { complete } = this if (complete == null) return let inserted = kind === CompleteFinishKind.Confirm || (this.popupEvent?.inserted && kind != CompleteFinishKind.Cancel) @@ -374,14 +378,16 @@ export class Completion implements Disposable { events.completing = false this.cancel() doc._forceSync() - void events.fire('CompleteDone', [toCompleteDoneItem(item, resolved?.item)]) + const completeDone = events.fire('CompleteDone', [toCompleteDoneItem(item, resolved?.item)]) if (close) this.nvim.call('coc#pum#_close', [], true) if (resolved && inserted) { this._mru.add(line.slice(character, inputStart) + input, item) } + let confirmDone = Promise.resolve() if (kind == CompleteFinishKind.Confirm && resolved) { - void this.confirmCompletion(resolved.source, resolved.item, option) + confirmDone = this.confirmCompletion(resolved.source, resolved.item, option) } + await Promise.all([completeDone, confirmDone]) } private async confirmCompletion(source: ISource, item: CompleteItem, option: CompleteOption): Promise {