From 6eeb393859ffea8d903ba39ef464e7a4d1339e1d Mon Sep 17 00:00:00 2001 From: tiago Date: Mon, 29 Jan 2024 19:28:59 +0000 Subject: [PATCH] lsp with custom server handlers and disabled lazy nvim notification --- .config/nvim/lua/tsousa/lazy.lua | 6 ++- .config/nvim/lua/tsousa/plugins/init.lua | 1 + .config/nvim/lua/tsousa/plugins/lsp.lua | 59 +++++++++++++----------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.config/nvim/lua/tsousa/lazy.lua b/.config/nvim/lua/tsousa/lazy.lua index d3d110d..1b3f8c7 100644 --- a/.config/nvim/lua/tsousa/lazy.lua +++ b/.config/nvim/lua/tsousa/lazy.lua @@ -11,5 +11,7 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) -require("lazy").setup("tsousa.plugins") - +require("lazy").setup( + "tsousa.plugins", + { change_detection = { notify = false } } +) diff --git a/.config/nvim/lua/tsousa/plugins/init.lua b/.config/nvim/lua/tsousa/plugins/init.lua index cc3085f..69f8fc6 100644 --- a/.config/nvim/lua/tsousa/plugins/init.lua +++ b/.config/nvim/lua/tsousa/plugins/init.lua @@ -3,4 +3,5 @@ return { "nvim-lua/plenary.nvim", "tpope/vim-surround", "github/copilot.vim", + "laytan/cloak.nvim", } diff --git a/.config/nvim/lua/tsousa/plugins/lsp.lua b/.config/nvim/lua/tsousa/plugins/lsp.lua index 6f256f6..8ac0e03 100644 --- a/.config/nvim/lua/tsousa/plugins/lsp.lua +++ b/.config/nvim/lua/tsousa/plugins/lsp.lua @@ -1,7 +1,6 @@ return { { "hrsh7th/nvim-cmp", - event = "InsertEnter", dependencies = { 'hrsh7th/cmp-nvim-lsp', -- lsp 'hrsh7th/cmp-nvim-lua', -- Nvim API completions @@ -190,6 +189,7 @@ return { { "neovim/nvim-lspconfig", dependencies = { + "hrsh7th/nvim-cmp", "williamboman/mason-lspconfig.nvim", "williamboman/mason.nvim", "j-hui/fidget.nvim", @@ -211,11 +211,42 @@ return { local mason_lspconfig = require("mason-lspconfig") + local lspconfig = require("lspconfig") + + -- ADD NVIM CMP AS A CAPABILITY + local lsp_defaults = lspconfig.util.default_config + + local capabilities = vim.tbl_deep_extend( + 'force', + lsp_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() + ) + mason_lspconfig.setup({ ensure_installed = { }, - automatic_installation = true + automatic_installation = true, + handlers = { + function(server_name) + lspconfig[server_name].setup({ + on_attach = on_attach, + on_init = on_init, + flags = lsp_flags, + capabilities = capabilities, + }) + end, + -- add here other custom overrides + ["lua_ls"] = function() + lspconfig.lua_ls.setup({ + settings = { + Lua = { + diagnostics = { globals = { "vim" } } + } + } + }) + end, + } }) local on_attach = function(client, bufnr) @@ -239,30 +270,6 @@ return { vim.keymap.set('n', 'fo', function() vim.lsp.buf.format { async = true } end, bufopts) vim.keymap.set('i', '', vim.lsp.buf.signature_help, bufopts) end - - local lspconfig = require("lspconfig") - - -- ADD NVIM CMP AS A CAPABILITY - local lsp_defaults = lspconfig.util.default_config - - local capabilities = vim.tbl_deep_extend( - 'force', - lsp_defaults.capabilities, - require('cmp_nvim_lsp').default_capabilities() - ) - - mason_lspconfig.setup_handlers({ - - -- This is a default handler that will be called for each installed server (also for new servers that are installed during a session) - function(server_name) - lspconfig[server_name].setup { - on_attach = on_attach, - on_init = on_init, - flags = lsp_flags, - capabilities = capabilities, - } - end, - }) end }, }