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. --- .../fixtures/autoload/provider/brokencall.vim | 2 ++ .../fixtures/autoload/provider/brokenenabled.vim | 6 ++++++ .../fixtures/autoload/provider/clipboard.vim | 1 + test/functional/provider/provider_spec.lua | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/functional/fixtures/autoload/provider/brokencall.vim create mode 100644 test/functional/fixtures/autoload/provider/brokenenabled.vim create mode 100644 test/functional/provider/provider_spec.lua (limited to 'test') 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) diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua new file mode 100644 index 0000000000..6f414f36f4 --- /dev/null +++ b/test/functional/provider/provider_spec.lua @@ -0,0 +1,19 @@ + +local helpers = require('test.functional.helpers')(after_each) +local clear, eq, feed_command, eval = helpers.clear, helpers.eq, helpers.feed_command, helpers.eval + +describe('Providers', function() + before_each(function() + clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp') + end) + + it('must set the enabled variable or fail', function() + eq(42, eval("provider#brokenenabled#Call('dosomething', [])")) + feed_command("call has('brokenenabled')") + eq(0, eval("has('brokenenabled')")) + end) + + it('without Call() are enabled', function() + eq(1, eval("has('brokencall')")) + end) +end) -- 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 --- .../functional/fixtures/autoload/provider/brokencall.vim | 2 +- .../fixtures/autoload/provider/brokenenabled.vim | 4 ++-- test/functional/fixtures/autoload/provider/clipboard.vim | 4 ++-- test/functional/provider/provider_spec.lua | 16 +++++++++------- 4 files changed, 14 insertions(+), 12 deletions(-) (limited to 'test') 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 diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua index 6f414f36f4..b690cf2566 100644 --- a/test/functional/provider/provider_spec.lua +++ b/test/functional/provider/provider_spec.lua @@ -1,19 +1,21 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, feed_command, eval = helpers.clear, helpers.eq, helpers.feed_command, helpers.eval +local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval +local command = helpers.command +local expect_err = helpers.expect_err -describe('Providers', function() +describe('providers', function() before_each(function() clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp') end) - it('must set the enabled variable or fail', function() - eq(42, eval("provider#brokenenabled#Call('dosomething', [])")) - feed_command("call has('brokenenabled')") - eq(0, eval("has('brokenenabled')")) + it('must define g:loaded_xx_provider', function() + command('set loadplugins') + expect_err('Vim:provider: brokenenabled: missing required variable g:loaded_brokenenabled_provider', + eval, "has('brokenenabled')") end) - it('without Call() are enabled', function() + it('without Call() but with g:loaded_xx_provider', function() eq(1, eval("has('brokencall')")) end) end) -- 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') 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 ++ test/functional/provider/provider_spec.lua | 10 +++++++--- 5 files changed, 15 insertions(+), 11 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') 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 diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua index b690cf2566..4220ec21cf 100644 --- a/test/functional/provider/provider_spec.lua +++ b/test/functional/provider/provider_spec.lua @@ -11,11 +11,15 @@ describe('providers', function() it('must define g:loaded_xx_provider', function() command('set loadplugins') - expect_err('Vim:provider: brokenenabled: missing required variable g:loaded_brokenenabled_provider', - eval, "has('brokenenabled')") + -- Using test-fixture with broken impl: + -- test/functional/fixtures/autoload/provider/python.vim + expect_err('Vim:provider: python: missing required variable g:loaded_python_provider', + eval, "has('python')") end) it('without Call() but with g:loaded_xx_provider', function() - eq(1, eval("has('brokencall')")) + -- Using test-fixture with broken impl: + -- test/functional/fixtures/autoload/provider/ruby.vim + eq(1, eval("has('ruby')")) end) end) -- cgit From 2141dc22625f73f3ce73460e581934b94f141cf9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 4 Aug 2019 12:37:05 +0200 Subject: provider: check #Call() if g:loaded_xx_provider=2 --- test/functional/provider/provider_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua index 4220ec21cf..bfb0bbc3a3 100644 --- a/test/functional/provider/provider_spec.lua +++ b/test/functional/provider/provider_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval +local clear, eval = helpers.clear, helpers.eval local command = helpers.command local expect_err = helpers.expect_err @@ -9,7 +9,7 @@ describe('providers', function() clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp') end) - it('must define g:loaded_xx_provider', function() + it('with #Call(), missing g:loaded_xx_provider', function() command('set loadplugins') -- Using test-fixture with broken impl: -- test/functional/fixtures/autoload/provider/python.vim @@ -17,9 +17,10 @@ describe('providers', function() eval, "has('python')") end) - it('without Call() but with g:loaded_xx_provider', function() + it('with g:loaded_xx_provider, missing #Call()', function() -- Using test-fixture with broken impl: -- test/functional/fixtures/autoload/provider/ruby.vim - eq(1, eval("has('ruby')")) + expect_err('Vim:provider: ruby: g:loaded_ruby_provider=2 but provider#ruby#Call is not defined', + eval, "has('ruby')") end) end) -- cgit