From 4bd04df779a77b5d3670ba76f5433bbad241c2c5 Mon Sep 17 00:00:00 2001 From: Pablu23 Date: Sun, 7 Jul 2024 16:16:02 +0200 Subject: [PATCH] Add handlers and capabilities default --- lua/plugins/lsp-config.lua | 97 ++++++++++++++------------------------ 1 file changed, 35 insertions(+), 62 deletions(-) diff --git a/lua/plugins/lsp-config.lua b/lua/plugins/lsp-config.lua index 406f3d7..e59c46d 100644 --- a/lua/plugins/lsp-config.lua +++ b/lua/plugins/lsp-config.lua @@ -1,68 +1,41 @@ return { - { + "neovim/nvim-lspconfig", + dependencies = { "williamboman/mason.nvim", - config = function() - require("mason").setup() - end, - }, - { "williamboman/mason-lspconfig.nvim", - config = function() - require("mason-lspconfig").setup({ - ensure_installed = { - "lua_ls", - "gopls", - "rust_analyzer", - "html", - "zls", - "pyright", - "ols", - }, - }) - end, }, - { - "neovim/nvim-lspconfig", - config = function() - local capabilities = require("cmp_nvim_lsp").default_capabilities() - local handlers = { - ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }), - ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }), - } + config = function() + local capabilities = require("cmp_nvim_lsp").default_capabilities() + local handlers = { + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }), + } - local lspconfig = require("lspconfig") - lspconfig.lua_ls.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.gopls.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.rust_analyzer.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.html.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.zls.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.pyright.setup({ - capabilities = capabilities, - handlers = handlers, - }) - lspconfig.ols.setup({ - capabilities = capabilities, - handlers = handlers, - }) - vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) - vim.keymap.set("n", "cr", vim.lsp.buf.rename, {}) - end, - }, + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = { + "lua_ls", + "gopls", + "rust_analyzer", + "html", + "zls", + "pyright", + "ols", + "clangd", + }, + handlers = { + function(server_name) + require("lspconfig")[server_name].setup { + capabilities = capabilities, + handlers = handlers + } + end + } + }) + + vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) + vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) + vim.keymap.set("n", "cr", vim.lsp.buf.rename, {}) + end, }