blob: d2032cc033a787a6d25ac5ee70f4c49651ed10ad (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
---@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
---@param pkg_name string
---@return Package?
function LuaRegistrySource:get_package(pkg_name)
local index = require(self.spec.mod)
if index[pkg_name] then
return require(index[pkg_name])
end
end
---@return string[]
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 ("LuaRegistrySource(mod=%s)"):format(self.spec.mod)
end
return LuaRegistrySource
|