From 2cfe4748e57bd510b98ca81bd915f801f5a50bb5 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Sun, 9 Jun 2019 18:22:10 +0100 Subject: 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. --- test/functional/fixtures/autoload/provider/brokencall.vim | 2 ++ test/functional/fixtures/autoload/provider/brokenenabled.vim | 6 ++++++ test/functional/fixtures/autoload/provider/clipboard.vim | 1 + 3 files changed, 9 insertions(+) create mode 100644 test/functional/fixtures/autoload/provider/brokencall.vim create mode 100644 test/functional/fixtures/autoload/provider/brokenenabled.vim (limited to 'test/functional/fixtures') diff --git a/test/functional/fixtures/autoload/provider/brokencall.vim b/test/functional/fixtures/autoload/provider/brokencall.vim new file mode 100644 index 0000000000..2c83dd2b4a --- /dev/null +++ b/test/functional/fixtures/autoload/provider/brokencall.vim @@ -0,0 +1,2 @@ +" A dummy test provider +let g:provider#brokencall#enabled = 1 diff --git a/test/functional/fixtures/autoload/provider/brokenenabled.vim b/test/functional/fixtures/autoload/provider/brokenenabled.vim new file mode 100644 index 0000000000..54ed11cedc --- /dev/null +++ b/test/functional/fixtures/autoload/provider/brokenenabled.vim @@ -0,0 +1,6 @@ +" Dummy test provider, missing +" let g:provider#brokenenabled#enabled = 0 + +function! provider#brokenenabled#Call(method, args) + return 42 +endfunction diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index 6d777255c8..d1ddd81b12 100644 --- a/test/functional/fixtures/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -35,6 +35,7 @@ function! s:methods.set(lines, regtype, reg) let g:test_clip[a:reg] = [a:lines, a:regtype] endfunction +let provider#clipboard#enabled = 1 function! provider#clipboard#Call(method, args) return call(s:methods[a:method],a:args,s:methods) -- cgit From 66938b928c05b913f3a11e520d13ca854621799d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 4 Aug 2019 03:54:06 +0200 Subject: provider: decide status by g:loaded_xx_provider --- test/functional/fixtures/autoload/provider/brokencall.vim | 2 +- test/functional/fixtures/autoload/provider/brokenenabled.vim | 4 ++-- test/functional/fixtures/autoload/provider/clipboard.vim | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional/fixtures') diff --git a/test/functional/fixtures/autoload/provider/brokencall.vim b/test/functional/fixtures/autoload/provider/brokencall.vim index 2c83dd2b4a..7dc5d828d2 100644 --- a/test/functional/fixtures/autoload/provider/brokencall.vim +++ b/test/functional/fixtures/autoload/provider/brokencall.vim @@ -1,2 +1,2 @@ " A dummy test provider -let g:provider#brokencall#enabled = 1 +let g:loaded_brokencall_provider = 1 diff --git a/test/functional/fixtures/autoload/provider/brokenenabled.vim b/test/functional/fixtures/autoload/provider/brokenenabled.vim index 54ed11cedc..dd33ce66f3 100644 --- a/test/functional/fixtures/autoload/provider/brokenenabled.vim +++ b/test/functional/fixtures/autoload/provider/brokenenabled.vim @@ -1,5 +1,5 @@ -" Dummy test provider, missing -" let g:provider#brokenenabled#enabled = 0 +" Dummy test provider, missing this required variable: +" let g:loaded_brokenenabled_provider = 0 function! provider#brokenenabled#Call(method, args) return 42 diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index d1ddd81b12..efa9f82bd4 100644 --- a/test/functional/fixtures/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -1,3 +1,5 @@ +let g:loaded_clipboard_provider = 1 + let g:test_clip = { '+': [''], '*': [''], } let s:methods = {} @@ -35,8 +37,6 @@ function! s:methods.set(lines, regtype, reg) let g:test_clip[a:reg] = [a:lines, a:regtype] endfunction -let provider#clipboard#enabled = 1 - function! provider#clipboard#Call(method, args) return call(s:methods[a:method],a:args,s:methods) endfunction -- cgit From 241956720d02d933b0b27097a3b0a1966f138d0b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 4 Aug 2019 12:06:24 +0200 Subject: provider: g:loaded_xx_provider=2 means "enabled and working" Value of 1 cannot be used, because users might set that in their vimrc to _disable_ a provider, which would confuse :checkhealth and has(). --- test/functional/fixtures/autoload/provider/brokencall.vim | 2 +- test/functional/fixtures/autoload/provider/clipboard.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/fixtures') diff --git a/test/functional/fixtures/autoload/provider/brokencall.vim b/test/functional/fixtures/autoload/provider/brokencall.vim index 7dc5d828d2..cad2b2a640 100644 --- a/test/functional/fixtures/autoload/provider/brokencall.vim +++ b/test/functional/fixtures/autoload/provider/brokencall.vim @@ -1,2 +1,2 @@ " A dummy test provider -let g:loaded_brokencall_provider = 1 +let g:loaded_brokencall_provider = 2 diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index efa9f82bd4..41e486b745 100644 --- a/test/functional/fixtures/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -1,4 +1,4 @@ -let g:loaded_clipboard_provider = 1 +let g:loaded_clipboard_provider = 2 let g:test_clip = { '+': [''], '*': [''], } -- cgit From 5e6a08f2e6b21e83c9fb381042f0aed89de4598d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 4 Aug 2019 12:20:30 +0200 Subject: provider: skip non-provider has() feature-names We don't want to retry autoload sourcing (slow) for every random has() query that finds it way to eval_call_provider(). --- test/functional/fixtures/autoload/provider/brokencall.vim | 2 -- test/functional/fixtures/autoload/provider/brokenenabled.vim | 6 ------ test/functional/fixtures/autoload/provider/python.vim | 6 ++++++ test/functional/fixtures/autoload/provider/ruby.vim | 2 ++ 4 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 test/functional/fixtures/autoload/provider/brokencall.vim delete mode 100644 test/functional/fixtures/autoload/provider/brokenenabled.vim create mode 100644 test/functional/fixtures/autoload/provider/python.vim create mode 100644 test/functional/fixtures/autoload/provider/ruby.vim (limited to 'test/functional/fixtures') diff --git a/test/functional/fixtures/autoload/provider/brokencall.vim b/test/functional/fixtures/autoload/provider/brokencall.vim deleted file mode 100644 index cad2b2a640..0000000000 --- a/test/functional/fixtures/autoload/provider/brokencall.vim +++ /dev/null @@ -1,2 +0,0 @@ -" A dummy test provider -let g:loaded_brokencall_provider = 2 diff --git a/test/functional/fixtures/autoload/provider/brokenenabled.vim b/test/functional/fixtures/autoload/provider/brokenenabled.vim deleted file mode 100644 index dd33ce66f3..0000000000 --- a/test/functional/fixtures/autoload/provider/brokenenabled.vim +++ /dev/null @@ -1,6 +0,0 @@ -" Dummy test provider, missing this required variable: -" let g:loaded_brokenenabled_provider = 0 - -function! provider#brokenenabled#Call(method, args) - return 42 -endfunction diff --git a/test/functional/fixtures/autoload/provider/python.vim b/test/functional/fixtures/autoload/provider/python.vim new file mode 100644 index 0000000000..d68360ac30 --- /dev/null +++ b/test/functional/fixtures/autoload/provider/python.vim @@ -0,0 +1,6 @@ +" Dummy test provider, missing this required variable: +" let g:loaded_brokenenabled_provider = 0 + +function! provider#python#Call(method, args) + return 42 +endfunction diff --git a/test/functional/fixtures/autoload/provider/ruby.vim b/test/functional/fixtures/autoload/provider/ruby.vim new file mode 100644 index 0000000000..35becc27ff --- /dev/null +++ b/test/functional/fixtures/autoload/provider/ruby.vim @@ -0,0 +1,2 @@ +" A dummy test provider +let g:loaded_ruby_provider = 2 -- cgit