aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2026-05-18 23:23:19 +0200
committerGitHub <noreply@github.com>2026-05-18 23:23:19 +0200
commitcbf8d285e1462dd24acf3507817be2bbcb035919 (patch)
tree42a5b07705b1dd863bc47a2460073e433ab6e2a6 /lua
parentfeat: add the infrastructure to support "system" packages (#2085) (diff)
downloadmason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar.gz
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar.bz2
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar.lz
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar.xz
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.tar.zst
mason-cbf8d285e1462dd24acf3507817be2bbcb035919.zip
feat(registry): add registry_cache setting for controlling cache behaviour (#2089)HEADmain
* feat(registry): add registry_cache setting for controlling cache behaviour * fix: call callback if available
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-registry/init.lua22
-rw-r--r--lua/mason/settings.lua13
2 files changed, 27 insertions, 8 deletions
diff --git a/lua/mason-registry/init.lua b/lua/mason-registry/init.lua
index 1e59175c..523a1256 100644
--- a/lua/mason-registry/init.lua
+++ b/lua/mason-registry/init.lua
@@ -2,6 +2,7 @@ local EventEmitter = require "mason-core.EventEmitter"
local InstallLocation = require "mason-core.installer.InstallLocation"
local log = require "mason-core.log"
local path = require "mason-core.path"
+local settings = require "mason.settings"
local uv = vim.loop
local LazySourceCollection = require "mason-registry.sources"
@@ -165,34 +166,39 @@ function Registry.update(callback)
a.run(update, callback or noop, Registry.sources)
end
-local REGISTRY_STORE_TTL = 86400 -- 24 hrs
-
---@param sources LazySourceCollection
---@param callback? RegistryUpdateCallback
local function refresh(sources, callback)
+ if not settings.current.registry_cache.refresh then
+ log.debug "Not performing a registry refresh as it's disabled in settings."
+ if callback then
+ return callback(true, {})
+ end
+ return true, {}
+ end
local a = require "mason-core.async"
local state = sources:get_install_state()
if state and sources:is_all_installed() then
local registry_age = os.time() - state.timestamp
- if registry_age <= REGISTRY_STORE_TTL and state.checksum == sources:checksum() then
+ if registry_age <= settings.current.registry_cache.duration and state.checksum == sources:checksum() then
log.fmt_debug(
"Registry refresh is not necessary yet. Registry age=%d, checksum=%s",
registry_age,
state.checksum
)
if callback then
- callback(true, {})
+ return callback(true, {})
end
- return
+ return true, {}
end
end
if not callback then
-- We don't want to error in the synchronous version because of how this function is recommended to be used in
-- 3rd party code. If accessing the update result is required, users are recommended to pass a callback.
- pcall(a.run_blocking, update, sources)
+ return pcall(a.run_blocking, update, sources)
else
a.run(update, callback, sources)
end
@@ -201,13 +207,13 @@ end
---@param callback? RegistryUpdateCallback
function Registry.refresh(callback)
log.debug "Refreshing the registry."
- refresh(Registry.sources, callback)
+ return refresh(Registry.sources, callback)
end
---@param callback? RegistryUpdateCallback
function Registry.refresh_system(callback)
log.debug "Refreshing the system registry."
- refresh(Registry.system_sources, callback)
+ return refresh(Registry.system_sources, callback)
end
return Registry
diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua
index 1788c035..1c72756b 100644
--- a/lua/mason/settings.lua
+++ b/lua/mason/settings.lua
@@ -42,6 +42,19 @@ local DEFAULT_SETTINGS = {
"github:mason-org/mason-system-registry",
},
+ registry_cache = {
+ ---@since 2.3.0
+ -- [Advanced setting]
+ -- Whether Mason should automatically refresh the registry when needed. If false, the registry will have to be
+ -- updated manually via :MasonUpdate or the :Mason UI.
+ refresh = true,
+
+ ---@since 2.3.0
+ -- Amount of seconds before the local registry cache is considered stale.
+ -- Note that this setting has no effect if refresh is set to false.
+ duration = 24 * 60 * 60, -- 24 hours
+ },
+
---@since 1.0.0
-- The provider implementations to use for resolving supplementary package metadata (e.g., all available versions).
-- Accepts multiple entries, where later entries will be used as fallback should prior providers fail.