From 164f1ea06d17e935f41e178e46bb05bbb676af20 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 10 Apr 2023 16:48:58 -0600 Subject: refactor(health): refactor provider healthchecks * Prefer pure Lua functions over vim.fn * Split up provider healthchecks into separate modules to help manage complexity --- runtime/lua/provider/perl/health.lua | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 runtime/lua/provider/perl/health.lua (limited to 'runtime/lua/provider/perl') diff --git a/runtime/lua/provider/perl/health.lua b/runtime/lua/provider/perl/health.lua new file mode 100644 index 0000000000..d14ebc97ab --- /dev/null +++ b/runtime/lua/provider/perl/health.lua @@ -0,0 +1,95 @@ +local health = vim.health + +local M = {} + +function M.check() + health.start('Perl provider (optional)') + + if health.provider_disabled('perl') then + return + end + + local perl_detect_table = vim.fn['provider#perl#Detect']() + local perl_exec = perl_detect_table[1] + local perl_warnings = perl_detect_table[2] + + if perl_exec:find('^%s*$') then + if perl_warnings:find('%S') then + health.warn(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', + }) + else + health.warn('No usable perl executable found') + end + 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 -- cgit 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/provider/perl/health.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'runtime/lua/provider/perl') diff --git a/runtime/lua/provider/perl/health.lua b/runtime/lua/provider/perl/health.lua index d14ebc97ab..6066c69968 100644 --- a/runtime/lua/provider/perl/health.lua +++ b/runtime/lua/provider/perl/health.lua @@ -9,19 +9,14 @@ function M.check() return end - local perl_detect_table = vim.fn['provider#perl#Detect']() - local perl_exec = perl_detect_table[1] - local perl_warnings = perl_detect_table[2] + local perl_exec, perl_warnings = require('vim.provider.perl').detect() - if perl_exec:find('^%s*$') then - if perl_warnings:find('%S') then - health.warn(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', - }) - else - health.warn('No usable perl executable found') - end + 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 -- cgit From 2e982f1aad9f1a03562b7a451d642f76b04c37cb Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 22 Jan 2024 18:23:28 +0100 Subject: 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. --- runtime/lua/provider/perl/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/provider/perl') diff --git a/runtime/lua/provider/perl/health.lua b/runtime/lua/provider/perl/health.lua index 6066c69968..535093d793 100644 --- a/runtime/lua/provider/perl/health.lua +++ b/runtime/lua/provider/perl/health.lua @@ -9,7 +9,7 @@ function M.check() return end - local perl_exec, perl_warnings = require('vim.provider.perl').detect() + local perl_exec, perl_warnings = vim.provider.perl.detect() if not perl_exec then health.warn(assert(perl_warnings), { -- cgit