From 86dbd56d31aa91c0bd483028f130bf4bb463fc6c Mon Sep 17 00:00:00 2001 From: William Boman Date: Wed, 21 Feb 2024 00:08:21 +0100 Subject: [PATCH] Fix setting up mason.nvim and mason-lspconfig.nvim These are currently being set up twice: - mason.nvim once by lazy.nvim (`config = true`) and then once manually - mason-lspconfig.nvim twice manually --- init.lua | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/init.lua b/init.lua index fd4567d9..9b041cb7 100644 --- a/init.lua +++ b/init.lua @@ -83,7 +83,7 @@ require('lazy').setup({ 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs to stdpath for neovim - { 'williamboman/mason.nvim', config = true }, + 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', -- Useful status updates for LSP @@ -507,6 +507,10 @@ vim.defer_fn(function() } end, 0) +-- [[ Configure Mason ]] +-- See `:help mason.nvim` +require('mason').setup() + -- [[ Configure LSP ]] -- This function gets run when an LSP connects to a particular buffer. local on_attach = function(_, bufnr) @@ -572,11 +576,6 @@ require('which-key').register({ ['h'] = { 'Git [H]unk' }, }, { mode = 'v' }) --- mason-lspconfig requires that these setup functions are called in this order --- before setting up the servers. -require('mason').setup() -require('mason-lspconfig').setup() - -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- @@ -610,22 +609,21 @@ require('neodev').setup() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' - -mason_lspconfig.setup { +require('mason-lspconfig').setup { + -- Ensure the servers above are installed ensure_installed = vim.tbl_keys(servers), -} - -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - filetypes = (servers[server_name] or {}).filetypes, - } - end, + -- Automatic setup of installed servers + -- See `:help mason-lspconfig-automatic-server-setup` + handlers = { + function(server_name) + require('lspconfig')[server_name].setup { + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + filetypes = (servers[server_name] or {}).filetypes, + } + end, + }, } -- [[ Configure nvim-cmp ]]