Help setting up sumneko_lua

I’m trying to set up the sumneko_lua language server with neovim/nvim-lspconfig. The server works fine, it’s detected by neovim and I get completion and diagnostics but for some reason I don’t get any of the mappings defined in the on_attach function but I do get them when using other language servers. Please, help me figure out why.

This is the LSP config I’m using (as close to the default as possilbe):

local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
	local function buf_set_keymap(...)
		vim.api.nvim_buf_set_keymap(bufnr, ...)
	local function buf_set_option(...)
		vim.api.nvim_buf_set_option(bufnr, ...)

	--Enable completion triggered by <c-x><c-o>
	buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")

	-- Mappings.
	local opts = { noremap = true, silent = true }

	-- See `:help vim.lsp.*` for documentation on any of the below functions
	buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
	buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)

local servers = {
-- local servers = {"sumneko_lua"}
for _, lsp in ipairs(servers) do
  nvim_lsp[lsp].setup {
    on_attach = on_attach,
    flags = {
      debounce_text_changes = 150,

local system_name
if vim.fn.has("mac") == 1 then
  system_name = "macOS"
elseif vim.fn.has("unix") == 1 then
  system_name = "Linux"
elseif vim.fn.has('win32') == 1 then
  system_name = "Windows"
  print("Unsupported system for sumneko")
-- set the path to the sumneko installation; if you previously installed via the now deprecated :LspInstall, use
local sumneko_root_path = vim.env.HOME .. '/.local/builds/lua-language-server'
local sumneko_binary = sumneko_root_path.."/bin/"..system_name.."/lua-language-server"
-- local sumneko_binary = "/usr/bin/lua-language-server"
-- local main = "/usr/share/lua-language-server/main.lua"
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")

require'lspconfig'.sumneko_lua.setup {
  cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
  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),
      -- Do not send telemetry data containing a randomized but unique identifier
      telemetry = {
        enable = false,

As I said neovim detects the server and completion and everything works fine but mappings are not set. For example:

:map gd


No mapping found

Thanks, I just made this a bit more explicit in the docs.

To be more explicit, you’re not passing on_attach into sumneko’s setup call.

1 Like

Oh makes sense!

By the way, in the sumneko lua section of you have the first key-value pair ending in a semicolon:

cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};

I thought it was meant to be a comma but surprisingly (for me) it works both with a comma or a semicolon. Is it a typo or does it serves a specific purpose? I’m not that knowledgeable about lua.

You can use semicolons or commas to delineate entries in tables (that’s a lua syntax thing). We should probably be consistent though. I added stylua format rules which I believe enforce commas.

1 Like

you can use lua-dev it have good document and you can goto definition of plugins function