mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
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.
This commit is contained in:
committed by
Justin M. Keyes
parent
ad7211ac8f
commit
f25f6c8d13
@ -439,6 +439,7 @@ UI
|
||||
• |ui-messages| content chunks now also contain the highlight group ID.
|
||||
• |:checkhealth| can display in a floating window, controlled by the
|
||||
|g:health| variable.
|
||||
• |:checkhealth| shows a summary in the header for every healthcheck.
|
||||
|
||||
VIMSCRIPT
|
||||
|
||||
|
@ -116,6 +116,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)
|
||||
@ -296,6 +297,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.
|
||||
@ -305,6 +307,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)
|
||||
@ -351,6 +354,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.
|
||||
---
|
||||
@ -408,9 +428,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
|
||||
@ -431,10 +451,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),
|
||||
'',
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
test_plug.full_render: require("test_plug.full_render.health").check()
|
||||
test_plug.full_render: 1 ⚠️ 1 ❌
|
||||
|
||||
report 1 ~
|
||||
- ✅ OK life is fine
|
||||
@ -150,7 +150,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
test_plug: require("test_plug.health").check()
|
||||
test_plug: ✅
|
||||
|
||||
report 1 ~
|
||||
- ✅ OK everything is fine
|
||||
@ -159,7 +159,7 @@ describe('vim.health', function()
|
||||
- ✅ OK nothing to see here
|
||||
|
||||
==============================================================================
|
||||
test_plug.success1: require("test_plug.success1.health").check()
|
||||
test_plug.success1: ✅
|
||||
|
||||
report 1 ~
|
||||
- ✅ OK everything is fine
|
||||
@ -168,7 +168,7 @@ describe('vim.health', function()
|
||||
- ✅ OK nothing to see here
|
||||
|
||||
==============================================================================
|
||||
test_plug.success2: require("test_plug.success2.health").check()
|
||||
test_plug.success2: ✅
|
||||
|
||||
another 1 ~
|
||||
- ✅ OK ok
|
||||
@ -180,7 +180,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
test_plug.submodule: require("test_plug.submodule.health").check()
|
||||
test_plug.submodule: ✅
|
||||
|
||||
report 1 ~
|
||||
- ✅ OK everything is fine
|
||||
@ -195,7 +195,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
|
||||
test_plug.submodule_empty: 1 ❌
|
||||
|
||||
- ❌ ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty.
|
||||
]])
|
||||
@ -221,7 +221,7 @@ describe('vim.health', function()
|
||||
- ❌ {Error:ERROR} No healthcheck found for "foo" plugin. |
|
||||
|
|
||||
{Bar: }|
|
||||
{h1:test_plug.success1: require("test_pl}|
|
||||
{h1:test_plug.success1: }|
|
||||
|
|
||||
{h2:report 1} |
|
||||
- ✅ {Ok:OK} everything is fine |
|
||||
@ -236,7 +236,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
non_existent_healthcheck:
|
||||
non_existent_healthcheck: 1 ❌
|
||||
|
||||
- ❌ ERROR No healthcheck found for "non_existent_healthcheck" plugin.
|
||||
]])
|
||||
@ -254,7 +254,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
test_plug.lua: require("test_plug.lua.health").check()
|
||||
test_plug.lua: ✅
|
||||
|
||||
nested lua/ directory ~
|
||||
- ✅ OK everything is ok
|
||||
@ -272,7 +272,7 @@ describe('vim.health', function()
|
||||
n.expect([[
|
||||
|
||||
==============================================================================
|
||||
nest: require("nest.health").check()
|
||||
nest: ✅
|
||||
|
||||
healthy pack ~
|
||||
- ✅ OK healthy ok
|
||||
@ -306,14 +306,14 @@ describe(':checkhealth window', function()
|
||||
^ |
|
||||
{14: }|
|
||||
{14: } |
|
||||
{h1:test_plug.success1: }|
|
||||
{h1:require("test_plug.success1.health").check()} |
|
||||
{h1:test_plug. }|
|
||||
{h1:success1: }|
|
||||
{h1: ✅} |
|
||||
|
|
||||
{h2:report 1} |
|
||||
- ✅ {32:OK} everything is fine |
|
||||
|
|
||||
{h2:report 2} |
|
||||
- ✅ {32:OK} nothing to see here |
|
||||
## grid 3
|
||||
|
|
||||
]],
|
||||
@ -349,8 +349,8 @@ describe(':checkhealth window', function()
|
||||
{14: } |
|
||||
{h1:test_plug. }|
|
||||
{h1:success1: }|
|
||||
{h1:require("test_plug. }|
|
||||
{h1:success1.health").check()}|
|
||||
{h1: }|
|
||||
{h1: ✅} |
|
||||
|
|
||||
{h2:report 1} |
|
||||
- ✅ {32:OK} everything is |
|
||||
@ -408,15 +408,15 @@ describe(':checkhealth window', function()
|
||||
^ |
|
||||
|
|
||||
|
|
||||
test_plug.success1: |
|
||||
require("test_plug.success1.health").check() |
|
||||
test_plug. |
|
||||
success1: |
|
||||
✅ |
|
||||
|
|
||||
report 1 |
|
||||
- ✅ OK everything is fine |
|
||||
|
|
||||
report 2 |
|
||||
- ✅ OK nothing to see here |
|
||||
|
|
||||
]]):format(
|
||||
top
|
||||
and [[
|
||||
|
Reference in New Issue
Block a user