Files
neovim/runtime/lua/provider/perl/health.lua
dundargoc 2e982f1aad refactor: create function for deferred loading
The benefit of this is that users only pay for what they use. If e.g.
only `vim.lsp.buf_get_clients()` is called then they don't need to load
all modules under `vim.lsp` which could lead to significant startuptime
saving.

Also `vim.lsp.module` is a bit nicer to user compared to
`require("vim.lsp.module")`.

This isn't used for some nested modules such as `filetype` as it breaks
tests with error messages such as "attempt to index field 'detect'".
It's not entirely certain the reason for this, but it is likely it is
due to filetype being precompiled which would imply deferred loading
isn't needed for performance reasons.
2024-02-03 16:53:41 +01:00

91 lines
2.8 KiB
Lua

local health = vim.health
local M = {}
function M.check()
health.start('Perl provider (optional)')
if health.provider_disabled('perl') then
return
end
local perl_exec, perl_warnings = vim.provider.perl.detect()
if not perl_exec then
health.warn(assert(perl_warnings), {
'See :help provider-perl for more information.',
'You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim',
})
health.warn('No usable perl executable found')
return
end
health.info('perl executable: ' .. perl_exec)
-- we cannot use cpanm that is on the path, as it may not be for the perl
-- set with g:perl_host_prog
local ok = health.cmd_ok({ perl_exec, '-W', '-MApp::cpanminus', '-e', '' })
if not ok then
return { perl_exec, '"App::cpanminus" module is not installed' }
end
local latest_cpan_cmd = {
perl_exec,
'-MApp::cpanminus::fatscript',
'-e',
'my $app = App::cpanminus::script->new; $app->parse_options ("--info", "-q", "Neovim::Ext"); exit $app->doit',
}
local latest_cpan
ok, latest_cpan = health.cmd_ok(latest_cpan_cmd)
if not ok or latest_cpan:find('^%s*$') then
health.error(
'Failed to run: ' .. table.concat(latest_cpan_cmd, ' '),
{ "Make sure you're connected to the internet.", 'Are you behind a firewall or proxy?' }
)
return
elseif latest_cpan[1] == '!' then
local cpanm_errs = vim.split(latest_cpan, '!')
if cpanm_errs[1]:find("Can't write to ") then
local advice = {}
for i = 2, #cpanm_errs do
advice[#advice + 1] = cpanm_errs[i]
end
health.warn(cpanm_errs[1], advice)
-- Last line is the package info
latest_cpan = cpanm_errs[#cpanm_errs]
else
health.error('Unknown warning from command: ' .. latest_cpan_cmd, cpanm_errs)
return
end
end
latest_cpan = vim.fn.matchstr(latest_cpan, [[\(\.\?\d\)\+]])
if latest_cpan:find('^%s*$') then
health.error('Cannot parse version number from cpanm output: ' .. latest_cpan)
return
end
local current_cpan_cmd = { perl_exec, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION' }
local current_cpan
ok, current_cpan = health.cmd_ok(current_cpan_cmd)
if not ok then
health.error(
'Failed to run: ' .. table.concat(current_cpan_cmd, ' '),
{ 'Report this issue with the output of: ', table.concat(current_cpan_cmd, ' ') }
)
return
end
if vim.version.lt(current_cpan, latest_cpan) then
local message = 'Module "Neovim::Ext" is out-of-date. Installed: '
.. current_cpan
.. ', latest: '
.. latest_cpan
health.warn(message, 'Run in shell: cpanm -n Neovim::Ext')
else
health.ok('Latest "Neovim::Ext" cpan module is installed: ' .. current_cpan)
end
end
return M