mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-19 21:06:46 +00:00
feat: spec.rocks is no longer needed & added support for installing any luarock
This commit is contained in:
parent
66249054c4
commit
73ea05feda
10 changed files with 120 additions and 235 deletions
|
@ -226,9 +226,6 @@ M.mapleader = nil
|
|||
---@type string
|
||||
M.maplocalleader = nil
|
||||
|
||||
---@type {specs:string, tree:string, path:string, cpath:string}
|
||||
M.rocks = {}
|
||||
|
||||
function M.headless()
|
||||
return #vim.api.nvim_list_uis() == 0
|
||||
end
|
||||
|
@ -279,17 +276,6 @@ function M.setup(opts)
|
|||
M.mapleader = vim.g.mapleader
|
||||
M.maplocalleader = vim.g.maplocalleader
|
||||
|
||||
M.rocks = {
|
||||
specs = M.options.rocks.root .. "/specs",
|
||||
tree = M.options.rocks.root .. "/tree",
|
||||
path = M.options.rocks.root .. "/tree/share/lua/5.1",
|
||||
cpath = M.options.rocks.root .. "/tree/lib/lua/5.1",
|
||||
}
|
||||
vim.fn.mkdir(M.rocks.specs, "p")
|
||||
vim.fn.mkdir(M.rocks.tree, "p")
|
||||
package.path = package.path .. ";" .. M.rocks.path .. "/?.lua;" .. M.rocks.path .. "/?/init.lua;"
|
||||
package.cpath = package.cpath .. ";" .. M.rocks.cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
|
||||
|
||||
if M.headless() then
|
||||
require("lazy.view.commands").setup()
|
||||
end
|
||||
|
|
|
@ -69,9 +69,8 @@ function M.install_missing()
|
|||
for _, plugin in pairs(Config.plugins) do
|
||||
local installed = plugin._.installed
|
||||
local has_errors = Plugin.has_errors(plugin)
|
||||
local rocks_installed = plugin._.rocks_installed ~= false
|
||||
|
||||
if not has_errors and not (installed and rocks_installed) then
|
||||
if not has_errors and not (installed and not plugin._.build) then
|
||||
for _, colorscheme in ipairs(Config.options.install.colorscheme) do
|
||||
if colorscheme == "default" then
|
||||
break
|
||||
|
@ -344,6 +343,10 @@ function M._load(plugin, reason, opts)
|
|||
|
||||
M.add_to_rtp(plugin)
|
||||
|
||||
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
|
||||
M.add_to_luapath(plugin)
|
||||
end
|
||||
|
||||
if plugin.dependencies then
|
||||
Util.try(function()
|
||||
M.load(plugin.dependencies, {})
|
||||
|
@ -487,6 +490,15 @@ function M.add_to_rtp(plugin)
|
|||
vim.opt.rtp = rtp
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
function M.add_to_luapath(plugin)
|
||||
local root = Config.options.rocks.root .. "/" .. plugin.name
|
||||
local path = root .. "/share/lua/5.1"
|
||||
local cpath = root .. "/lib/lua/5.1"
|
||||
package.path = package.path .. ";" .. path .. "/?.lua;" .. path .. "/?/init.lua;"
|
||||
package.cpath = package.cpath .. ";" .. cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
|
||||
end
|
||||
|
||||
function M.source(path)
|
||||
Util.track({ runtime = path })
|
||||
Util.try(function()
|
||||
|
|
|
@ -33,10 +33,11 @@ function M:load_pkgs()
|
|||
if not Config.options.pkg.enabled then
|
||||
return
|
||||
end
|
||||
local specs = Pkg.spec()
|
||||
for dir, spec in pairs(specs) do
|
||||
local meta, fragment = self:add(spec)
|
||||
local specs = Pkg.get()
|
||||
for dir, pkg in pairs(specs) do
|
||||
local meta, fragment = self:add(pkg.spec)
|
||||
if meta and fragment then
|
||||
meta._.pkg = pkg
|
||||
-- tag all package fragments as optional
|
||||
for _, fid in ipairs(meta._.frags) do
|
||||
local frag = self.fragments:get(fid)
|
||||
|
@ -165,18 +166,23 @@ function M:_rebuild(name)
|
|||
|
||||
assert(#plugin._.frags > 0, "no fragments found for plugin " .. name)
|
||||
|
||||
---@type table<number, boolean>
|
||||
local done = {}
|
||||
for _, fid in ipairs(plugin._.frags) do
|
||||
local fragment = self.fragments:get(fid)
|
||||
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
super = setmetatable(fragment.spec, super and { __index = super } or nil)
|
||||
plugin._.dep = plugin._.dep and fragment.dep
|
||||
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
|
||||
plugin.url = fragment.url or plugin.url
|
||||
if not done[fid] then
|
||||
done[fid] = true
|
||||
local fragment = self.fragments:get(fid)
|
||||
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
super = setmetatable(fragment.spec, super and { __index = super } or nil)
|
||||
plugin._.dep = plugin._.dep and fragment.dep
|
||||
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
|
||||
plugin.url = fragment.url or plugin.url
|
||||
|
||||
-- dependencies
|
||||
for _, dep in ipairs(fragment.deps or {}) do
|
||||
table.insert(plugin.dependencies, self.fragments:get(dep).name)
|
||||
-- dependencies
|
||||
for _, dep in ipairs(fragment.deps or {}) do
|
||||
table.insert(plugin.dependencies, self.fragments:get(dep).name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -236,7 +236,7 @@ function M.update_state()
|
|||
installed[name] = nil
|
||||
end
|
||||
|
||||
require("lazy.manage.rocks").update_state()
|
||||
M.update_rocks_state()
|
||||
|
||||
Config.to_clean = {}
|
||||
for pack, dir_type in pairs(installed) do
|
||||
|
@ -253,6 +253,23 @@ function M.update_state()
|
|||
end
|
||||
end
|
||||
|
||||
function M.update_rocks_state()
|
||||
local root = Config.options.rocks.root
|
||||
---@type table<string,string>
|
||||
local installed = {}
|
||||
Util.ls(root, function(_, name, type)
|
||||
if type == "directory" then
|
||||
installed[name] = name
|
||||
end
|
||||
end)
|
||||
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
|
||||
plugin._.build = not installed[plugin.name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param path string
|
||||
function M.local_spec(path)
|
||||
local file = vim.secure.read(path)
|
||||
|
@ -321,11 +338,11 @@ function M.load()
|
|||
-- copy state. This wont do anything during startup
|
||||
for name, plugin in pairs(existing) do
|
||||
if Config.plugins[name] then
|
||||
local dep = Config.plugins[name]._.dep
|
||||
local frags = Config.plugins[name]._.frags
|
||||
local new_state = Config.plugins[name]._
|
||||
Config.plugins[name]._ = plugin._
|
||||
Config.plugins[name]._.dep = dep
|
||||
Config.plugins[name]._.frags = frags
|
||||
Config.plugins[name]._.dep = new_state.dep
|
||||
Config.plugins[name]._.frags = new_state.frags
|
||||
-- Config.plugins[name]._.tasks = new_state.tasks
|
||||
end
|
||||
end
|
||||
Util.track()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue