-- LSP config local nvim_lsp = require("lspconfig") function setup() -- 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 keymap_set(...) 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 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 keymap_set("n", "gD", "lua vim.lsp.buf.declaration()", opts) keymap_set("n", "gd", "lua vim.lsp.buf.definition()", opts) keymap_set("n", "K", "lua vim.lsp.buf.hover()", opts) keymap_set("n", "gi", "lua vim.lsp.buf.implementation()", opts) keymap_set("n", "", "lua vim.lsp.buf.signature_help()", opts) keymap_set("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) keymap_set("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) keymap_set("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) keymap_set("n", "D", "lua vim.lsp.buf.type_definition()", opts) keymap_set("n", "rn", "lua vim.lsp.buf.rename()", opts) keymap_set("n", "ca", "lua vim.lsp.buf.code_action()", opts) keymap_set("n", "gr", "lua vim.lsp.buf.references()", opts) keymap_set("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) keymap_set("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) keymap_set("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) keymap_set("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) keymap_set("n", "f", "lua vim.lsp.buf.formatting()", opts) end local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) -- Enable the following language servers local servers = { "clangd", "rust_analyzer", "pyright", "tsserver", "rnix", "sumneko_lua" } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, capabilities = capabilities, } end end return { setup = setup, }