NeoVim API information not working with lua-language-server (sumneko)

I have copied + pasted the proposed config for the lua-language-server:

-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, 'lua/?.lua')
table.insert(runtime_path, 'lua/?/init.lua')

nvim_lsp.sumneko_lua.setup {
  on_attach = on_attach,
  settings = {
    Lua = {
      runtime = {
        -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
        version = 'LuaJIT',
        -- Setup your lua path
        path = runtime_path,
      },
      diagnostics = {
        -- Get the language server to recognize the `vim` global
        globals = {'vim'},
      },
      workspace = {
        -- Make the server aware of Neovim runtime files
        library = vim.api.nvim_get_runtime_file("", true),
        checkThirdParty = false,
      },
      -- Do not send telemetry data containing a randomized but unique identifier
      telemetry = {
        enable = false,
      },
    },
  },
}

And have installed the server. If I type, e.g. print(, I get the right suggestions and docs pop-up.
However, if I try to use vim.api…, I get nothing other than text matches; I don’t get the nice list of available functions and their documentation:

I’m not sure if I’m missing anything obvious, but I’d appreciate any pointers!

NVIM v0.7.0-dev+1211-g2783f4cc4                                                                                                                                                                                                                                                  
Build type: Release                                                                                                                                                                                                                                                              
LuaJIT 2.1.0-beta3  

Is my NeoVim build, and I updated all my plugins today so I’m on the latest and greatest lspconfig.

Thanks!

I believe you need another completion source for the nvim api. At least that was my experience.

If you use nvim-cmp, you can use this one, by the author of nvim-cmp

I think you can also provide emmylua annotations like lua-dev.nvim

1 Like

I have the same problem too. Did you solve it?

Adding GitHub - hrsh7th/cmp-nvim-lua: nvim-cmp source for nvim lua to my config got it working for me, thanks!

It works, thanks! But I’m still wondering why that sumneko_lua works for Neovim API information before I did something. So I reinstalled a lua lsp in a virtual machine and it completes Neovim API without cmp-nvim-lua source.It made me confused…

For me, the problem is not only with completion, but with general lsp info.

For example, I don’t get the full API on hover, only the methods I used.

image