Skip to content

Fix setting up mason.nvim and mason-lspconfig.nvim #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -572,11 +576,6 @@ require('which-key').register({
['<leader>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.
--
Expand Down Expand Up @@ -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 ]]
Expand Down