Skip to content

Commit fcfd548

Browse files
committed
feat: spec.rocks is no longer needed & added support for installing any luarock
1 parent b3ee5b9 commit fcfd548

File tree

10 files changed

+121
-236
lines changed

10 files changed

+121
-236
lines changed

lua/lazy/core/config.lua

-14
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ M.mapleader = nil
226226
---@type string
227227
M.maplocalleader = nil
228228

229-
---@type {specs:string, tree:string, path:string, cpath:string}
230-
M.rocks = {}
231-
232229
function M.headless()
233230
return #vim.api.nvim_list_uis() == 0
234231
end
@@ -279,17 +276,6 @@ function M.setup(opts)
279276
M.mapleader = vim.g.mapleader
280277
M.maplocalleader = vim.g.maplocalleader
281278

282-
M.rocks = {
283-
specs = M.options.rocks.root .. "/specs",
284-
tree = M.options.rocks.root .. "/tree",
285-
path = M.options.rocks.root .. "/tree/share/lua/5.1",
286-
cpath = M.options.rocks.root .. "/tree/lib/lua/5.1",
287-
}
288-
vim.fn.mkdir(M.rocks.specs, "p")
289-
vim.fn.mkdir(M.rocks.tree, "p")
290-
package.path = package.path .. ";" .. M.rocks.path .. "/?.lua;" .. M.rocks.path .. "/?/init.lua;"
291-
package.cpath = package.cpath .. ";" .. M.rocks.cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
292-
293279
if M.headless() then
294280
require("lazy.view.commands").setup()
295281
end

lua/lazy/core/loader.lua

+14-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ function M.install_missing()
6969
for _, plugin in pairs(Config.plugins) do
7070
local installed = plugin._.installed
7171
local has_errors = Plugin.has_errors(plugin)
72-
local rocks_installed = plugin._.rocks_installed ~= false
7372

74-
if not has_errors and not (installed and rocks_installed) then
73+
if not has_errors and not (installed and not plugin._.build) then
7574
for _, colorscheme in ipairs(Config.options.install.colorscheme) do
7675
if colorscheme == "default" then
7776
break
@@ -344,6 +343,10 @@ function M._load(plugin, reason, opts)
344343

345344
M.add_to_rtp(plugin)
346345

