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/ruby/health.lua | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 runtime/lua/provider/ruby/health.lua (limited to 'runtime/lua/provider/ruby') diff --git a/runtime/lua/provider/ruby/health.lua b/runtime/lua/provider/ruby/health.lua new file mode 100644 index 0000000000..12f1ed9b80 --- /dev/null +++ b/runtime/lua/provider/ruby/health.lua @@ -0,0 +1,71 @@ +local health = vim.health +local executable = health.executable +local iswin = vim.loop.os_uname().sysname == 'Windows_NT' + +local M = {} + +function M.check() + health.start('Ruby provider (optional)') + + if health.provider_disabled('ruby') then + return + end + + if not executable('ruby') or not executable('gem') then + health.warn( + '`ruby` and `gem` must be in $PATH.', + 'Install Ruby and verify that `ruby` and `gem` commands work.' + ) + return + end + health.info('Ruby: ' .. health.system({ 'ruby', '-v' })) + + local ruby_detect_table = vim.fn['provider#ruby#Detect']() + local host = ruby_detect_table[1] + if host:find('^%s*$') then + health.warn('`neovim-ruby-host` not found.', { + 'Run `gem install neovim` to ensure the neovim RubyGem is installed.', + 'Run `gem environment` to ensure the gem bin directory is in $PATH.', + 'If you are using rvm/rbenv/chruby, try "rehashing".', + 'See :help g:ruby_host_prog for non-standard gem installations.', + 'You may disable this provider (and warning) by adding `let g:loaded_ruby_provider = 0` to your init.vim', + }) + return + end + health.info('Host: ' .. host) + + local latest_gem_cmd = (iswin and 'cmd /c gem list -ra "^^neovim$"' or 'gem list -ra ^neovim$') + local ok, latest_gem = health.cmd_ok(vim.split(latest_gem_cmd, ' ')) + if not ok or latest_gem:find('^%s*$') then + health.error( + 'Failed to run: ' .. latest_gem_cmd, + { "Make sure you're connected to the internet.", 'Are you behind a firewall or proxy?' } + ) + return + end + local gem_split = vim.split(latest_gem, [[neovim (\|, \|)$]]) + latest_gem = gem_split[1] or 'not found' + + local current_gem_cmd = { host, '--version' } + local current_gem + ok, current_gem = health.cmd_ok(current_gem_cmd) + if not ok then + health.error( + 'Failed to run: ' .. table.concat(current_gem_cmd, ' '), + { 'Report this issue with the output of: ', table.concat(current_gem_cmd, ' ') } + ) + return + end + + if vim.version.lt(current_gem, latest_gem) then + local message = 'Gem "neovim" is out-of-date. Installed: ' + .. current_gem + .. ', latest: ' + .. latest_gem + health.warn(message, 'Run in shell: gem update neovim') + else + health.ok('Latest "neovim" gem is installed: ' .. current_gem) + end +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/provider/ruby/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/provider/ruby') diff --git a/runtime/lua/provider/ruby/health.lua b/runtime/lua/provider/ruby/health.lua index 12f1ed9b80..b102cbe535 100644 --- a/runtime/lua/provider/ruby/health.lua +++ b/runtime/lua/provider/ruby/health.lua @@ -20,7 +20,7 @@ function M.check() end health.info('Ruby: ' .. health.system({ 'ruby', '-v' })) - local ruby_detect_table = vim.fn['provider#ruby#Detect']() + local ruby_detect_table = require('vim.provider.ruby').detect() local host = ruby_detect_table[1] if host:find('^%s*$') then health.warn('`neovim-ruby-host` not found.', { -- cgit From e39b6d0c52410b59ad75312659ab278da42e42c6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 28 Jan 2024 12:59:22 -0800 Subject: fix(health): "attempt to concatenate nil" Problem: If `neovim` module is not installed, python and ruby healthchecks fail: - ERROR Failed to run healthcheck for "provider.python" plugin. Exception: .../runtime/lua/provider/python/health.lua:348: attempt to concatenate local 'pyname' (a nil value) - ERROR Failed to run healthcheck for "provider.ruby" plugin. Exception: .../runtime/lua/provider/ruby/health.lua:25: attempt to index local 'host' (a nil value) Solution: Check for non-nil. --- runtime/lua/provider/ruby/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/provider/ruby') diff --git a/runtime/lua/provider/ruby/health.lua b/runtime/lua/provider/ruby/health.lua index b102cbe535..d43d7cf9b3 100644 --- a/runtime/lua/provider/ruby/health.lua +++ b/runtime/lua/provider/ruby/health.lua @@ -22,7 +22,7 @@ function M.check() local ruby_detect_table = require('vim.provider.ruby').detect() local host = ruby_detect_table[1] - if host:find('^%s*$') then + if (not host) or host:find('^%s*$') then health.warn('`neovim-ruby-host` not found.', { 'Run `gem install neovim` to ensure the neovim RubyGem is installed.', 'Run `gem environment` to ensure the gem bin directory is in $PATH.', -- 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/ruby/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/provider/ruby') diff --git a/runtime/lua/provider/ruby/health.lua b/runtime/lua/provider/ruby/health.lua index d43d7cf9b3..04f6e303e6 100644 --- a/runtime/lua/provider/ruby/health.lua +++ b/runtime/lua/provider/ruby/health.lua @@ -20,7 +20,7 @@ function M.check() end health.info('Ruby: ' .. health.system({ 'ruby', '-v' })) - local ruby_detect_table = require('vim.provider.ruby').detect() + local ruby_detect_table = vim.provider.ruby.detect() local host = ruby_detect_table[1] if (not host) or host:find('^%s*$') then health.warn('`neovim-ruby-host` not found.', { -- cgit