From bf087883b05082a07ec2abe22e904b227b21f0d3 Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 14 Mar 2023 04:48:03 +0100 Subject: feat: add registry.refresh() method (#1096) --- lua/mason-registry/sources/init.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lua/mason-registry/sources/init.lua') diff --git a/lua/mason-registry/sources/init.lua b/lua/mason-registry/sources/init.lua index 0e5e0d29..0739f40b 100644 --- a/lua/mason-registry/sources/init.lua +++ b/lua/mason-registry/sources/init.lua @@ -1,3 +1,5 @@ +local _ = require "mason-core.functional" + local M = {} ---@param registry_id string @@ -72,4 +74,25 @@ function M.iter(opts) end end +---@return boolean #Returns true if all sources are installed. +function M.is_installed() + for source in M.iter { include_uninstalled = true } do + if not source:is_installed() then + return false + end + end + return true +end + +---@return string # The sha256 checksum of the currently registered sources. +function M.checksum() + ---@type string[] + local registry_ids = {} + for source in M.iter { include_uninstalled = true } do + table.insert(registry_ids, source.id) + end + local checksum = _.compose(vim.fn.sha256, _.join "", _.sort_by(_.identity)) + return checksum(registry_ids) +end + return M -- cgit v1.2.3-70-g09d2