346+
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
347+
M.add_to_luapath(plugin)
348+
end
349+
347350
if plugin.dependencies then
348351
Util.try(function()
349352
M.load(plugin.dependencies, {})
@@ -487,6 +490,15 @@ function M.add_to_rtp(plugin)
487490
vim.opt.rtp = rtp
488491
end
489492

493+
---@param plugin LazyPlugin
494+
function M.add_to_luapath(plugin)
495+
local root = Config.options.rocks.root .. "/" .. plugin.name
496+
local path = root .. "/share/lua/5.1"
497+
local cpath = root .. "/lib/lua/5.1"
498+
package.path = package.path .. ";" .. path .. "/?.lua;" .. path .. "/?/init.lua;"
499+
package.cpath = package.cpath .. ";" .. cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
500+
end
501+
490502
function M.source(path)
491503
Util.track({ runtime = path })
492504
Util.try(function()

lua/lazy/core/meta.lua

+20-14
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ function M:load_pkgs()
3333
if not Config.options.pkg.enabled then
3434
return
3535
end
36-
local specs = Pkg.spec()
37-
for dir, spec in pairs(specs) do
38-
local meta, fragment = self:add(spec)
36+
local specs = Pkg.get()
37+
for dir, pkg in pairs(specs) do
38+
local meta, fragment = self:add(pkg.spec)
3939
if meta and fragment then
40+
meta._.pkg = pkg
4041
-- tag all package fragments as optional
4142
for _, fid in ipairs(meta._.frags) do
4243
local frag = self.fragments:get(fid)
@@ -165,18 +166,23 @@ function M:_rebuild(name)
165166

166167
assert(#plugin._.frags > 0, "no fragments found for plugin " .. name)
167168

169+
---@type table<number, boolean>
170+
local done = {}
168171
for _, fid in ipairs(plugin._.frags) do
169-
local fragment = self.fragments:get(fid)
170-
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
171-
---@diagnostic disable-next-line: no-unknown
172-
super = setmetatable(fragment.spec, super and { __index = super } or nil)
173-
plugin._.dep = plugin._.dep and fragment.dep
174-
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
175-
plugin.url = fragment.url or plugin.url
176-
177-
-- dependencies
178-
for _, dep in ipairs(fragment.deps or {}) do
179-
table.insert(plugin.dependencies, self.fragments:get(dep).name)
172+
if not done[fid] then
173+
done[fid] = true
174+
local fragment = self.fragments:get(fid)
175+
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
176+
---@diagnostic disable-next-line: no-unknown
177+
super = setmetatable(fragment.spec, super and { __index = super } or nil)
178+
plugin._.dep = plugin._.dep and fragment.dep
179+
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
180+
plugin.url = fragment.url or plugin.url
181+
182+
-- dependencies
183+
for _, dep in ipairs(fragment.deps or {}) do
184+
table.insert(plugin.dependencies, self.fragments:get(dep).name)
185+
end
180186
end
181187
end
182188

lua/lazy/core/plugin.lua

+22-5
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function M.update_state()
236236
installed[name] = nil
237237
end
238238

239-
require("lazy.manage.rocks").update_state()
239+
M.update_rocks_state()
240240

241241
Config.to_clean = {}
242242
for pack, dir_type in pairs(installed) do
@@ -253,6 +253,23 @@ function M.update_state()
253253
end
254254
end
255255

256+
function M.update_rocks_state()
257+
local root = Config.options.rocks.root
258+
---@type table<string,string>
259+
local installed = {}
260+
Util.ls(root, function(_, name, type)
261+
if type == "directory" then
262+
installed[name] = name
263+
end
264+
end)
265+
266+
for _, plugin in pairs(Config.plugins) do
267+
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
268+
plugin._.build = not installed[plugin.name]
269+
end
270+
end
271+
end
272+
256273
---@param path string
257274
function M.local_spec(path)
258275
local file = vim.secure.read(path)
@@ -321,11 +338,11 @@ function M.load()
321338
-- copy state. This wont do anything during startup
322339
for name, plugin in pairs(existing) do
323340
if Config.plugins[name] then
324-
local dep = Config.plugins[name]._.dep
325-
local frags = Config.plugins[name]._.frags
341+
local new_state = Config.plugins[name]._
326342
Config.plugins[name]._ = plugin._
327-
Config.plugins[name]._.dep = dep
328-
Config.plugins[name]._.frags = frags
343+
Config.plugins[name]._.dep = new_state.dep
344+
Config.plugins[name]._.frags = new_state.frags
345+
-- Config.plugins[name]._.tasks = new_state.tasks
329346
end
330347
end
331348
Util.track()

lua/lazy/manage/init.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ function M.install(opts)
8282
pipeline = {
8383
"git.clone",
8484
{ "git.checkout", lockfile = opts.lockfile },
85-
"rocks.install",
8685
"plugin.docs",
8786
"wait",
8887
"plugin.build",
8988
},
9089
plugins = function(plugin)
91-
return plugin.url and not (plugin._.installed and plugin._.rocks_installed ~= false)
90+
return plugin.url and not (plugin._.installed and not plugin._.build)
9291
end,
9392
}, opts):wait(function()
9493
require("lazy.manage.lock").update()
@@ -107,7 +106,6 @@ function M.update(opts)
107106
"git.fetch",
108107
"git.status",
109108
{ "git.checkout", lockfile = opts.lockfile },
110-
"rocks.install",
111109
"plugin.docs",
112110
"wait",
113111
"plugin.build",
@@ -224,7 +222,7 @@ function M.clear(plugins)
224222
if plugin._.tasks then
225223
---@param task LazyTask
226224
plugin._.tasks = vim.tbl_filter(function(task)
227-
return task:is_running()
225+
return task:is_running() or task.error
228226
end, plugin._.tasks)
229227
end
230228
end

lua/lazy/manage/rocks.lua

-90
This file was deleted.

lua/lazy/manage/task/rocks.lua

-57
This file was deleted.

0 commit comments

Comments
 (0)