aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-registry/sources/init.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2026-01-07 14:39:35 +0100
committerWilliam Boman <william@redwill.se>2026-01-07 14:39:35 +0100
commitad903f1c1f18fd229d67e523418b3aa6c9f1c862 (patch)
treed52cca80e062b3df9b8daeba20435aa83c34c7a2 /lua/mason-registry/sources/init.lua
parentfix(installer): update cwd after uv_fs_rename() was successful (#2033) (diff)
downloadmason-fix/support-removed-packages.tar
mason-fix/support-removed-packages.tar.gz
mason-fix/support-removed-packages.tar.bz2
mason-fix/support-removed-packages.tar.lz
mason-fix/support-removed-packages.tar.xz
mason-fix/support-removed-packages.tar.zst
mason-fix/support-removed-packages.zip
feat: add support for removal of packages from a registryfix/support-removed-packages
This adds support for removal of packages from any given registry. Currently mason.nvim doesn't support this at all and throws an error when trying to interact with the registry in any way while having a removed package installed locally. This ensures that removed packages are available both in the `:Mason` UI as well as the public Lua APIs. These "synthesized" packages only supports uninstallation, and metadata such as licenses, categories, homepage, etc is not available.
Diffstat (limited to 'lua/mason-registry/sources/init.lua')
-rw-r--r--lua/mason-registry/sources/init.lua17
1 files changed, 15 insertions, 2 deletions
diff --git a/lua/mason-registry/sources/init.lua b/lua/mason-registry/sources/init.lua
index 765d4904..f468a8ef 100644
--- a/lua/mason-registry/sources/init.lua
+++ b/lua/mason-registry/sources/init.lua
@@ -11,7 +11,7 @@ local log = require "mason-core.log"
---@field serialize fun(self: RegistrySource): InstallReceiptRegistry
---@field is_same_location fun(self: RegistrySource, other: RegistrySource): boolean
----@alias RegistrySourceType '"github"' | '"lua"' | '"file"'
+---@alias RegistrySourceType '"github"' | '"lua"' | '"file"' | '"synthesized"'
---@class LazySource
---@field type RegistrySourceType
@@ -54,6 +54,11 @@ function LazySource.File(id)
}
end
+function LazySource.Synthesized()
+ local SynthesizedSource = require "mason-registry.sources.synthesized"
+ return SynthesizedSource:new()
+end
+
---@param type RegistrySourceType
---@param id string
---@param init fun(id: string): RegistrySource
@@ -115,6 +120,7 @@ end
---@class LazySourceCollection
---@field list LazySource[]
+---@field synthesized LazySource
local LazySourceCollection = {}
LazySourceCollection.__index = LazySourceCollection
@@ -123,6 +129,7 @@ function LazySourceCollection:new()
local instance = {}
setmetatable(instance, self)
instance.list = {}
+ instance.synthesized = LazySource:new("synthesized", "synthesized", LazySource.Synthesized)
return instance
end
@@ -184,7 +191,7 @@ function LazySourceCollection:checksum()
return vim.fn.sha256(table.concat(registry_ids, ""))
end
----@param opts? { include_uninstalled?: boolean }
+---@param opts? { include_uninstalled?: boolean, include_synthesized?: boolean }
function LazySourceCollection:iterate(opts)
opts = opts or {}
@@ -197,6 +204,12 @@ function LazySourceCollection:iterate(opts)
return source
end
end
+
+ -- We've exhausted the true registry sources, fall back to the synthesized registry source.
+ if idx == #self.list + 1 and opts.include_synthesized ~= false then
+ idx = idx + 1
+ return self.synthesized:get()
+ end
end
end