From f4d1c4cf2590c3cf7c01313afc0866989ce12ed7 Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 1 Jul 2025 21:38:10 -0400 Subject: [PATCH] reorganize the main file a little bit --- lua/dep.lua | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lua/dep.lua b/lua/dep.lua index d9f7c45..ceb91dc 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -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()