mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 05:37:57 +08:00
feat(nvim-plug): support max_processes
This commit is contained in:
parent
daf276de98
commit
8a4834b360
2
bundle/nvim-plug/README.md
vendored
2
bundle/nvim-plug/README.md
vendored
@ -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({
|
||||||
|
6
bundle/nvim-plug/lua/plug/config.lua
vendored
6
bundle/nvim-plug/lua/plug/config.lua
vendored
@ -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
|
||||||
|
24
bundle/nvim-plug/lua/plug/installer.lua
vendored
24
bundle/nvim-plug/lua/plug/installer.lua
vendored
@ -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
|
||||||
|
|
||||||
|
30
bundle/nvim-plug/lua/plug/loader.lua
vendored
30
bundle/nvim-plug/lua/plug/loader.lua
vendored
@ -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,18 +23,18 @@ 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
|
||||||
@ -63,8 +63,8 @@ end
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user