Skip to content

Commit

Permalink
fix: rplugin check should be deferred, call it on filetype events
Browse files Browse the repository at this point in the history
When the plugin is not lazy-loaded, plugin/semshi.vim may be executed
earlier than rplugin.vim (then `:Semshi` will not exist). Checking
rplugin manifests can be done on the first call of `s:filetype_changed`
rather than doing immediately on startup.
  • Loading branch information
wookayin committed Oct 31, 2023
1 parent f615d62 commit eddc530
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions plugin/semshi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ function! s:remove_builtin_extra()
endfunction

" Ensure the rplugin manifest
if exists(':Semshi') == 0
command! -nargs=* Semshi call nvim_err_writeln(":Semshi not found. Run :UpdateRemotePlugins.")
function! s:check_rplugin_manifest() abort
if exists('s:semshi_rplugin_error') > 0
return v:false
endif
if exists(':Semshi') > 0
return v:true
endif
let s:semshi_rplugin_error = 1
command! -nargs=* Semshi call nvim_err_writeln(":Semshi not found. Run :UpdateRemotePlugins.")

let s:semshi_rplugin_error = 1
if exists(':lua') && has('nvim-0.5.0') > 0
" notify with an asynchronous error message
if exists(':lua') && has('nvim-0.5.0') > 0
lua << EOF
vim.schedule(function()
vim.notify(":Semshi not found. Run :UpdateRemotePlugins.", 'ERROR', { title = "semshi" })
end)
vim.schedule(function()
vim.notify(":Semshi not found. Run :UpdateRemotePlugins.", 'ERROR', { title = "semshi" })
end)
EOF
endif
endif

function! s:filetype_changed()
if exists('s:semshi_rplugin_error')
" Avoid exceptions inside FileType autocmd, because the stacktrace is ugly.
" Instead, an asynchronous notification that something is broken will be made.
return
end
endif
return v:false
endfunction

function! s:filetype_changed() abort
if !s:check_rplugin_manifest()
" Avoid exceptions inside FileType autocmd, because the stacktrace is ugly.
" Instead, an asynchronous notification that something is broken will be made.
return
endif

let l:ft = expand('<amatch>')
if index(g:semshi#filetypes, l:ft) != -1
Expand Down

0 comments on commit eddc530

Please sign in to comment.