reorganize the main file a little bit
This commit is contained in:
53
lua/dep.lua
53
lua/dep.lua
@ -17,7 +17,7 @@ local M = {}
|
|||||||
--- sync a tree of plugins
|
--- sync a tree of plugins
|
||||||
---@param tree package[] tree of plugins
|
---@param tree package[] tree of plugins
|
||||||
---@param cb function? callback
|
---@param cb function? callback
|
||||||
function M.synctree(tree, cb)
|
local function synctree(tree, cb)
|
||||||
local progress = 0
|
local progress = 0
|
||||||
local has_errors = false
|
local has_errors = false
|
||||||
|
|
||||||
@ -57,6 +57,29 @@ function M.synctree(tree, cb)
|
|||||||
end
|
end
|
||||||
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
|
-- basically the main function of our program
|
||||||
---@param opts speclist
|
---@param opts speclist
|
||||||
return function(opts)
|
return function(opts)
|
||||||
@ -65,17 +88,6 @@ return function(opts)
|
|||||||
bench.setup()
|
bench.setup()
|
||||||
lazy.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()
|
local initialized, err = pcall(function()
|
||||||
packager.set_base_dir(opts.base_dir or vim.fn.stdpath("data").."/site/pack/deps/opt/")
|
packager.set_base_dir(opts.base_dir or vim.fn.stdpath("data").."/site/pack/deps/opt/")
|
||||||
bench.mark("load", function()
|
bench.mark("load", function()
|
||||||
@ -115,27 +127,16 @@ return function(opts)
|
|||||||
package:reload()
|
package:reload()
|
||||||
end
|
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
|
-- get all package that need syncing
|
||||||
local targets = {}
|
local targets = {}
|
||||||
for _, package in pairs(packager.get_packages()) do
|
for _, package in pairs(packager.get_packages()) do
|
||||||
if shouldsync(package) then
|
if shouldsync(opts, package) then
|
||||||
table.insert(targets, package)
|
table.insert(targets, package)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install all targets
|
-- install all targets
|
||||||
M.synctree(targets)
|
synctree(targets)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not initialized then
|
if not initialized then
|
||||||
@ -163,7 +164,7 @@ return function(opts)
|
|||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("DepSync", function()
|
vim.api.nvim_create_user_command("DepSync", function()
|
||||||
M.synctree(packager.get_packages())
|
synctree(packager.get_packages())
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("DepReload", function()
|
vim.api.nvim_create_user_command("DepReload", function()
|
||||||
|
Reference in New Issue
Block a user