1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 06:07:58 +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
setup nvim-plug:
```lua
require('plug').setup({
bundle_dir = 'D:/bundle_dir',
@ -43,7 +45,13 @@ require('plug').setup({
ui = 'notify', -- default ui is `notify`, use `default` for split window UI
http_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({
{
@ -89,10 +97,12 @@ require('plug').add({
| `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 |
| `frozen` | update only when specific with `PlugUpdate name` |
| `depends` | `table<PluginSpec>` a list of plugins |
## Commands
- `:PlugInstall`: install specific plugin
- `:PlugInstall`: install specific plugin or all plugins
- `:PlugUpdate`: update specific plugin or all plugins
## Default UI

View File

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

View File

@ -20,6 +20,9 @@ end
--- @param plugins table<PluginSpec>
function M.add(plugins)
for _, plug in ipairs(plugins) do
if plug.depends then
M.add(plug.depends)
else
loader.parser(plug)
if not plug.enabled then
goto continue
@ -56,6 +59,7 @@ function M.add(plugins)
::continue::
end
end
end
function M.get()
return all_plugins

View File

@ -84,7 +84,11 @@ local function install_plugin(plugSpec)
on_uidate(plugSpec.name, { command = 'clone', clone_done = true })
return
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
table.insert(cmd, '--branch')
table.insert(cmd, plugSpec.branch)
@ -97,17 +101,12 @@ local function install_plugin(plugSpec)
table.insert(cmd, plugSpec.path)
on_uidate(plugSpec.name, { command = 'clone', clone_process = '' })
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)
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,
on_exit = function(id, data, single)
@ -151,17 +150,12 @@ local function update_plugin(plugSpec, force)
local cmd = { 'git', 'pull', '--progress' }
on_uidate(plugSpec.name, { command = 'pull', pull_process = '' })
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)
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,
on_exit = function(id, data, single)

View File

@ -28,7 +28,12 @@ require('plug').add({
{
'wsdjeg/JavaUnit.vim',
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',

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,
})