Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suptertab chaining is not working with neovim LSP #221

Open
sblask opened this issue Jun 8, 2022 · 2 comments
Open

Suptertab chaining is not working with neovim LSP #221

sblask opened this issue Jun 8, 2022 · 2 comments

Comments

@sblask
Copy link

sblask commented Jun 8, 2022

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?

@jparoz
Copy link

jparoz commented Aug 29, 2022

+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.

@ddickstein
Copy link

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>")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants