diff --git a/nvim/lua/user/plugins/core.lua b/nvim/lua/user/plugins/core.lua index bb521f5..7987146 100644 --- a/nvim/lua/user/plugins/core.lua +++ b/nvim/lua/user/plugins/core.lua @@ -1,5 +1,15 @@ return { { import = "user.plugins.core.colorscheme" }, + { + "williamboman/mason.nvim", + build = ":MasonUpdate", + cmd = "Mason", + opts_extend = { "ensure_installed" }, + opts = {}, + config = function(_, opts) + require("mason").setup(opts) + end + }, -- Icons { 'nvim-tree/nvim-web-devicons', diff --git a/nvim/lua/user/plugins/lsp.lua b/nvim/lua/user/plugins/lsp.lua index 73ad568..0aa719c 100644 --- a/nvim/lua/user/plugins/lsp.lua +++ b/nvim/lua/user/plugins/lsp.lua @@ -3,6 +3,13 @@ return { -- event = "InsertEnter", lazy = true, dependencies = { + { + "williamboman/mason.nvim", + optional = true, + dependencies = { + { "williamboman/mason-lspconfig.nvim", config = function () end } + } + }, { -- Autocomplete source "hrsh7th/nvim-cmp", @@ -59,7 +66,12 @@ return { vim.lsp.protocol.make_client_capabilities() or {}, has_cmp and cmp_lsp.default_capabilities() or {}) - for name, server_opts in pairs(opts.servers) do + local function setup(server) + local server_opts = opts.servers[server] + + if type(server_opts) == "function" then + server_opts = server_opts() + end local features = vim.tbl_deep_extend("force", { codelens = opts.codelens, @@ -99,7 +111,30 @@ return { capabilities = capabilities }, server_opts or {}) - lspconfig[name].setup(server_opts) + lspconfig[server].setup(server_opts) + end + + local have_mason, mlsp = pcall(require, "mason-lspconfig") + + local all_mslp_servers = {} + if have_mason then + all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package) + end + + local ensure_installed = {} ---@type string[] + for name, server_opts in pairs(opts.servers) do + if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, name) then + setup(name) + else + ensure_installed[#ensure_installed + 1] = name + end + end + + if have_mason then + mlsp.setup({ + ensure_installed = ensure_installed, + handlers = { setup }, + }) end end, }