semanser / vim-outdated-plugins

🔄 Async Vim/Neovim plugin for showing the number of your outdated plugins
51 stars 4 forks source link

Display message only once after all jobs are finished #13

Closed kiryph closed 5 years ago

kiryph commented 5 years ago

I am using vim8 and have configured a minimal setup:

~/.vim
❯ tree -L 3
.
├── autoload
│   └── plug.vim
├── plugged
│   ├── vim-easy-align
│   │   ├── EXAMPLES.md
│   │   ├── README.md
│   │   ├── autoload
│   │   ├── doc
│   │   ├── plugin
│   │   ├── test
│   │   └── zip
│   └── vim-outdated-plugins
│       ├── README.md
│       ├── autoload
│       ├── images
│       └── plugin
└── vimrc

11 directories, 6 files
~/.vim
❯ cat vimrc
source $VIMRUNTIME/defaults.vim

call plug#begin('~/.vim/plugged')

Plug 'junegunn/vim-easy-align'
Plug 'semanser/vim-outdated-plugins'

call plug#end()

When I start vim and run :messages, I see that vim-outdated-plugins has emitted two times the message:

Messages maintainer: Bram Moolenaar <Bram@vim.org>
All plugins up-to-date
All plugins up-to-date

I would prefer only to get a single message when all checks are done.

I have come up with a solution which works for me but I am not sure if it is implemented job-safe : I mean: I remove a job id from a dict in a callback which I am not sure could lead to a collision.

~/.vim/plugged/vim-outdated-plugins master*
❯ g diff
diff --git a/plugin/vim-outdated-plugins.vim b/plugin/vim-outdated-plugins.vim
index 8d12f4d..5e86b18 100644
--- a/plugin/vim-outdated-plugins.vim
+++ b/plugin/vim-outdated-plugins.vim
@@ -1,14 +1,17 @@
 function! s:JobHandler(job_id, data, event) dict
-  if (join(a:data) =~ "is behind")
+  if (str2nr(join(a:data)) != 0)
     let g:pluginsToUpdate += 1
   endif
 endfunction

 function! s:CalculateUpdates(job_id, data, event) dict
-  if g:pluginsToUpdate > 0
-    echom 'Plugins to update: ' . g:pluginsToUpdate
-  else
-    echom 'All plugins up-to-date'
+  call remove(g:check_for_updates_jobids, a:job_id) " Question: lock required?
+  if len(g:check_for_updates_jobids) == 0
+    if g:pluginsToUpdate > 0
+      echom 'Plugins to update: ' . g:pluginsToUpdate
+    else
+      echom 'All plugins up-to-date'
+    endif
   endif
 endfunction

@@ -21,8 +24,9 @@ function! CheckForUpdates()
   let g:pluginsToUpdate = 0

   " TODO check only activated plugins and not all downloaded
+  let g:check_for_updates_jobids = {}
   for key in keys(g:plugs)
-    let job = async#job#start([ 'bash', '-c', "cd " . g:plugs[key].dir ." && git remote update && git status -uno"], s:callbacks)
+    let g:check_for_updates_jobids[async#job#start([ 'bash', '-c', "cd " . g:plugs[key].dir ." && git remote update > /dev/null && git rev-list HEAD..origin --count"], s:callbacks)] = key
   endfor
 endfunction

Another issue which I think has to be taken into account is when the git command fails.

BTW Issue #11 should easily be resolved by simply removing the lines

-  else
-    echom 'All plugins up-to-date'
semanser commented 5 years ago

@kiryph Thanks again. Fixed.

About the #11 issue, I still think that the configurable variable is a better option. So probably I will add a variable to configure that behavior.