diff options
| author | William Boman <william@redwill.se> | 2025-04-28 01:03:22 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-04-28 01:04:53 +0200 |
| commit | 6b2ba82e34d393e85374148a2b3a2009a41269d4 (patch) | |
| tree | 9f76703cffc85547f8b7ef0684d19046a16973fb /lua | |
| parent | fix: fix module imports (diff) | |
| download | mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar.gz mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar.bz2 mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar.lz mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar.xz mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.tar.zst mason-lspconfig-6b2ba82e34d393e85374148a2b3a2009a41269d4.zip | |
fix: enable servers outside of registry.refresh() and vim.schedule() callbacks
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-lspconfig/features/automatic_enable.lua | 27 | ||||
| -rw-r--r-- | lua/mason-lspconfig/init.lua | 10 |
2 files changed, 27 insertions, 10 deletions
diff --git a/lua/mason-lspconfig/features/automatic_enable.lua b/lua/mason-lspconfig/features/automatic_enable.lua index 34ae265..79ab99a 100644 --- a/lua/mason-lspconfig/features/automatic_enable.lua +++ b/lua/mason-lspconfig/features/automatic_enable.lua @@ -3,6 +3,8 @@ local mappings = require "mason-lspconfig.mappings" local registry = require "mason-registry" local settings = require "mason-lspconfig.settings" +local enabled_servers = {} + ---@param mason_pkg string | Package local function enable_server(mason_pkg) if type(mason_pkg) ~= "string" then @@ -12,6 +14,9 @@ local function enable_server(mason_pkg) if not lspconfig_name then return end + if enabled_servers[lspconfig_name] then + return + end local automatic_enable = settings.current.automatic_enable @@ -40,15 +45,21 @@ local function enable_server(mason_pkg) end vim.lsp.enable(lspconfig_name) + enabled_servers[lspconfig_name] = true end local enable_server_scheduled = vim.schedule_wrap(enable_server) -return function() - _.each(enable_server, registry.get_installed_package_names()) - - -- We deregister the event handler primarily for testing purposes where .setup() is called multiple times in the - -- same instance - registry:off("package:install:success", enable_server_scheduled) - registry:on("package:install:success", enable_server_scheduled) -end +return { + init = function() + enabled_servers = {} + _.each(enable_server, registry.get_installed_package_names()) + -- We deregister the event handler primarily for testing purposes where .setup() is called multiple times in the + -- same instance. + registry:off("package:install:success", enable_server_scheduled) + registry:on("package:install:success", enable_server_scheduled) + end, + enable_all = function() + _.each(enable_server, registry.get_installed_package_names()) + end, +} diff --git a/lua/mason-lspconfig/init.lua b/lua/mason-lspconfig/init.lua index 771610a..c886285 100644 --- a/lua/mason-lspconfig/init.lua +++ b/lua/mason-lspconfig/init.lua @@ -25,16 +25,22 @@ function M.setup(config) check_and_notify_bad_setup_order() local registry = require "mason-registry" - registry.refresh(vim.schedule_wrap(function() + registry.refresh(vim.schedule_wrap(function(success, updated_registries) if not platform.is_headless and #settings.current.ensure_installed > 0 then require "mason-lspconfig.features.ensure_installed"() end - require "mason-lspconfig.features.automatic_enable"() + if success and #updated_registries > 0 and settings.current.automatic_enable ~= false then + require("mason-lspconfig.features.automatic_enable").enable_all() + end registry.register_package_aliases(_.map(function(server_name) return { server_name } end, require("mason-lspconfig.mappings").get_mason_map().package_to_lspconfig)) end)) + if settings.current.automatic_enable ~= false then + require("mason-lspconfig.features.automatic_enable").init() + end + require "mason-lspconfig.api.command" end |
