From 48514768c299c76c6cadaf88e97ddf9bad579da5 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 2 Dec 2014 02:48:25 +0900 Subject: [PATCH] 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. --- plug.vim | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plug.vim b/plug.vim index 3732574..cb72a13 100644 --- a/plug.vim +++ b/plug.vim @@ -752,20 +752,18 @@ function! s:job_abort() call system('rm -rf ' . s:shellesc(g:plugs[name].dir)) endif endfor - let s:jobs = {} - let s:jobs_idx = {} + let s:jobs = {} endfunction -function! s:job_handler() abort +function! s:job_handler(name) abort if !s:plug_window_exists() " plug window closed return s:job_abort() endif - let name = get(s:jobs_idx, v:job_data[0], '') - if empty(name) " stale task + if !has_key(s:jobs, a:name) return endif - let job = s:jobs[name] + let job = s:jobs[a:name] if v:job_data[1] == 'exit' let job.running = 0 @@ -773,14 +771,14 @@ function! s:job_handler() abort let job.error = 1 let job.result = substitute(job.result, "Error[\r\n]$", '', '') endif - call s:reap(name) + call s:reap(a:name) call s:tick() else let job.result .= s:to_s(v:job_data[2]) " To reduce the number of buffer updates let job.tick = get(job, 'tick', -1) + 1 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 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) \ . ' || echo Error']) if x > 0 - let s:jobs_idx[x] = a:name let job.jobid = x 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 else let job.running = 0 @@ -869,8 +866,7 @@ function! s:log(bullet, name, lines) endfunction function! s:update_vim() - let s:jobs = {} - let s:jobs_idx = {} + let s:jobs = {} call s:bar() call s:tick()