Skip to content

Commit

Permalink
feat: rewrite some known plugins to lazy specs instead of luarocks (p…
Browse files Browse the repository at this point in the history
…lenary.nvim). Closes #1540
  • Loading branch information
folke committed Jun 24, 2024
1 parent 1446f6c commit a089d43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lua/lazy/pkg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ M.dirty = false

---@class LazyPkgSpec
---@field file string
---@field source? string
---@field spec? LazySpec
---@field code? string

Expand Down Expand Up @@ -54,7 +55,7 @@ function M.update()
local pkg = {
name = plugin.name,
dir = plugin.dir,
source = source.name,
source = spec.source or source.name,
file = spec.file,
spec = spec.spec or {},
}
Expand Down
27 changes: 26 additions & 1 deletion lua/lazy/pkg/rockspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ local M = {}
M.dev_suffix = "-1.rockspec"
M.skip = { "lua" }

M.rewrites = {
["plenary.nvim"] = { "nvim-lua/plenary.nvim", lazy = true },
}

---@param plugin LazyPlugin
function M.deps(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name
Expand All @@ -32,6 +36,14 @@ end
---@param plugin LazyPlugin
---@return LazyPkgSpec?
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?
Util.ls(plugin.dir, function(path, name, t)
if t == "file" and name:sub(-#M.dev_suffix) == M.dev_suffix then
Expand Down Expand Up @@ -59,9 +71,16 @@ function M.get(plugin)

local has_lua = not not vim.uv.fs_stat(plugin.dir .. "/lua")

---@type LazyPluginSpec
local rewrites = {}

---@param dep string
local rocks = vim.tbl_filter(function(dep)
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)
end, rockspec.dependencies or {})

Expand All @@ -75,6 +94,12 @@ function M.get(plugin)
)

if not use then
if #rewrites > 0 then
return {
file = vim.fn.fnamemodify(rockspec_file, ":t"),
spec = rewrites,
}
end
return
end

Expand All @@ -90,7 +115,7 @@ function M.get(plugin)
build = "rockspec",
lazy = lazy,
},
} or nil
}
end

return M

0 comments on commit a089d43

Please sign in to comment.