aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-registry/sources
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-13 21:14:29 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:23:19 +0100
commitae208dc380808ff1aef39929a0e897e881571d43 (patch)
treeb9044cec7223062db69998189c76f8163ac9d58b /lua/mason-registry/sources
parentfix(location): use correct registry path (diff)
downloadmason-ae208dc380808ff1aef39929a0e897e881571d43.tar
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.gz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.bz2
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.lz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.xz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.zst
mason-ae208dc380808ff1aef39929a0e897e881571d43.zip
refactor: standardize constructors and improve inheritance construction
Diffstat (limited to 'lua/mason-registry/sources')
-rw-r--r--lua/mason-registry/sources/file.lua10
-rw-r--r--lua/mason-registry/sources/github.lua18
-rw-r--r--lua/mason-registry/sources/init.lua6
-rw-r--r--lua/mason-registry/sources/lua.lua12
-rw-r--r--lua/mason-registry/sources/util.lua2
5 files changed, 27 insertions, 21 deletions
diff --git a/lua/mason-registry/sources/file.lua b/lua/mason-registry/sources/file.lua
index bb53c28d..628b1253 100644
--- a/lua/mason-registry/sources/file.lua
+++ b/lua/mason-registry/sources/file.lua
@@ -23,10 +23,12 @@ local FileRegistrySource = {}
FileRegistrySource.__index = FileRegistrySource
---@param spec FileRegistrySourceSpec
-function FileRegistrySource.new(spec)
- return setmetatable({
- spec = spec,
- }, FileRegistrySource)
+function FileRegistrySource:new(spec)
+ ---@type FileRegistrySource
+ local instance = {}
+ setmetatable(instance, self)
+ instance.spec = spec
+ return instance
end
function FileRegistrySource:is_installed()
diff --git a/lua/mason-registry/sources/github.lua b/lua/mason-registry/sources/github.lua
index 81ccaf56..d0a782fb 100644
--- a/lua/mason-registry/sources/github.lua
+++ b/lua/mason-registry/sources/github.lua
@@ -31,15 +31,17 @@ local GitHubRegistrySource = {}
GitHubRegistrySource.__index = GitHubRegistrySource
---@param spec GitHubRegistrySourceSpec
-function GitHubRegistrySource.new(spec)
+function GitHubRegistrySource:new(spec)
+ ---@type GitHubRegistrySource
+ local instance = {}
+ setmetatable(instance, GitHubRegistrySource)
local root_dir = InstallLocation.global():registry(path.concat { "github", spec.namespace, spec.name })
- return setmetatable({
- id = spec.id,
- spec = spec,
- root_dir = root_dir,
- data_file = path.concat { root_dir, "registry.json" },
- info_file = path.concat { root_dir, "info.json" },
- }, GitHubRegistrySource)
+ instance.id = spec.id
+ instance.spec = spec
+ instance.root_dir = root_dir
+ instance.data_file = path.concat { root_dir, "registry.json" }
+ instance.info_file = path.concat { root_dir, "info.json" }
+ return instance
end
function GitHubRegistrySource:is_installed()
diff --git a/lua/mason-registry/sources/init.lua b/lua/mason-registry/sources/init.lua
index bdaaf38e..af1b9f6a 100644
--- a/lua/mason-registry/sources/init.lua
+++ b/lua/mason-registry/sources/init.lua
@@ -25,7 +25,7 @@ local function parse(registry_id)
local name, version = unpack(vim.split(name, "@"))
return function()
local GitHubRegistrySource = require "mason-registry.sources.github"
- return GitHubRegistrySource.new {
+ return GitHubRegistrySource:new {
id = registry_id,
repo = ("%s/%s"):format(namespace, name),
namespace = namespace,
@@ -36,7 +36,7 @@ local function parse(registry_id)
elseif type == "lua" then
return function()
local LuaRegistrySource = require "mason-registry.sources.lua"
- return LuaRegistrySource.new {
+ return LuaRegistrySource:new {
id = registry_id,
mod = id,
}
@@ -44,7 +44,7 @@ local function parse(registry_id)
elseif type == "file" then
return function()
local FileRegistrySource = require "mason-registry.sources.file"
- return FileRegistrySource.new {
+ return FileRegistrySource:new {
path = id,
}
end
diff --git a/lua/mason-registry/sources/lua.lua b/lua/mason-registry/sources/lua.lua
index 1ca88a8d..fd88a49d 100644
--- a/lua/mason-registry/sources/lua.lua
+++ b/lua/mason-registry/sources/lua.lua
@@ -12,11 +12,13 @@ local LuaRegistrySource = {}
LuaRegistrySource.__index = LuaRegistrySource
---@param spec LuaRegistrySourceSpec
-function LuaRegistrySource.new(spec)
- return setmetatable({
- id = spec.id,
- spec = spec,
- }, LuaRegistrySource)
+function LuaRegistrySource:new(spec)
+ ---@type LuaRegistrySource
+ local instance = {}
+ setmetatable(instance, LuaRegistrySource)
+ instance.id = spec.id
+ instance.spec = spec
+ return instance
end
---@param pkg_name string
diff --git a/lua/mason-registry/sources/util.lua b/lua/mason-registry/sources/util.lua
index 04ab7845..8be07010 100644
--- a/lua/mason-registry/sources/util.lua
+++ b/lua/mason-registry/sources/util.lua
@@ -35,7 +35,7 @@ M.hydrate_package = _.curryN(function(buffer, spec)
pkg.spec = spec
return pkg
end
- return Pkg.new(spec)
+ return Pkg:new(spec)
end, 2)
return M