maralla / completor.vim

Async completion framework made ease.
MIT License
1.27k stars 63 forks source link

Fix completeopt not being restored after completion #258

Closed arthurxavierx closed 5 years ago

arthurxavierx commented 5 years ago

According to the documentation:

"[...] The config `completeopt` will be 
       overwritten by the value when the completion is triggered and restored
       after completion done."

This is not what happens in reality though, as completeopt is overwritten when entering insert mode, and only restored after leaving it, completely breaking the use of Vim's native completion with the user's completeopt.

This pull request fixes this behavior, adapting it to what is described in the documentation and to what is considered a better user experience.

arthurxavierx commented 5 years ago

This will probably fix #252.

maralla commented 5 years ago

Thanks for figuring this out. I have a similar fix for this problem in the commit c11ab62 several months ago. But soon I found that at certain situations the CompleteDone event will not be triggered. For example to terminate completion with ctrl_c. I don’t have much time to come out an appropriate solution, so the problem still exists.

arthurxavierx commented 5 years ago

Hmm, I see. Well, an easy solution is to recover the original completeopt after both the CompleteDone and InsertLeave events then. I will update the PR with this.

maralla commented 5 years ago

I tested and found out that InsertLeave won't triggered after ctrl_c. Here is my vim version:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 31 2018 17:01:35)
macOS version
Included patches: 1-300
Compiled by Homebrew

From the doc:

InsertLeave When leaving Insert mode. Also when using CTRL-O i_CTRL-O. But not for i_CTRL-C.

arthurxavierx commented 5 years ago

I see. So, the thing here is that this behavior already exists in the current version of the plugin. This PR only improves (or fixes) the functionality that's described in the documentation:

"[...] The config `completeopt` will be 
       overwritten by the value when the completion is triggered and restored
       after completion done."

Currently, completeopt is not restored after completion is done, only after insert mode is left (without ctrl_c). This PR is a small improvement aiming at the described behavior in my opinion.

maralla commented 5 years ago

Thanks!

maralla commented 5 years ago

There has other side effects of restore cot in CompleteDone. Look at the following screencast:

com

I want to insert Golang under the cursor, but it completes global for me. The cot option is menuone,longest,preview and the g:completor_complete_options is menuone,noselect,preview. The log in the top right pane shows that during completion cot is restored before the completion finished.

I reverted the pr in #260.

arthurxavierx commented 5 years ago

Oh this is sad. :/