yami-beta / asyncomplete-omni.vim

Omni completion source for asyncomplete.vim
MIT License
39 stars 11 forks source link

Omnicompletion for the new native lsp completion #16

Closed entropitor closed 4 years ago

entropitor commented 4 years ago

When I set up neovim using https://neovim.io/doc/user/lsp.html#vim.lsp.omnifunc(), this plugin fails with the following error

Vim(return):E117: Unknown function: v:lua.vim.lsp.omnifunc

How can I fix this?

yami-beta commented 4 years ago

asyncomplete-omni.vim is omni completion source of asyncomplete.vim. Maybe, neovim's native lsp completion does not use asyncomplete-omni.vim.

entropitor commented 4 years ago

@yami-beta they use omni function but they use a lua function to do so. This is configured using v:lua:... and that seems to be erroring in this plugin

entropitor commented 4 years ago

I guess it's related to this

acomagu commented 4 years ago

After struggling, this worked for me:

diff --git a/autoload/asyncomplete/sources/omni.vim b/autoload/asyncomplete/sources/omni.vim
index 78acce7..a12a424 100644
--- a/autoload/asyncomplete/sources/omni.vim
+++ b/autoload/asyncomplete/sources/omni.vim
@@ -34,12 +34,20 @@ endfunction
 function! s:safe_omnifunc(...) abort
   let cursor = getpos('.')
   try
-    return call(&omnifunc, a:000)
+    if &omnifunc == 'v:lua.vim.lsp.omnifunc'
+      return s:call_nvim_lsp_omnifunc(a:1, a:2)
+    elseif
+      return call(&omnifunc, a:000)
+    endif
   finally
     call setpos('.', cursor)
   endtry
 endfunction

+function! s:call_nvim_lsp_omnifunc(a:fundstart, a:base) abort
+  return v:lua.vim.lsp.omnifunc(a:findstart, a:base)
+endfunction
+

 let &cpo = s:save_cpo
 unlet s:save_cpo

I really not familiar with VimScript so please anyone improve this!!

acomagu commented 4 years ago

I'll create a pull.