|
|
local M = {} |
|
|
local s_err |
|
|
local s_host |
|
|
|
|
|
function M.require(host, prog) |
|
|
local args = { prog, '-e', 'use Neovim::Ext; start_host();' } |
|
|
|
|
|
|
|
|
local perl_plugins = vim.fn['remote#host#PluginsForHost'](host.name) |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
function M.detect() |
|
|
|
|
|
local prog = vim.fn.exepath(vim.g.perl_host_prog or 'perl') |
|
|
if prog == '' then |
|
|
return nil, 'No perl executable found' |
|
|
end |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
local ok, result = pcall(vim.fn['remote#host#Require'], 'legacy-perl-provider') |
|
|
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() |
|
|
|
|
|
vim.fn['remote#host#RegisterClone']('legacy-perl-provider', 'perl') |
|
|
vim.fn['remote#host#RegisterPlugin']('legacy-perl-provider', 'ScriptHost.pm', {}) |
|
|
end |
|
|
|
|
|
return M |
|
|
|