aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-registry/sources/lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/mason-registry/sources/lua.lua')
-rw-r--r--lua/mason-registry/sources/lua.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/lua/mason-registry/sources/lua.lua b/lua/mason-registry/sources/lua.lua
new file mode 100644
index 00000000..94b4e4f8
--- /dev/null
+++ b/lua/mason-registry/sources/lua.lua
@@ -0,0 +1,43 @@
+---@class LuaRegistrySourceSpec
+---@field id string
+---@field mod string
+
+---@class LuaRegistrySource : RegistrySource
+---@field private spec LuaRegistrySourceSpec
+local LuaRegistrySource = {}
+LuaRegistrySource.__index = LuaRegistrySource
+
+---@param spec LuaRegistrySourceSpec
+function LuaRegistrySource.new(spec)
+ return setmetatable({
+ spec = spec,
+ }, LuaRegistrySource)
+end
+
+function LuaRegistrySource:get_package(pkg_name)
+ local index = require(self.spec.mod)
+ if index[pkg_name] then
+ return require(index[pkg_name])
+ end
+end
+
+function LuaRegistrySource:get_all_package_names()
+ local index = require(self.spec.mod)
+ return vim.tbl_keys(index)
+end
+
+function LuaRegistrySource:is_installed()
+ local ok = pcall(require, self.spec.mod)
+ return ok
+end
+
+function LuaRegistrySource:install()
+ local Result = require "mason-core.result"
+ return Result.success()
+end
+
+function LuaRegistrySource:__tostring()
+ return ("LuaRegistry(mod=%s)"):format(self.spec.mod)
+end
+
+return LuaRegistrySource