mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 02:18:00 +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
|
||||
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({
|
||||
|
6
bundle/nvim-plug/lua/plug/config.lua
vendored
6
bundle/nvim-plug/lua/plug/config.lua
vendored
@ -5,13 +5,15 @@
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
|
||||
local M = {}
|
||||
|
||||
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
|
||||
|
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 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
|
||||
|
||||
|
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 config = require("plug.config")
|
||||
local config = require('plug.config')
|
||||
|
||||
--- @class PluginSpec
|
||||
--- @field rtp string
|
||||
@ -23,18 +23,18 @@ 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]
|
||||
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
|
||||
@ -63,8 +63,8 @@ end
|
||||
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}")
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user