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, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
--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)
end
local servers = {
"pyright",
"clangd",
"bashls",
"texlab",
"vimls",
"sumneko_lua"
}
-- local servers = {"sumneko_lua"}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
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"
else
print("Unsupported system for sumneko")
end
-- 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
returns
No mapping found