blob: ac41c03cceace3166e885b34590eeb9bf6c11dd5 (
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
47
48
49
50
51
52
53
54
|
---@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:get_installer()
local Optional = require "mason-core.optional"
return Optional.empty()
end
function LuaRegistrySource:get_display_name()
if self:is_installed() then
return ("require(%q)"):format(self.spec.mod)
else
return ("require(%q) [uninstalled]"):format(self.spec.mod)
end
end
function LuaRegistrySource:__tostring()
return ("LuaRegistrySource(mod=%s)"):format(self.spec.mod)
end
return LuaRegistrySource
|