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/provider/provider_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/functional/provider/provider_spec.lua (limited to 'test/functional/provider') 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 --- test/functional/provider/provider_spec.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/functional/provider') 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 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/provider/provider_spec.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/functional/provider') 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/functional/provider') 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