diff --git a/bundle/nvim-plug/README.md b/bundle/nvim-plug/README.md index eeb27accd..1858d1b69 100644 --- a/bundle/nvim-plug/README.md +++ b/bundle/nvim-plug/README.md @@ -12,6 +12,8 @@ ```lua require('plug').setup({ bundle_dir = 'D:/bundle_dir', + max_processes = 5, -- max number of processes used for nvim-plug job + base_url = 'https://github.com', }) require('plug').add({ diff --git a/bundle/nvim-plug/lua/plug/config.lua b/bundle/nvim-plug/lua/plug/config.lua index 25140dab4..a01c1b98b 100644 --- a/bundle/nvim-plug/lua/plug/config.lua +++ b/bundle/nvim-plug/lua/plug/config.lua @@ -5,13 +5,15 @@ -- License: GPLv3 --============================================================================= - local M = {} -M.bundle_dir = vim.fn.stdpath('data') .. '/bundle_dir' - +M.bundle_dir = vim.fn.stdpath('data') .. '/bundle_dir' +M.max_processes = 5 +M.base_url = 'https://github.com/' function M.setup(opt) M.bundle_dir = opt.bundle_dir or M.bundle_dir + M.max_processes = opt.max_processes or M.max_processes + M.base_url = opt.base_url or M.base_url end return M diff --git a/bundle/nvim-plug/lua/plug/installer.lua b/bundle/nvim-plug/lua/plug/installer.lua index 94b66e0bb..4faed1e34 100644 --- a/bundle/nvim-plug/lua/plug/installer.lua +++ b/bundle/nvim-plug/lua/plug/installer.lua @@ -10,9 +10,19 @@ local M = {} local job = require('spacevim.api.job') local notify = require('spacevim.api.notify') local jobs = {} +local config = require('plug.config') + +local processes = 0 + +local installation_queue = {} +local building_queue = {} --- @param plugSpec PluginSpec local function build(plugSpec) + if processes >= config.max_processes then + table.insert(building_queue, plugSpec) + return + end local jobid = job.start(plugSpec.build, { on_stdout = function(id, data) for _, v in ipairs(data) do @@ -30,13 +40,22 @@ local function build(plugSpec) else notify.notify('failed to build ' .. jobs['jobid_' .. id]) end + processes = processes - 1 + if #building_queue > 0 then + build(table.remove(building_queue)) + end end, }) + processes = processes + 1 jobs['jobid_' .. jobid] = plugSpec.name end --- @param plugSpec PluginSpec local function install_plugin(plugSpec) + if processes >= config.max_processes then + table.insert(installation_queue, plugSpec) + return + end local cmd = { 'git', 'clone', '--depth', '1' } if plugSpec.branch then table.insert(cmd, '--branch') @@ -68,8 +87,13 @@ local function install_plugin(plugSpec) else notify.notify('failed to install ' .. jobs['jobid_' .. id]) end + processes = processes - 1 + if #installation_queue > 0 then + install_plugin(table.remove(installation_queue, 1)) + end end, }) + processes = processes + 1 jobs['jobid_' .. jobid] = plugSpec.name end diff --git a/bundle/nvim-plug/lua/plug/loader.lua b/bundle/nvim-plug/lua/plug/loader.lua index 6767a977e..2ccc9aae8 100644 --- a/bundle/nvim-plug/lua/plug/loader.lua +++ b/bundle/nvim-plug/lua/plug/loader.lua @@ -7,7 +7,7 @@ local M = {} -local config = require("plug.config") +local config = require('plug.config') --- @class PluginSpec --- @field rtp string @@ -23,21 +23,21 @@ local config = require("plug.config") function M.parser(plugSpec) plugSpec.name = vim.split(plugSpec[1], '/')[2] - if not plugSpec.type or plugSpec.type == "none" then - plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] - plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] - plugSpec.url = "https://github.com/" .. plugSpec[1] - elseif plugSpec.type == "color" then - plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] - plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/color' - plugSpec.repo = "https://github.com/" .. plugSpec[1] - elseif plugSpec.type == "plugin" then - plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] - plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/plugin' - plugSpec.url = "https://github.com/" .. plugSpec[1] - end + if not plugSpec.type or plugSpec.type == 'none' then + plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1] + plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] + plugSpec.url = config.base_url .. '/' .. plugSpec[1] + elseif plugSpec.type == 'color' then + plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1] + plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/color' + plugSpec.repo = config.base_url .. '/' .. plugSpec[1] + elseif plugSpec.type == 'plugin' then + plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1] + plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/plugin' + plugSpec.url = config.base_url .. '/' .. plugSpec[1] + end - return plugSpec + return plugSpec end -- {'loadconf': 1, @@ -61,15 +61,15 @@ end -- 'merged': 0, -- 'path': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git'} function M.load(plugSpec) - if vim.fn.isdirectory(plugSpec.rtp) == 1 then - vim.opt.runtimepath:append(plugSpec.rtp) - if vim.fn.has("vim_starting") ~= 1 then - local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, "plugin/*.{lua,vim}") - for _, f in ipairs(plugin_directory_files) do - vim.cmd.source(f) - end - end - end + if vim.fn.isdirectory(plugSpec.rtp) == 1 then + vim.opt.runtimepath:append(plugSpec.rtp) + if vim.fn.has('vim_starting') ~= 1 then + local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}') + for _, f in ipairs(plugin_directory_files) do + vim.cmd.source(f) + end + end + end end return M