feat(health): highlight headings #30525

Problem:
checkhealth report sections are not visually separated.

Solution:
Highlight with "reverse".

TODO: migrate checkhealth filetype to use treesitter.
TODO: default :help should also highlight headings more boldy!
This commit is contained in:
Justin M. Keyes 2024-09-26 07:45:03 -07:00 committed by GitHub
parent efcfcb1efc
commit f2fa4ca97e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 35 deletions

View File

@ -379,7 +379,14 @@ function M._check(mods, plugin_names)
s_output = {} s_output = {}
M.error('The healthcheck report for "' .. name .. '" plugin is empty.') M.error('The healthcheck report for "' .. name .. '" plugin is empty.')
end end
local header = { string.rep('=', 78), name .. ': ' .. func, '' }
local header = {
string.rep('=', 78),
-- Example: `foo.health: [ …] require("foo.health").check()`
('%s: %s%s'):format(name, (' '):rep(76 - name:len() - func:len()), func),
'',
}
-- remove empty line after header from report_start -- remove empty line after header from report_start
if s_output[1] == '' then if s_output[1] == '' then
local tmp = {} ---@type string[] local tmp = {} ---@type string[]

View File

@ -14,7 +14,9 @@ syn case match
syn keyword DiagnosticError ERROR[:] syn keyword DiagnosticError ERROR[:]
syn keyword DiagnosticWarn WARNING[:] syn keyword DiagnosticWarn WARNING[:]
syn keyword DiagnosticOk OK[:] syn keyword DiagnosticOk OK[:]
syn match helpSectionDelim "^======*\n.*$" " Note: hs=e starts higlighting on the title line (instead of the "===" line).
syn match healthHeadingChar "=" conceal cchar=contained containedin=helpSectionDelim syn match helpSectionDelim /^======*\n.*$/hs=e
highlight helpSectionDelim gui=reverse cterm=reverse
syn match healthHeadingChar "=" conceal cchar= contained containedin=helpSectionDelim
let b:current_syntax = "checkhealth" let b:current_syntax = "checkhealth"

View File

@ -157,9 +157,10 @@ describe('vim.health', function()
local screen = Screen.new(50, 12) local screen = Screen.new(50, 12)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
h1 = { reverse = true },
h2 = { foreground = tonumber('0x6a0dad') },
Ok = { foreground = Screen.colors.LightGreen }, Ok = { foreground = Screen.colors.LightGreen },
Error = { foreground = Screen.colors.Red }, Error = { foreground = Screen.colors.Red },
Heading = { foreground = tonumber('0x6a0dad') },
Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey }, Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey },
}) })
command('checkhealth foo success1') command('checkhealth foo success1')
@ -167,15 +168,15 @@ describe('vim.health', function()
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
{Bar:}| {Bar: }|
{Heading:foo: } | {h1:foo: }|
| |
- {Error:ERROR} No healthcheck found for "foo" plugin. | - {Error:ERROR} No healthcheck found for "foo" plugin. |
| |
{Bar:}| {Bar: }|
{Heading:test_plug.success1: require("test_plug.success1.he}| {h1:test_plug.success1: require("test_pl}|
| |
{Heading:report 1} | {h2:report 1} |
- {Ok:OK} everything is fine | - {Ok:OK} everything is fine |
| |
]], ]],
@ -223,9 +224,10 @@ describe(':checkhealth window', function()
it('opens directly if no buffer created', function() it('opens directly if no buffer created', function()
local screen = Screen.new(50, 12) local screen = Screen.new(50, 12)
screen:set_default_attr_ids { screen:set_default_attr_ids {
h1 = { reverse = true },
h2 = { foreground = tonumber('0x6a0dad') },
[1] = { foreground = Screen.colors.Blue, bold = true }, [1] = { foreground = Screen.colors.Blue, bold = true },
[14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray },
[31] = { foreground = tonumber('0x6a0dad') },
[32] = { foreground = Screen.colors.PaleGreen2 }, [32] = { foreground = Screen.colors.PaleGreen2 },
} }
screen:attach({ ext_multigrid = true }) screen:attach({ ext_multigrid = true })
@ -237,15 +239,15 @@ describe(':checkhealth window', function()
[3:--------------------------------------------------]| [3:--------------------------------------------------]|
## grid 2 ## grid 2
^ | ^ |
{14:}| {14: }|
{14:} | {14: } |
{31:test_plug.success1: require("test_plug.success1. }| {h1:test_plug.success1: }|
{31:health").check()} | {h1:require("test_plug.success1.health").check()} |
| |
{31:report 1} | {h2:report 1} |
- {32:OK} everything is fine | - {32:OK} everything is fine |
| |
{31:report 2} | {h2:report 2} |
- {32:OK} nothing to see here | - {32:OK} nothing to see here |
## grid 3 ## grid 3
| |
@ -256,9 +258,10 @@ describe(':checkhealth window', function()
local function test_health_vsplit(left, emptybuf, mods) local function test_health_vsplit(left, emptybuf, mods)
local screen = Screen.new(50, 20) local screen = Screen.new(50, 20)
screen:set_default_attr_ids { screen:set_default_attr_ids {
h1 = { reverse = true },
h2 = { foreground = tonumber('0x6a0dad') },
[1] = { foreground = Screen.colors.Blue, bold = true }, [1] = { foreground = Screen.colors.Blue, bold = true },
[14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray },
[31] = { foreground = tonumber('0x6a0dad') },
[32] = { foreground = Screen.colors.PaleGreen2 }, [32] = { foreground = Screen.colors.PaleGreen2 },
} }
screen:attach({ ext_multigrid = true }) screen:attach({ ext_multigrid = true })
@ -278,19 +281,20 @@ describe(':checkhealth window', function()
| |
## grid 4 ## grid 4
^ | ^ |
{14:}|*3 {14: }|*3
{14:} | {14: } |
{31:test_plug.success1: }| {h1:test_plug. }|
{31:require("test_plug. }| {h1:success1: }|
{31:success1.health").check()}| {h1:require("test_plug. }|
{h1:success1.health").check()}|
| |
{31:report 1} | {h2:report 1} |
- {32:OK} everything is fine | - {32:OK} everything is fine |
| |
{31:report 2} | {h2:report 2} |
- {32:OK} nothing to see here | - {32:OK} nothing to see here |
| |
{1:~ }|*4 {1:~ }|*3
]]):format( ]]):format(
left and '[4:-------------------------]│[2:------------------------]|*19' left and '[4:-------------------------]│[2:------------------------]|*19'
or '[2:------------------------]│[4:-------------------------]|*19', or '[2:------------------------]│[4:-------------------------]|*19',
@ -337,10 +341,10 @@ describe(':checkhealth window', function()
| |
## grid 4 ## grid 4
^ | ^ |
| |
| |
test_plug.success1: require("test_plug.success1. | test_plug.success1: |
health").check() | require("test_plug.success1.health").check() |
| |
report 1 | report 1 |
- OK everything is fine | - OK everything is fine |