Skip to content

Commit

Permalink
fix: prevent mason setup from being run twice
Browse files Browse the repository at this point in the history
Addresses #1297

Currently, we're calling `require('mason').setup(...)` twice:
* once when setting it as a dependency of `nvim-lspconfig` (since we set
	`config = true`)
* once in the `config` function we define for `nvim-lspconfig`

Calling setup twice can cause issues with, e.g., setting the `PATH`
option: you might append Mason's bin dir in one setup call and prepend
it in the other.

We've kept the setup of `mason` in the `nvim-lspconfig` dependencies
table since leaving it to the `config` function caused some
plugin-loading-order related issues in the past. See:
* #210
* #554
* #555
* #865
  • Loading branch information
tomasgareau committed Jan 3, 2025
1 parent a8f5395 commit 95daefb
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,16 @@ require('lazy').setup({
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs and related tools to stdpath for Neovim
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
{
'williamboman/mason.nvim',
-- Mason must be loaded before its dependents so we'll define `opts`
-- here: this will make `lazy` automatically run
-- `require('mason').setup(opts)` when `nvim-lspconfig` loads.
opts = {
-- Add overrides for mason's default settings here if needed! e.g.:
-- log_level = vim.log.levels.DEBUG,
},
},
'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',

Expand Down Expand Up @@ -646,13 +655,16 @@ require('lazy').setup({
}

-- Ensure the servers and tools above are installed
-- To check the current status of installed tools and/or manually install
-- other tools, you can run
--
-- To check the current status of installed tools and/or manually install
-- other tools, you can run
-- :Mason
--
-- You can press `g?` for help in this menu.
require('mason').setup()

-- You can press `g?` for help in this menu.
--
-- `mason` had to be setup earlier: to configure its options see the
-- `dependencies` table for `nvim-lspconfig` above.
--
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.
local ensure_installed = vim.tbl_keys(servers or {})
Expand Down

0 comments on commit 95daefb

Please sign in to comment.