From 576db141be6e4d9b5d9b840c599bac670df25d1a Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 22 Jan 2024 22:07:14 +0100 Subject: refactor: rewrite perl provider in lua --- runtime/lua/vim/provider/perl.lua | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 runtime/lua/vim/provider/perl.lua (limited to 'runtime/lua/vim/provider/perl.lua') diff --git a/runtime/lua/vim/provider/perl.lua b/runtime/lua/vim/provider/perl.lua new file mode 100644 index 0000000000..8918c9792e --- /dev/null +++ b/runtime/lua/vim/provider/perl.lua @@ -0,0 +1,66 @@ +local M = {} +local s_err ---@type string? +local s_host ---@type string? + +function M.require(host, prog) + local args = { prog, '-e', 'use Neovim::Ext; start_host();' } + + -- Collect registered perl plugins into args + local perl_plugins = vim.fn['remote#host#PluginsForHost'](host.name) ---@type any + ---@param plugin any + for _, plugin in ipairs(perl_plugins) do + table.insert(args, plugin.path) + end + + return vim.fn['provider#Poll'](args, host.orig_name, '$NVIM_PERL_LOG_FILE') +end + +--- @return string? path to detected perl, if any; nil if not found +--- @return string? error message if perl can't be detected; nil if success +function M.detect() + -- use g:perl_host_prog if set or check if perl is on the path + local prog = vim.fn.exepath(vim.g.perl_host_prog or 'perl') + if prog == '' then + return nil, 'No perl executable found' + end + + -- if perl is available, make sure we have 5.22+ + vim.fn.system({ prog, '-e', 'use v5.22' }) + if vim.v.shell_error ~= 0 then + return nil, 'Perl version is too old, 5.22+ required' + end + + -- if perl is available, make sure the required module is available + vim.fn.system({ prog, '-W', '-MNeovim::Ext', '-e', '' }) + if vim.v.shell_error ~= 0 then + return nil, '"Neovim::Ext" cpan module is not installed' + end + return prog, nil +end + +function M.call(method, args) + if s_err then + return + end + + if not s_host then + -- Ensure that we can load the Perl host before bootstrapping + local ok, result = pcall(vim.fn['remote#host#Require'], 'legacy-perl-provider') ---@type any, any + if not ok then + s_err = result + vim.api.nvim_echo({ result, 'WarningMsg' }, true, {}) + return + end + s_host = result + end + + return vim.fn.rpcrequest(s_host, 'perl_' .. method, unpack(args)) +end + +function M.start() + -- The perl provider plugin will run in a separate instance of the perl host. + vim.fn['remote#host#RegisterClone']('legacy-perl-provider', 'perl') + vim.fn['remote#host#RegisterPlugin']('legacy-perl-provider', 'ScriptHost.pm', {}) +end + +return M -- cgit From b280d57db9845359186bfb5167e1559b6184f8d5 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 22 Jan 2024 22:07:14 +0100 Subject: refactor: rewrite ruby provider in lua --- runtime/lua/vim/provider/perl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/provider/perl.lua') diff --git a/runtime/lua/vim/provider/perl.lua b/runtime/lua/vim/provider/perl.lua index 8918c9792e..da4af0a2a7 100644 --- a/runtime/lua/vim/provider/perl.lua +++ b/runtime/lua/vim/provider/perl.lua @@ -48,7 +48,7 @@ function M.call(method, args) local ok, result = pcall(vim.fn['remote#host#Require'], 'legacy-perl-provider') ---@type any, any if not ok then s_err = result - vim.api.nvim_echo({ result, 'WarningMsg' }, true, {}) + vim.api.nvim_echo({ { result, 'WarningMsg' } }, true, {}) return end s_host = result -- cgit