Skip to content

Commit 56c5984

Browse files
tomasgareauandreacanton
authored andcommitted
fix: prevent mason setup from being run twice (nvim-lua#1298)
* fix: prevent mason setup from being run twice Addresses nvim-lua#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: * nvim-lua#210 * nvim-lua#554 * nvim-lua#555 * nvim-lua#865 * docs: tweak comments per review feedback
1 parent d1852a4 commit 56c5984

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
@@ -464,7 +464,9 @@ require('lazy').setup({
464464
'neovim/nvim-lspconfig',
465465
dependencies = {
466466
-- Automatically install LSPs and related tools to stdpath for Neovim
467-
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
467+
-- Mason must be loaded before its dependents so we need to set it up here.
468+
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
469+
{ 'williamboman/mason.nvim', opts = {} },
468470
'williamboman/mason-lspconfig.nvim',
469471
'WhoIsSethDaniel/mason-tool-installer.nvim',
470472

@@ -653,13 +655,16 @@ require('lazy').setup({
653655
}
654656

655657
-- Ensure the servers and tools above are installed
656-
-- To check the current status of installed tools and/or manually install
657-
-- other tools, you can run
658+
--
659+
-- To check the current status of installed tools and/or manually install
660+
-- other tools, you can run
658661
-- :Mason
659662
--
660-
-- You can press `g?` for help in this menu.
661-
require('mason').setup()
662-
663+
-- You can press `g?` for help in this menu.
664+
--
665+
-- `mason` had to be setup earlier: to configure its options see the
666+
-- `dependencies` table for `nvim-lspconfig` above.
667+
--
663668
-- You can add other tools here that you want Mason to install
664669
-- for you, so that they are available from within Neovim.
665670
local ensure_installed = vim.tbl_keys(servers or {})

0 commit comments

Comments
 (0)