-- This function configures all the LSP clients that i might care about. -- It is expected to be called in the 'config' step of the 'lspconfig' plugin. -- autocommand: function, that can create autocmds return function() local integrate_into_neovim = function(client, buffer_number) print("LSP " .. client.name .. " [" .. client.id .. "] " .. "started.") local chain_complete_list = { default = { { complete_items = { "lsp", "snippet" } }, { complete_items = { "path" }, triggered_only = { "/" } }, { complete_items = { "buffers" } }, }, string = { { complete_items = { "path" }, triggered_only = { "/" } }, }, comment = {}, } require("completion").on_attach({ sorting = "length", enable_auto_popup = false, chain_complete_list = chain_complete_list, }) -- hook lsp into vim autocomplete in insert mode vim.api.nvim_buf_set_option(buffer_number, 'omnifunc', 'v:lua.vim.lsp.omnifunc') local map = function(type, key, value) vim.api.nvim_buf_set_keymap(buffer_number, type, key, value, { noremap = true, silent = true }) end map("n", "gD", "lua vim.lsp.buf.declaration()") map("n", "gd", "lua vim.lsp.buf.definition()") map("n", "K", "lua vim.lsp.buf.hover()") map("n", "gr", "lua vim.lsp.buf.references()") map("n", "gs", "lua vim.lsp.buf.signature_help()") map("n", "gi", "lua vim.lsp.buf.implementation()") map("n", "gt", "lua vim.lsp.buf.type_definition()") map("n", "gw", "lua vim.lsp.buf.document_symbol()") map("n", "gW", "lua vim.lsp.buf.workspace_symbol()") map("n", "ah", "lua vim.lsp.buf.hover()") map("n", "af", "lua vim.lsp.buf.code_action()") map("n", "ar", "lua vim.lsp.buf.rename()") map("n", "=", "lua vim.lsp.buf.formatting()") map("n", "ai", "lua vim.lsp.buf.incoming_calls()") map("n", "ao", "lua vim.lsp.buf.outgoing_calls()") map("n", "n", "lua vim.lsp.diagnostic.goto_next()") map("n", "N", "lua vim.lsp.diagnostic.goto_prev()") map("n", "", "lua vim.lsp.diagnostic.show_line_diagnostics()") end local lsp = require("lspconfig") -- Nvim lua configuration LSP local neovim_runtime_path = vim.split(package.path, ";") table.insert(neovim_runtime_path, "lua/?.lua") table.insert(neovim_runtime_path, "lua/?/init.lua") 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 local neovim_lua_library = {} for _, path in pairs(vim.api.nvim_list_runtime_paths()) do local lua_path = path .. "/lua/" if vim.fn.isdirectory(lua_path) then neovim_lua_library[lua_path] = true end end local sumneko_home = "~/Workspace/sua-language-server" if system_name == "Windows" then sumneko_home = "W:/misc/lua-language-server" end -- This loads the `lua` files from nvim into the runtime. neovim_lua_library[vim.fn.expand("$VIMRUNTIME/lua")] = true --TODO: How to switch this configuration based upon if we are editing neovim configuration or just any Lua file/project? lsp.sumneko_lua.setup({ on_attach = integrate_into_neovim, cmd = { sumneko_home .. "/bin/" .. system_name .. "/lua-language-server", "-E", "-W", sumneko_home .. "/main.lua", }, settings = { Lua = { runtime = { version = "LuaJIT", path = neovim_runtime_path, }, diagnostics = { enable = true, disable = "trailing-space", globals = { "vim" }, }, hint = { enable = true, }, workspace = { library = neovim_lua_library, maxPreload = 10000, preloadFileSize = 10000, }, telemetry = { enable = true, }, globals = { "cheatsheet", }, }, }, }) -- Markdown Notes (Zettelkasten) LSP lsp.zeta_note.setup({ on_attach = integrate_into_neovim, cmd = { "zeta-note" }, }) -- YAML LSP lsp.yamlls.setup({ on_attach = integrate_into_neovim, --FIXME: Only works on Windows cmd = { "yaml-language-server.cmd", "--stdio" }, root_dir = function() return vim.fn.getcwd() end, }) -- Zig LSP -- FIXME: ZLS is very tied to the specific version of the zig compiler one uses. -- we need to build our own version for 0.8.0 because it is not done upstream yet -- lsp.zls.setup({ on_attach = integrate_into_neovim }) -- LLVM Clang LSP lsp.clangd.setup({ on_attach = integrate_into_neovim }) -- JSON LSP lsp.jsonls.setup({ on_attach = integrate_into_neovim, cmd = { "vscode-json-language-server.cmd", "--stdio" }, commands = { Format = { -- Apply the ranged formatting to the whole file function() vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 }) end, }, }, }) -- GraphViz Dot LSP lsp.dotls.setup({ on_attach = integrate_into_neovim }) -- Null-ls local nls = require("null-ls") nls.setup({ debug = false, sources = { nls.builtins.formatting.stylua.with({ args = { "-s", "$FILENAME" }, to_stdin = false, }), }, on_attach = integrate_into_neovim, }) end