feat: rewrite some known plugins to lazy specs instead of luarocks (plenary.nvim). Closes #1540

This commit is contained in:
Folke Lemaitre 2024-06-24 21:57:34 +02:00
parent 1446f6cfbb
commit a089d43dba
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 28 additions and 2 deletions

View File

@ -14,6 +14,7 @@ M.dirty = false
---@class LazyPkgSpec ---@class LazyPkgSpec
---@field file string ---@field file string
---@field source? string
---@field spec? LazySpec ---@field spec? LazySpec
---@field code? string ---@field code? string
@ -54,7 +55,7 @@ function M.update()
local pkg = { local pkg = {
name = plugin.name, name = plugin.name,
dir = plugin.dir, dir = plugin.dir,
source = source.name, source = spec.source or source.name,
file = spec.file, file = spec.file,
spec = spec.spec or {}, spec = spec.spec or {},
} }

View File

@ -7,6 +7,10 @@ local M = {}
M.dev_suffix = "-1.rockspec" M.dev_suffix = "-1.rockspec"
M.skip = { "lua" } M.skip = { "lua" }
M.rewrites = {
["plenary.nvim"] = { "nvim-lua/plenary.nvim", lazy = true },
}
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M.deps(plugin) function M.deps(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name local root = Config.options.rocks.root .. "/" .. plugin.name
@ -32,6 +36,14 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
---@return LazyPkgSpec? ---@return LazyPkgSpec?
function M.get(plugin) function M.get(plugin)
if M.rewrites[plugin.name] then
return {
file = "rewrite",
source = "lazy",
spec = M.rewrites[plugin.name],
}
end
local rockspec_file ---@type string? local rockspec_file ---@type string?
Util.ls(plugin.dir, function(path, name, t) Util.ls(plugin.dir, function(path, name, t)
if t == "file" and name:sub(-#M.dev_suffix) == M.dev_suffix then if t == "file" and name:sub(-#M.dev_suffix) == M.dev_suffix then
@ -59,9 +71,16 @@ function M.get(plugin)
local has_lua = not not vim.uv.fs_stat(plugin.dir .. "/lua") local has_lua = not not vim.uv.fs_stat(plugin.dir .. "/lua")
---@type LazyPluginSpec
local rewrites = {}
---@param dep string ---@param dep string
local rocks = vim.tbl_filter(function(dep) local rocks = vim.tbl_filter(function(dep)
local name = dep:gsub("%s.*", "") local name = dep:gsub("%s.*", "")
if M.rewrites[name] then
table.insert(rewrites, M.rewrites[name])
return false
end
return not vim.tbl_contains(M.skip, name) return not vim.tbl_contains(M.skip, name)
end, rockspec.dependencies or {}) end, rockspec.dependencies or {})
@ -75,6 +94,12 @@ function M.get(plugin)
) )
if not use then if not use then
if #rewrites > 0 then
return {
file = vim.fn.fnamemodify(rockspec_file, ":t"),
spec = rewrites,
}
end
return return
end end
@ -90,7 +115,7 @@ function M.get(plugin)
build = "rockspec", build = "rockspec",
lazy = lazy, lazy = lazy,
}, },
} or nil }
end end
return M return M