provider: let providers decide their status

Instead of deciding provider status in eval_has_provider, move the
decision to the provider Vim scripts.

Previously, provider loading worked as follows:

1. eval_has_provider() verified provider availability by searching for
   the provider#providername#Call function and cached this verificaion as a static
   variable for some providers
2. providers short-circuited on loading to prevent the definition of the
   Call function (with the exception of the node provider that did not)

This commit changes the expected interface between nvim and its
providers to facilitate provider reloading, by splitting the
verification of the provider from the availability of the Call function.

eval_has_provider() now checks for a provider#providername#enabled
variable. It is up to the provider script to set this to 0 or 1
accordingly. eval_call_provider() remains unchanged.

All providers hosting a Call function were updated to respect this.

The clipboard provider now has a Reload function to reload the
provider.
This commit is contained in:
Rui Abreu Ferreira
2019-06-09 18:22:10 +01:00
committed by Justin M. Keyes
parent 2860453c4f
commit 2cfe4748e5
11 changed files with 65 additions and 59 deletions

View File

@@ -10,6 +10,7 @@ endif
let g:loaded_python_provider = 1
let [s:prog, s:err] = provider#pythonx#Detect(2)
let g:provider#python#enabled = !empty(s:prog)
function! provider#python#Prog() abort
return s:prog
@@ -19,11 +20,6 @@ function! provider#python#Error() abort
return s:err
endfunction
if s:prog == ''
" Detection failed
finish
endif
" The Python provider plugin will run in a separate instance of the Python
" host.
call remote#host#RegisterClone('legacy-python-provider', 'python')