1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 01:57:58 +08:00

feat(nvim-plug): support max_processes

This commit is contained in:
Eric Wong 2025-02-05 00:43:02 +08:00
parent daf276de98
commit 8a4834b360
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
4 changed files with 55 additions and 27 deletions

View File

@ -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({

View File

@ -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

View File

@ -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

View File

@ -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