reorganize the main file a little bit

This commit is contained in:
2025-07-01 21:38:10 -04:00
parent 2346a0baa5
commit f4d1c4cf25

View File

@ -17,7 +17,7 @@ local M = {}
--- sync a tree of plugins
---@param tree package[] tree of plugins
---@param cb function? callback
function M.synctree(tree, cb)
local function synctree(tree, cb)
local progress = 0
local has_errors = false
@ -57,6 +57,29 @@ function M.synctree(tree, cb)
end
end
--- check if a package should be synced
---@param opts table options
---@param package package package table spec
---@return boolean sync
local function shouldsync(opts, package)
if opts.sync == "new" or opts.sync == nil then
return not package.exists
else
return opts.sync == "always"
end
end
--- make comparison for table.sort
---@param a package package spec a
---@param b package package spec b
---@return boolean
local function comp(a, b)
-- NOTE: this doesn't have to be in any real order, it just has to be
-- consistant, thus we can just check if the unicode value of one package
-- id is less than the other
return a.id < b.id
end
-- basically the main function of our program
---@param opts speclist
return function(opts)
@ -65,17 +88,6 @@ return function(opts)
bench.setup()
lazy.setup()
--- make comparison for table.sort
---@param a package package spec a
---@param b package package spec b
---@return boolean
local function comp(a, b)
-- NOTE: this doesn't have to be in any real order, it just has to be
-- consistant, thus we can just check if the unicode value of one package
-- id is less than the other
return a.id < b.id
end
local initialized, err = pcall(function()
packager.set_base_dir(opts.base_dir or vim.fn.stdpath("data").."/site/pack/deps/opt/")
bench.mark("load", function()
@ -115,27 +127,16 @@ return function(opts)
package:reload()
end
--- check if a package should be synced
---@param package table package table spec
---@return boolean sync
local function shouldsync(package)
if opts.sync == "new" or opts.sync == nil then
return not package.exists
else
return opts.sync == "always"
end
end
-- get all package that need syncing
local targets = {}
for _, package in pairs(packager.get_packages()) do
if shouldsync(package) then
if shouldsync(opts, package) then
table.insert(targets, package)
end
end
-- install all targets
M.synctree(targets)
synctree(targets)
end)
if not initialized then
@ -163,7 +164,7 @@ return function(opts)
end, {})
vim.api.nvim_create_user_command("DepSync", function()
M.synctree(packager.get_packages())
synctree(packager.get_packages())
end, {})
vim.api.nvim_create_user_command("DepReload", function()