Skip to content

Commit 5224e24

Browse files
tomasgareauna47io
authored andcommitted
fix: prevent mason setup from being run twice (#1298)
* fix: prevent mason setup from being run twice 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 * docs: tweak comments per review feedback
1 parent 98fc38b commit 5224e24

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

init.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ require('lazy').setup({
374374
'neovim/nvim-lspconfig',
375375
dependencies = {
376376
-- Automatically install LSPs and related tools to stdpath for Neovim
377-
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
377+
-- Mason must be loaded before its dependents so we need to set it up here.
378+
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
379+
{ 'williamboman/mason.nvim', opts = {} },
378380
'williamboman/mason-lspconfig.nvim',
379381
'WhoIsSethDaniel/mason-tool-installer.nvim',
380382

@@ -573,13 +575,16 @@ require('lazy').setup({
573575
}
574576

575577
-- Ensure the servers and tools above are installed
576-
-- To check the current status of installed tools and/or manually install
577-
-- other tools, you can run
578+
--
579+
-- To check the current status of installed tools and/or manually install
580+
-- other tools, you can run
578581
-- :Mason
579582
--
580-
-- You can press `g?` for help in this menu.
581-
require('mason').setup()
582-
583+
-- You can press `g?` for help in this menu.
584+
--
585+
-- `mason` had to be setup earlier: to configure its options see the
586+
-- `dependencies` table for `nvim-lspconfig` above.
587+
--
583588
-- You can add other tools here that you want Mason to install
584589
-- for you, so that they are available from within Neovim.
585590
local ensure_installed = vim.tbl_keys(servers or {})

0 commit comments

Comments
 (0)