function setup_keymap_lsp() -- -- Global mappings. -- -- See `:help vim.diagnostic.*` for documentation on any of the below functions -- vim.keymap.set("n", "e", vim.diagnostic.open_float) -- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) -- vim.keymap.set("n", "]d", vim.diagnostic.goto_next) -- vim.keymap.set("n", "q", vim.diagnostic.setloclist) vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf } vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) vim.keymap.set("n", "K", vim.lsp.buf.hover, 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", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, 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", "v" }, "ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "f", function() vim.lsp.buf.format { async = true } end, opts) end, }) end return { { "neovim/nvim-lspconfig", enabled = full_feature, dependencies = { "hrsh7th/nvim-cmp", "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "hrsh7th/cmp-cmdline", "L3MON4D3/LuaSnip", }, lazy = false, config = function (_, opts) local capabilities = require("cmp_nvim_lsp").default_capabilities() local servers = { "clangd", "rust_analyzer", "pyright", "gopls", "quick_lint_js" } for _, lsp in ipairs(servers) do require("lspconfig")[lsp].setup{ capabilities = capabilities, } end local luasnip = require("luasnip") local cmp = require("cmp") cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "buffer" }, { name = "luasnip" }, }), }) cmp.setup.cmdline(":", { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) }) setup_keymap_lsp() end, keys = { { "e", vim.diagnostic.open_float, mode = "n" }, { "[d", vim.diagnostic.goto_prev, mode = "n" }, { "]d", vim.diagnostic.goto_next, mode = "n" }, { "q", vim.diagnostic.setloclist, mode = "n" } }, }, }