hrsh7th / vim-vsnip-integ

vim-vsnip integrations to other plugins.
MIT License
127 stars 15 forks source link

Error detected while processing function <SNR>151_on_complete_done_after #46

Closed jandamm closed 3 years ago

jandamm commented 3 years ago

Hey I've got the following error:

Error detected while processing function <SNR>151_on_complete_done_after[15]..<SNR>151_remove_completed_text:
line   33:
E474: Invalid argument

I use the builtin neovim lsp with the builtin omnifunc. To reproduce this error open autoload/vsnip-integ.vim with lspconfig.vimls setup:

lspconfig.vimls.setup({
    capabilities = { textDocument = { completion = { completionItem = { snippetSupport = true } } } },
    init_options = { usePlaceholders = true }
})

I use these completeopts: menu, with menu,menuone it does however work.

Then type:

call s:re<C-x><C-o>

Now you should see call s:remove_completed_text(context)${0 Here is another error since ${0 shouldn't be there.

Then type <DEL> until the current line is call s:remove_completed_tex. Then <C-x><C-o> again. Now this error should happen.

When you exit insert mode between the two invocations of omnifunc it doesn't produce this error.

jandamm commented 3 years ago

It seems the range.start.character is -6 while it should be 7. Which is because the current line does not contain the match and is 13 chars shorter than the code assumes.

Screenshot 2021-09-09 at 09 53 31@2x
jandamm commented 3 years ago

There is also another weird case which I cannot reproduce with vimls.

I type Rul<C-x><C-o><C-y> and it completes to Rule invoking s:on_complete_done('Rule'). Which is fine.

Then I type (<C-x><C-o> which invokes s:on_complete_done('Rule') again. Which is wrong. Afterwards it presents the completion which is what would be in the brackets. When accepting the completion it the context is changed and ( is deleted. Which results in the same error.

hrsh7th commented 3 years ago

I might improve it because I have more knowledge than when I implemented it.

jandamm commented 3 years ago

I'm not sure about other side effects but it seems to work quite well with this changes:

plugin/vsnip_integ.vim:11

+autocmd CompleteDonePre * if complete_info(['mode']).mode !=? '' | call vsnip_integ#on_complete_done(v:completed_item) | endif
-autocmd CompleteDone * call vsnip_integ#on_complete_done(v:completed_item)