supertab
supertab copied to clipboard
Suptertab chaining is not working with neovim LSP
I set up Neovim's LSP following the guide here: https://github.com/neovim/nvim-lspconfig the relevant bit being this:
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
There are two problems with it. Because the omnifunc is only set when the LSP attaches, the autocmd to configure SuperTab:
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ endif
for setting up the chaining doesn't work because when it's executed omnifunc is still empty.
But even if I change it to:
autocmd FileType * call SuperTabChain(&omnifunc, "<c-p>")
I get errors:
=SuperTab('n')
Error detected while processing function SuperTabCodeComplete:
line 12:
E15: Invalid expression: v:lua
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 12:
E475: Invalid argument: v:lua.vim.lsp.omnifunc
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 15:
E117: Unknown function: Func
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 16:
E121: Undefined variable: start
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 12:
E15: Invalid expression: v:lua
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 12:
E475: Invalid argument: v:lua.vim.lsp.omnifunc
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 23:
E117: Unknown function: Func
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 26:
E121: Undefined variable: results
Press ENTER or type command to continue
Error detected while processing function SuperTabCodeComplete:
line 26:
E116: Invalid arguments for function type
Press ENTER or type command to continue
Scanning tags.
Press ENTER or type command to continue
Is there anything I can do or can SuperTab be changed to make this work?
+1 for this from me, same issue precisely. I might have a poke around in Supertab in the next week or two to try to figure out a fix.
Edit: I ended up switching to mucomplete, so I won't be looking any further on this.
This happens because SuperTabCodeComplete
has the line:
let Func = function(b:SuperTabChain[0])
which makes a funcref
out of b:SuperTabChain[0]
, and the docs for v:lua
explicitly say:
Note: v:lua without a call is not allowed in a Vimscript expression: Funcrefs cannot represent Lua functions.
You can work around this with the following:
vim.cmd [[
function! SuperTabLspOmnifunc(findstart, base)
return v:lua.vim.lsp.omnifunc(a:findstart, a:base)
endfunction
]]
vim.bo.omnifunc = "SuperTabLspOmnifunc"
-- Reactivate completion chaining after setting omnifunc (see `:h supertab-completionchaining`)
vim.fn.SuperTabChain("SuperTabLspOmnifunc", "<c-p>")
vim.fn.SuperTabSetDefaultCompletionType("<c-x><c-u>")