-- 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 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 vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set("n", "wl", print(vim.inspect(vim.lsp.buf.list_workspace_folders, opts))) vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) vim.keymap.set("n", "e", vim.lsp.diagnostic.show_line_diagnostics, opts) vim.keymap.set("n", "[d", vim.lsp.diagnostic.goto_prev, opts) vim.keymap.set("n", "]d", vim.lsp.diagnostic.goto_next, opts) vim.keymap.set("n", "q", vim.lsp.diagnostic.set_loclist, opts) vim.keymap.set("n", "f", 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").default_capabilities(capabilities) -- Enable the following language servers local servers = { "clangd", "rust_analyzer", "pyright", "tsserver", "rnix", "lua_ls" } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup({ on_attach = on_attach, capabilities = capabilities, }) end end return { setup = setup, }