diff options
author | Yochem van Rosmalen <git@yochem.nl> | 2025-04-09 13:13:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-09 04:13:20 -0700 |
commit | 5a94edad70f9c47250fa53dd73cf30f191a3cd49 (patch) | |
tree | f47f636000b7b3bd4327a276d8f82d01eb756880 /runtime/lua/vim/health.lua | |
parent | ff2cbe8facd56e27705e6ada2c08136773e5bbe8 (diff) | |
download | rneovim-5a94edad70f9c47250fa53dd73cf30f191a3cd49.tar.gz rneovim-5a94edad70f9c47250fa53dd73cf30f191a3cd49.tar.bz2 rneovim-5a94edad70f9c47250fa53dd73cf30f191a3cd49.zip |
feat(health): summary in section heading #33388
Problem:
As checkhealth grows, it is increasingly hard to quickly glance through
the information.
Solution:
Show a summary of ok, warn, and error outputs per section.
Diffstat (limited to 'runtime/lua/vim/health.lua')
-rw-r--r-- | runtime/lua/vim/health.lua | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index 294f2a357a..302cc6bc99 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -106,6 +106,7 @@ local M = {} local s_output = {} ---@type string[] +local check_summary = { warn = 0, error = 0 } -- From a path return a list [{name}, {func}, {type}] representing a healthcheck local function filepath_to_healthcheck(path) @@ -286,6 +287,7 @@ end function M.warn(msg, ...) local input = format_report_message('⚠️ WARNING', msg, ...) collect_output(input) + check_summary['warn'] = check_summary['warn'] + 1 end --- Reports an error. @@ -295,6 +297,7 @@ end function M.error(msg, ...) local input = format_report_message('❌ ERROR', msg, ...) collect_output(input) + check_summary['error'] = check_summary['error'] + 1 end local path2name = function(path) @@ -341,6 +344,23 @@ M._complete = function() return rv end +--- Gets the results heading for the current report section. +--- +---@return string +local function get_summary() + local s = '' + local errors = check_summary['error'] + local warns = check_summary['warn'] + + s = s .. (warns > 0 and (' %2d ⚠️'):format(warns) or '') + s = s .. (errors > 0 and (' %2d ❌'):format(errors) or '') + if errors == 0 and warns == 0 then + s = s .. '✅' + end + + return s +end + --- Runs the specified healthchecks. --- Runs all discovered healthchecks if plugin_names is empty. --- @@ -397,9 +417,9 @@ function M._check(mods, plugin_names) local func = value[1] local type = value[2] s_output = {} + check_summary = { warn = 0, error = 0 } if func == '' then - s_output = {} M.error('No healthcheck found for "' .. name .. '" plugin.') end if type == 'v' then @@ -420,10 +440,12 @@ function M._check(mods, plugin_names) M.error('The healthcheck report for "' .. name .. '" plugin is empty.') end + local report = get_summary() + local replen = vim.fn.strwidth(report) local header = { string.rep('=', 78), - -- Example: `foo.health: [ …] require("foo.health").check()` - ('%s: %s%s'):format(name, (' '):rep(76 - name:len() - func:len()), func), + -- Example: `foo.health: [ …] 1 ⚠️ 5 ❌` + ('%s: %s%s'):format(name, (' '):rep(76 - name:len() - replen), report), '', } |