Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display message only once after all jobs are finished #13

Closed
kiryph opened this issue Nov 24, 2018 · 1 comment
Closed

Display message only once after all jobs are finished #13

kiryph opened this issue Nov 24, 2018 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@kiryph
Copy link

kiryph commented Nov 24, 2018

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 semanser self-assigned this Dec 2, 2018
@semanser semanser added the enhancement New feature or request label Dec 2, 2018
@semanser
Copy link
Owner

semanser commented Dec 2, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants