k-takata / minpac

A minimal package manager for Vim 8+ (and Neovim)
841 stars 30 forks source link

Function called from within a post update hook doesn't work but using it as a post update hook works #74

Closed ahmedelgabri closed 5 years ago

ahmedelgabri commented 5 years ago

I'm trying to add a custom post update hook, when I do this it blows up

  let s:coc_extensions = [
        \ 'coc-css',
        \ 'coc-rls',
        \ 'coc-html',
        \ 'coc-json',
        \ 'coc-pyls',
        \ 'coc-yaml',
        \ 'coc-emoji',
        \ 'coc-tsserver',
        \ 'coc-ultisnips',
        \ 'coc-highlight'
        \ ]

  function! s:coc_plugins() abort
    call coc#util#install() " Throws here
    call coc#util#install_extension(join(get(s:, 'coc_extensions', [])))
  endfunction

  call minpac#add('https://github.com/neoclide/coc.nvim', {'do': function('s:coc_plugins')})

~while this works as expected~ actually this also stopped working...

  call minpac#add('https://github.com/neoclide/coc.nvim', {'do': { -> coc#util#install() } })

Any idea where is the problem & how to make it work?

ahmedelgabri commented 5 years ago

I had to do this to make it work, but not sure if this is the right thing

  function! s:coc_plugins() abort
+    execute 'packadd ' . a:name
     call coc#util#install() 
     call coc#util#install_extension(join(get(s:, 'coc_extensions', [])))
  endfunction
k-takata commented 5 years ago

The post-update hook is called after updating by the git command is finished. At the moment, the plugin might not be added to the 'runtimepath'. (Vim will update it after .vimrc is loaded or packadd is used.) Adding execute 'packadd ' . a:name looks right solution.

ahmedelgabri commented 5 years ago

@k-takata perfect, thanks!

ahmedelgabri commented 5 years ago

Sorry to revive this issue back, but execute 'packadd ' . a:name is also not working properly. That's because hooks only run as a post-update & they don't run after the initial install.

Is there is any way to be able to run this on initial install & on updates too?