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 ```lua
require('plug').setup({ require('plug').setup({
bundle_dir = 'D:/bundle_dir', 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({ require('plug').add({

View File

@ -5,13 +5,15 @@
-- License: GPLv3 -- License: GPLv3
--============================================================================= --=============================================================================
local M = {} 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) function M.setup(opt)
M.bundle_dir = opt.bundle_dir or M.bundle_dir 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 end
return M return M

View File

@ -10,9 +10,19 @@ local M = {}
local job = require('spacevim.api.job') local job = require('spacevim.api.job')
local notify = require('spacevim.api.notify') local notify = require('spacevim.api.notify')
local jobs = {} local jobs = {}
local config = require('plug.config')
local processes = 0
local installation_queue = {}
local building_queue = {}
--- @param plugSpec PluginSpec --- @param plugSpec PluginSpec
local function build(plugSpec) local function build(plugSpec)
if processes >= config.max_processes then
table.insert(building_queue, plugSpec)
return
end
local jobid = job.start(plugSpec.build, { local jobid = job.start(plugSpec.build, {
on_stdout = function(id, data) on_stdout = function(id, data)
for _, v in ipairs(data) do for _, v in ipairs(data) do
@ -30,13 +40,22 @@ local function build(plugSpec)
else else
notify.notify('failed to build ' .. jobs['jobid_' .. id]) notify.notify('failed to build ' .. jobs['jobid_' .. id])
end end
processes = processes - 1
if #building_queue > 0 then
build(table.remove(building_queue))
end
end, end,
}) })
processes = processes + 1
jobs['jobid_' .. jobid] = plugSpec.name jobs['jobid_' .. jobid] = plugSpec.name
end end
--- @param plugSpec PluginSpec --- @param plugSpec PluginSpec
local function install_plugin(plugSpec) local function install_plugin(plugSpec)
if processes >= config.max_processes then
table.insert(installation_queue, plugSpec)
return
end
local cmd = { 'git', 'clone', '--depth', '1' } local cmd = { 'git', 'clone', '--depth', '1' }
if plugSpec.branch then if plugSpec.branch then
table.insert(cmd, '--branch') table.insert(cmd, '--branch')
@ -68,8 +87,13 @@ local function install_plugin(plugSpec)
else else
notify.notify('failed to install ' .. jobs['jobid_' .. id]) notify.notify('failed to install ' .. jobs['jobid_' .. id])
end end
processes = processes - 1
if #installation_queue > 0 then
install_plugin(table.remove(installation_queue, 1))
end
end, end,
}) })
processes = processes + 1
jobs['jobid_' .. jobid] = plugSpec.name jobs['jobid_' .. jobid] = plugSpec.name
end end

View File

@ -7,7 +7,7 @@
local M = {} local M = {}
local config = require("plug.config") local config = require('plug.config')
--- @class PluginSpec --- @class PluginSpec
--- @field rtp string --- @field rtp string
@ -23,21 +23,21 @@ local config = require("plug.config")
function M.parser(plugSpec) function M.parser(plugSpec)
plugSpec.name = vim.split(plugSpec[1], '/')[2] plugSpec.name = vim.split(plugSpec[1], '/')[2]
if not plugSpec.type or plugSpec.type == "none" then if not plugSpec.type or plugSpec.type == 'none' then
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1]
plugSpec.url = "https://github.com/" .. plugSpec[1] plugSpec.url = config.base_url .. '/' .. plugSpec[1]
elseif plugSpec.type == "color" then elseif plugSpec.type == 'color' then
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/color' plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/color'
plugSpec.repo = "https://github.com/" .. plugSpec[1] plugSpec.repo = config.base_url .. '/' .. plugSpec[1]
elseif plugSpec.type == "plugin" then elseif plugSpec.type == 'plugin' then
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1] plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/plugin' plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/plugin'
plugSpec.url = "https://github.com/" .. plugSpec[1] plugSpec.url = config.base_url .. '/' .. plugSpec[1]
end end
return plugSpec return plugSpec
end end
-- {'loadconf': 1, -- {'loadconf': 1,
@ -61,15 +61,15 @@ end
-- 'merged': 0, -- 'merged': 0,
-- 'path': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git'} -- 'path': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git'}
function M.load(plugSpec) function M.load(plugSpec)
if vim.fn.isdirectory(plugSpec.rtp) == 1 then if vim.fn.isdirectory(plugSpec.rtp) == 1 then
vim.opt.runtimepath:append(plugSpec.rtp) vim.opt.runtimepath:append(plugSpec.rtp)
if vim.fn.has("vim_starting") ~= 1 then if vim.fn.has('vim_starting') ~= 1 then
local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, "plugin/*.{lua,vim}") local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}')
for _, f in ipairs(plugin_directory_files) do for _, f in ipairs(plugin_directory_files) do
vim.cmd.source(f) vim.cmd.source(f)
end end
end end
end end
end end
return M return M