Skip to content

Commit 7ee8ed6

Browse files
tomasgareauKevin Langmade
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 d45ff52 commit 7ee8ed6

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
@@ -434,7 +434,9 @@ require('lazy').setup({
434434
'neovim/nvim-lspconfig',
435435
dependencies = {
436436
-- Automatically install LSPs and related tools to stdpath for Neovim
437-
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
437+
-- Mason must be loaded before its dependents so we need to set it up here.
438+
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
439+
{ 'williamboman/mason.nvim', opts = {} },
438440
'williamboman/mason-lspconfig.nvim',
439441
'WhoIsSethDaniel/mason-tool-installer.nvim',
440442

@@ -623,13 +625,16 @@ require('lazy').setup({
623625
}
624626

625627
-- Ensure the servers and tools above are installed
626-
-- To check the current status of installed tools and/or manually install
627-
-- other tools, you can run
628+
--
629+
-- To check the current status of installed tools and/or manually install
630+
-- other tools, you can run
628631
-- :Mason
629632
--
630-
-- You can press `g?` for help in this menu.
631-
require('mason').setup()
632-
633+
-- You can press `g?` for help in this menu.
634+
--
635+
-- `mason` had to be setup earlier: to configure its options see the
636+
-- `dependencies` table for `nvim-lspconfig` above.
637+
--
633638
-- You can add other tools here that you want Mason to install
634639
-- for you, so that they are available from within Neovim.
635640
local ensure_installed = vim.tbl_keys(servers or {})

0 commit comments

Comments
 (0)