diff --git a/.config/nvim/lua/blake/lsp.lua b/.config/nvim/lua/blake/lsp.lua index 894b0b5..a20a6e6 100644 --- a/.config/nvim/lua/blake/lsp.lua +++ b/.config/nvim/lua/blake/lsp.lua @@ -170,6 +170,7 @@ end -- <<< M.lspconfig = function() local nvim_lsp = require('lspconfig') + -- Keybinds for servers >>> -- 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) @@ -200,14 +201,14 @@ M.lspconfig = function() buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - end + end -- <<< + -- Load servers >>> -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local lsp_servers = { clangd = 'clangd', html = 'vscode-html-language-server', - sumneko_lua = 'lua-language-server', bashls = 'bash-language-server', } for lsp, exe in pairs(lsp_servers) do @@ -220,6 +221,56 @@ M.lspconfig = function() } end end + -- Custom servers >>> + -- lua >>> + -- From kickstart.nvim: + local sumneko_root_path + local sumneko_binary + if (vim.fn.exepath('lua-language-server') ~= '') then + -- If you installed this with your package manager + sumneko_root_path = '/usr/lib/lua-language-server/bin/Linux' + sumneko_binary = vim.fn.exepath('lua-language-server') + else + -- If you installed this with lspinstall + sumneko_root_path = vim.fn.getenv 'HOME' .. '/.local/share/nvim/lspinstall/lua/sumneko-lua/extension/server' + sumneko_binary = sumneko_root_path .. '/lua-language-server' + end + + -- Make runtime files discoverable to the server + 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' }, + on_attach = on_attach, + capabilities = capabilities, + 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, + }, + }, + }, + } + -- lua <<< + -- Custom servers <<< + -- Load servers <<< end -- <<< return M