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

fix(nvim-plug): fix clone progress

This commit is contained in:
Eric Wong 2025-02-08 20:39:11 +08:00
parent 28fc69c56a
commit 2fe9e8fc11
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
6 changed files with 65 additions and 64 deletions

View File

@ -35,6 +35,8 @@ nvim-plug is an asynchronous Neovim plugin manager written in Lua.
## Usage ## Usage
setup nvim-plug:
```lua ```lua
require('plug').setup({ require('plug').setup({
bundle_dir = 'D:/bundle_dir', bundle_dir = 'D:/bundle_dir',
@ -43,7 +45,13 @@ require('plug').setup({
ui = 'notify', -- default ui is `notify`, use `default` for split window UI ui = 'notify', -- default ui is `notify`, use `default` for split window UI
http_proxy = 'http://127.0.0.1:7890', -- default is nil http_proxy = 'http://127.0.0.1:7890', -- default is nil
https_proxy = 'http://127.0.0.1:7890', -- default is nil https_proxy = 'http://127.0.0.1:7890', -- default is nil
clone_depth = 1 -- default history depth for `git clone`
}) })
```
add plugins:
```lua
require('plug').add({ require('plug').add({
{ {
@ -89,10 +97,12 @@ require('plug').add({
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api | | `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | | `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
| `frozen` | update only when specific with `PlugUpdate name` | | `frozen` | update only when specific with `PlugUpdate name` |
| `depends` | `table<PluginSpec>` a list of plugins |
## Commands ## Commands
- `:PlugInstall`: install specific plugin - `:PlugInstall`: install specific plugin or all plugins
- `:PlugUpdate`: update specific plugin or all plugins
## Default UI ## Default UI

View File

@ -11,6 +11,7 @@ M.bundle_dir = vim.fn.stdpath('data') .. '/bundle_dir'
M.max_processes = 5 M.max_processes = 5
M.base_url = 'https://github.com/' M.base_url = 'https://github.com/'
M.ui = 'notify' M.ui = 'notify'
M.clone_depth = '1'
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.max_processes = opt.max_processes or M.max_processes
@ -18,6 +19,7 @@ function M.setup(opt)
M.ui = opt.ui or M.ui M.ui = opt.ui or M.ui
M.http_proxy = opt.http_proxy M.http_proxy = opt.http_proxy
M.https_proxy = opt.https_proxy M.https_proxy = opt.https_proxy
M.clone_depth = opt.clone_depth or M.clone_depth
end end
return M return M

View File

@ -20,40 +20,44 @@ end
--- @param plugins table<PluginSpec> --- @param plugins table<PluginSpec>
function M.add(plugins) function M.add(plugins)
for _, plug in ipairs(plugins) do for _, plug in ipairs(plugins) do
loader.parser(plug) if plug.depends then
if not plug.enabled then M.add(plug.depends)
goto continue else
end loader.parser(plug)
all_plugins[plug.name] = plug if not plug.enabled then
if plug.cmds then goto continue
hooks.on_cmds(plug.cmds, plug) end
end all_plugins[plug.name] = plug
if plug.events then if plug.cmds then
hooks.on_events(plug.events, plug) hooks.on_cmds(plug.cmds, plug)
end end
if plug.events then
hooks.on_events(plug.events, plug)
end
if plug.on_ft then if plug.on_ft then
hooks.on_ft(plug.on_ft, plug) hooks.on_ft(plug.on_ft, plug)
end end
if plug.on_map then if plug.on_map then
hooks.on_map(plug.on_map, plug) hooks.on_map(plug.on_map, plug)
end end
if plug.on_func then if plug.on_func then
hooks.on_func(plug.on_func, plug) hooks.on_func(plug.on_func, plug)
end end
if if
not plug.events not plug.events
and not plug.cmds and not plug.cmds
and not plug.on_ft and not plug.on_ft
and not plug.on_map and not plug.on_map
and not plug.on_func and not plug.on_func
then then
loader.load(plug) loader.load(plug)
end
::continue::
end end
::continue::
end end
end end

View File

@ -84,7 +84,11 @@ local function install_plugin(plugSpec)
on_uidate(plugSpec.name, { command = 'clone', clone_done = true }) on_uidate(plugSpec.name, { command = 'clone', clone_done = true })
return return
end end
local cmd = { 'git', 'clone', '--depth', '1', '--progress' } local cmd = { 'git', 'clone', '--progress' }
if config.clone_depth ~= 0 then
table.insert(cmd, '--depth')
table.insert(cmd, tostring(config.clone_depth))
end
if plugSpec.branch then if plugSpec.branch then
table.insert(cmd, '--branch') table.insert(cmd, '--branch')
table.insert(cmd, plugSpec.branch) table.insert(cmd, plugSpec.branch)
@ -97,17 +101,12 @@ local function install_plugin(plugSpec)
table.insert(cmd, plugSpec.path) table.insert(cmd, plugSpec.path)
on_uidate(plugSpec.name, { command = 'clone', clone_process = '' }) on_uidate(plugSpec.name, { command = 'clone', clone_process = '' })
local jobid = job.start(cmd, { local jobid = job.start(cmd, {
on_stdout = function(id, data)
for _, v in ipairs(data) do
local status = vim.fn.matchstr(v, [[\d\+%\s(\d\+/\d\+)]])
if vim.fn.empty(status) == 1 then
on_uidate(plugSpec.name, { clone_process = status })
end
end
end,
on_stderr = function(id, data) on_stderr = function(id, data)
for _, v in ipairs(data) do for _, v in ipairs(data) do
notify.notify(jobs['jobid_' .. id .. ':' .. v]) local status = vim.fn.matchstr(v, [[\d\+%\s(\d\+/\d\+)]])
if vim.fn.empty(status) == 0 then
on_uidate(plugSpec.name, { clone_process = status })
end
end end
end, end,
on_exit = function(id, data, single) on_exit = function(id, data, single)
@ -151,17 +150,12 @@ local function update_plugin(plugSpec, force)
local cmd = { 'git', 'pull', '--progress' } local cmd = { 'git', 'pull', '--progress' }
on_uidate(plugSpec.name, { command = 'pull', pull_process = '' }) on_uidate(plugSpec.name, { command = 'pull', pull_process = '' })
local jobid = job.start(cmd, { local jobid = job.start(cmd, {
on_stdout = function(id, data)
for _, v in ipairs(data) do
local status = vim.fn.matchstr(v, [[\d\+%\s(\d\+/\d\+)]])
if vim.fn.empty(status) == 1 then
on_uidate(plugSpec.name, { pull_process = status })
end
end
end,
on_stderr = function(id, data) on_stderr = function(id, data)
for _, v in ipairs(data) do for _, v in ipairs(data) do
notify.notify(jobs['jobid_' .. id .. ':' .. v]) local status = vim.fn.matchstr(v, [[\d\+%\s(\d\+/\d\+)]])
if vim.fn.empty(status) == 0 then
on_uidate(plugSpec.name, { pull_process = status })
end
end end
end, end,
on_exit = function(id, data, single) on_exit = function(id, data, single)

View File

@ -28,7 +28,12 @@ require('plug').add({
{ {
'wsdjeg/JavaUnit.vim', 'wsdjeg/JavaUnit.vim',
cmds = { 'JavaUnit' }, cmds = { 'JavaUnit' },
build = {'javac', '-encoding', 'utf8', '-d', 'bin', 'src/com/wsdjeg/util/*.java'} build = {'javac', '-encoding', 'utf8', '-d', 'bin', 'src/com/wsdjeg/util/*.java'},
depends = {
{
'wsdjeg/syntastic'
}
}
}, },
{ {
'wsdjeg/vim-async-dict', 'wsdjeg/vim-async-dict',

View File

@ -1,14 +0,0 @@
local ui = require('plug.ui')
ui.open()
ui.on_update('test.vim', {
clone_done = true,
})
ui.on_update('test2.vim', {
clone_process = '16% (160/1000)',
})
ui.on_update('test3.vim', {
clone_done = true,
})
ui.on_update('test4.vim', {
clone_done = false,
})