diff options
| author | William Boman <william@redwill.se> | 2023-02-20 22:19:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-20 22:19:39 +0100 |
| commit | b8a6632a0f2d263199d5d480ca85477fe0f414ab (patch) | |
| tree | 57e1ee0f3cef078ec144ecdf1b2fa861acf47755 /lua/mason-registry/sources/init.lua | |
| parent | chore: autogenerate (#1015) (diff) | |
| download | mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.gz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.bz2 mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.lz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.xz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.zst mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.zip | |
feat: configurable registries (#1016)
Diffstat (limited to 'lua/mason-registry/sources/init.lua')
| -rw-r--r-- | lua/mason-registry/sources/init.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lua/mason-registry/sources/init.lua b/lua/mason-registry/sources/init.lua new file mode 100644 index 00000000..39b7fad5 --- /dev/null +++ b/lua/mason-registry/sources/init.lua @@ -0,0 +1,57 @@ +local M = {} + +---@param registry_id string +---@return fun(): RegistrySource # Thunk to instantiate provider. +local function parse(registry_id) + local type, id = registry_id:match "^(.+):(.+)$" + if type == "lua" then + return function() + local LuaRegistrySource = require "mason-registry.sources.lua" + return LuaRegistrySource.new { + id = registry_id, + mod = id, + } + end + elseif type ~= nil then + error(("Unknown registry type %q: %q."):format(type, registry_id), 0) + end + error(("Malformed registry id: %q."):format(registry_id), 0) +end + +---@type ((fun(): RegistrySource) | RegistrySource)[] +local registries = {} + +---@param registry_ids string[] +function M.set_registries(registry_ids) + for _, registry in ipairs(registry_ids) do + local ok, err = pcall(function() + table.insert(registries, parse(registry)) + end) + if not ok then + local log = require "mason-core.log" + local notify = require "mason-core.notify" + log.fmt_error("Failed to parse registry %q: %s", registry, err) + notify(err, vim.log.levels.ERROR) + end + end +end + +function M.iter() + local i = 1 + return function() + while i <= #registries do + local registry = registries[i] + if type(registry) == "function" then + -- unwrap thunk + registry = registry() + registries[i] = registry + end + i = i + 1 + if registry:is_installed() then + return registry + end + end + end +end + +return M |
