diff options
author | Javier Lopez <graulopezjavier@gmail.com> | 2022-05-31 13:10:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 11:10:18 -0700 |
commit | e6652821bd32e4ff8d62a0b67fc2041a5f41e252 (patch) | |
tree | cc5106c44d65f8f504a4f3ba6654b918a6f33c13 /runtime | |
parent | 7380ebfc17723662f6fe1e38372f54b3d67fe082 (diff) | |
download | rneovim-e6652821bd32e4ff8d62a0b67fc2041a5f41e252.tar.gz rneovim-e6652821bd32e4ff8d62a0b67fc2041a5f41e252.tar.bz2 rneovim-e6652821bd32e4ff8d62a0b67fc2041a5f41e252.zip |
refactor(checkhealth)!: rename to vim.health, move logic to Lua #18720
- Complete function:
There was lots of unnecessary C code for the complete function, therefore
moving it to Lua and use all the plumbing we have in place to retrieve the
results.
- Moving the module:
It's important we keep nvim lua modules name spaced, avoids conflict with
plugins, luarocks, etc.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/pi_health.txt | 24 | ||||
-rw-r--r-- | runtime/lua/health.lua | 29 | ||||
-rw-r--r-- | runtime/lua/vim/_editor.lua | 1 | ||||
-rw-r--r-- | runtime/lua/vim/health.lua | 47 |
4 files changed, 65 insertions, 36 deletions
diff --git a/runtime/doc/pi_health.txt b/runtime/doc/pi_health.txt index 179c1066cd..04e04b5165 100644 --- a/runtime/doc/pi_health.txt +++ b/runtime/doc/pi_health.txt @@ -48,27 +48,26 @@ Commands *health-commands* :checkhealth vim* < ============================================================================== -Lua Functions *health-functions-lua* *health-lua* +Lua Functions *health-functions-lua* *health-lua* *vim.health* The Lua "health" module can be used to create new healthchecks (see also -|health-functions-vim|). To get started, simply use: > - local health = require('health') -< -health.report_start({name}) *health.report_start()* +|health-functions-vim|). To get started, simply use: + +vim.health.report_start({name}) *vim.health.report_start()* Starts a new report. Most plugins should call this only once, but if you want different sections to appear in your report, call this once per section. -health.report_info({msg}) *health.report_info()* +vim.health.report_info({msg}) *vim.health.report_info()* Reports an informational message. -health.report_ok({msg}) *health.report_ok()* +vim.health.report_ok({msg}) *vim.health.report_ok()* Reports a "success" message. -health.report_warn({msg} [, {advice}]) *health.report_warn()* +vim.health.report_warn({msg} [, {advice}]) *vim.health.report_warn()* Reports a warning. {advice} is an optional List of suggestions. -health.report_error({msg} [, {advice}]) *health.report_error()* +vim.health.report_error({msg} [, {advice}]) *vim.health.report_error()* Reports an error. {advice} is an optional List of suggestions. ============================================================================== @@ -98,15 +97,14 @@ Copy this sample code into `lua/foo/health/init.lua` or `lua/foo/health.lua`, replacing "foo" in the path with your plugin name: > local M = {} - local health = require("health") M.check = function() - health.report_start("my_plugin report") + vim.health.report_start("my_plugin report") -- make sure setup function parameters are ok if check_setup() then - health.report_ok("Setup function is correct") + vim.health.report_ok("Setup function is correct") else - health.report_error("Setup function is incorrect") + vim.health.report_error("Setup function is incorrect") end -- do some more checking -- ... diff --git a/runtime/lua/health.lua b/runtime/lua/health.lua index 142a353bf2..40e2b3c3e7 100644 --- a/runtime/lua/health.lua +++ b/runtime/lua/health.lua @@ -1,23 +1,6 @@ -local M = {} - -function M.report_start(msg) - vim.fn['health#report_start'](msg) -end - -function M.report_info(msg) - vim.fn['health#report_info'](msg) -end - -function M.report_ok(msg) - vim.fn['health#report_ok'](msg) -end - -function M.report_warn(msg, ...) - vim.fn['health#report_warn'](msg, ...) -end - -function M.report_error(msg, ...) - vim.fn['health#report_error'](msg, ...) -end - -return M +return setmetatable({}, { + __index = function(_, k) + vim.deprecate("require('health')", 'vim.health', '0.9', false) + return vim.health[k] + end, +}) diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index e6ab48f30d..c8a0aa8260 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -49,6 +49,7 @@ for k, v in pairs({ diagnostic = true, keymap = true, ui = true, + health = true, }) do vim._submodules[k] = v end diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua new file mode 100644 index 0000000000..67c5c3b37f --- /dev/null +++ b/runtime/lua/vim/health.lua @@ -0,0 +1,47 @@ +local M = {} + +function M.report_start(msg) + vim.fn['health#report_start'](msg) +end + +function M.report_info(msg) + vim.fn['health#report_info'](msg) +end + +function M.report_ok(msg) + vim.fn['health#report_ok'](msg) +end + +function M.report_warn(msg, ...) + vim.fn['health#report_warn'](msg, ...) +end + +function M.report_error(msg, ...) + vim.fn['health#report_error'](msg, ...) +end + +local path2name = function(path) + if path:match('%.lua$') then + -- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp" + return path:gsub('.-lua[%\\%/]', '', 1):gsub('[%\\%/]', '.'):gsub('%.health.-$', '') + else + -- Vim: transform "../autoload/health/provider.vim" into "provider" + return vim.fn.fnamemodify(path, ':t:r') + end +end + +local PATTERNS = { '/autoload/health/*.vim', '/lua/**/**/health.lua', '/lua/**/**/health/init.lua' } +-- :checkhealth completion function used by ex_getln.c get_healthcheck_names() +M._complete = function() + local names = vim.tbl_flatten(vim.tbl_map(function(pattern) + return vim.tbl_map(path2name, vim.api.nvim_get_runtime_file(pattern, true)) + end, PATTERNS)) + -- Remove duplicates + local unique = {} + vim.tbl_map(function(f) + unique[f] = true + end, names) + return vim.tbl_keys(unique) +end + +return M |