Fix missing progress update (#127)

In the recent versions of NeoVim, jobstart() does not return
monotonically increasing numbers, this caused vim-plug to miss updating
the progress of a task when the job ID for the task is already
reassigned to a new task.
This commit is contained in:
Junegunn Choi 2014-12-02 02:48:25 +09:00
parent 68ad02c5c3
commit 48514768c2

View File

@ -752,20 +752,18 @@ function! s:job_abort()
call system('rm -rf ' . s:shellesc(g:plugs[name].dir)) call system('rm -rf ' . s:shellesc(g:plugs[name].dir))
endif endif
endfor endfor
let s:jobs = {} let s:jobs = {}
let s:jobs_idx = {}
endfunction endfunction
function! s:job_handler() abort function! s:job_handler(name) abort
if !s:plug_window_exists() " plug window closed if !s:plug_window_exists() " plug window closed
return s:job_abort() return s:job_abort()
endif endif
let name = get(s:jobs_idx, v:job_data[0], '') if !has_key(s:jobs, a:name)
if empty(name) " stale task
return return
endif endif
let job = s:jobs[name] let job = s:jobs[a:name]
if v:job_data[1] == 'exit' if v:job_data[1] == 'exit'
let job.running = 0 let job.running = 0
@ -773,14 +771,14 @@ function! s:job_handler() abort
let job.error = 1 let job.error = 1
let job.result = substitute(job.result, "Error[\r\n]$", '', '') let job.result = substitute(job.result, "Error[\r\n]$", '', '')
endif endif
call s:reap(name) call s:reap(a:name)
call s:tick() call s:tick()
else else
let job.result .= s:to_s(v:job_data[2]) let job.result .= s:to_s(v:job_data[2])
" To reduce the number of buffer updates " To reduce the number of buffer updates
let job.tick = get(job, 'tick', -1) + 1 let job.tick = get(job, 'tick', -1) + 1
if job.tick % len(s:jobs) == 0 if job.tick % len(s:jobs) == 0
call s:log(job.new ? '+' : '*', name, job.result) call s:log(job.new ? '+' : '*', a:name, job.result)
endif endif
endif endif
endfunction endfunction
@ -795,10 +793,9 @@ function! s:spawn(name, cmd, opts)
\ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd) \ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd)
\ . ' || echo Error']) \ . ' || echo Error'])
if x > 0 if x > 0
let s:jobs_idx[x] = a:name
let job.jobid = x let job.jobid = x
augroup PlugJobControl augroup PlugJobControl
execute 'autocmd JobActivity' a:name 'call s:job_handler()' execute 'autocmd JobActivity' a:name printf('call s:job_handler(%s)', string(a:name))
augroup END augroup END
else else
let job.running = 0 let job.running = 0
@ -869,8 +866,7 @@ function! s:log(bullet, name, lines)
endfunction endfunction
function! s:update_vim() function! s:update_vim()
let s:jobs = {} let s:jobs = {}
let s:jobs_idx = {}
call s:bar() call s:bar()
call s:tick() call s:tick()