feat(checkhealth): use "help" syntax, avoid tabpage #20879

- If Nvim was just started, don't create a new tab.
- Name the buffer "health://".
- Use "help" syntax instead of "markdown". It fits better, and
  eliminates various workarounds.
- Simplfy formatting, avoid visual noise.
- Don't print a "INFO" status, it is noisy.
- Drop the ":" after statuses, they are already UPPERCASE and highlighted.
This commit is contained in:
Justin M. Keyes 2022-11-11 21:33:31 -05:00 committed by GitHub
parent 2425fe2dc5
commit 4d2373f5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 116 deletions

View File

@ -5,8 +5,13 @@ function! health#check(plugin_names) abort
\ ? s:discover_healthchecks() \ ? s:discover_healthchecks()
\ : s:get_healthcheck(a:plugin_names) \ : s:get_healthcheck(a:plugin_names)
" create scratch-buffer " Create buffer and open in a tab, unless this is the default buffer when Nvim starts.
execute 'tab sbuffer' nvim_create_buf(v:true, v:true) let emptybuf = (bufnr('$') == 1 && empty(getline(1)) && 1 == line('$'))
execute (emptybuf ? 'buffer' : 'tab sbuffer') nvim_create_buf(v:true, v:true)
if bufexists('health://')
bwipe health://
endif
file health://
setfiletype checkhealth setfiletype checkhealth
if empty(healthchecks) if empty(healthchecks)
@ -38,7 +43,7 @@ function! health#check(plugin_names) abort
\ name, v:throwpoint, v:exception)) \ name, v:throwpoint, v:exception))
endif endif
endtry endtry
let header = [name. ': ' . func, repeat('=', 72)] let header = [repeat('=', 78), name .. ': ' .. func, '']
" remove empty line after header from report_start " remove empty line after header from report_start
let s:output = s:output[0] == '' ? s:output[1:] : s:output let s:output = s:output[0] == '' ? s:output[1:] : s:output
let s:output = header + s:output + [''] let s:output = header + s:output + ['']
@ -47,8 +52,7 @@ function! health#check(plugin_names) abort
endfor endfor
endif endif
" needed for plasticboy/vim-markdown, because it uses fdm=expr " Clear the 'Running healthchecks...' message.
normal! zR
redraw|echo '' redraw|echo ''
endfunction endfunction
@ -58,7 +62,7 @@ endfunction
" Starts a new report. " Starts a new report.
function! health#report_start(name) abort function! health#report_start(name) abort
call s:collect_output("\n## " . a:name) call s:collect_output(printf("\n%s ~", a:name))
endfunction endfunction
" Indents lines *except* line 1 of a string if it contains newlines. " Indents lines *except* line 1 of a string if it contains newlines.
@ -81,7 +85,7 @@ endfunction
" Format a message for a specific report item. " Format a message for a specific report item.
" a:1: Optional advice (string or list) " a:1: Optional advice (string or list)
function! s:format_report_message(status, msg, ...) abort " {{{ function! s:format_report_message(status, msg, ...) abort " {{{
let output = ' - ' . a:status . ': ' . s:indent_after_line1(a:msg, 4) let output = '- ' .. a:status .. (empty(a:status) ? '' : ' ') .. s:indent_after_line1(a:msg, 2)
" Optional parameters " Optional parameters
if a:0 > 0 if a:0 > 0
@ -92,9 +96,9 @@ function! s:format_report_message(status, msg, ...) abort " {{{
" Report each suggestion " Report each suggestion
if !empty(advice) if !empty(advice)
let output .= "\n - ADVICE:" let output .= "\n - ADVICE:"
for suggestion in advice for suggestion in advice
let output .= "\n - " . s:indent_after_line1(suggestion, 10) let output .= "\n - " . s:indent_after_line1(suggestion, 6)
endfor endfor
endif endif
endif endif
@ -102,9 +106,9 @@ function! s:format_report_message(status, msg, ...) abort " {{{
return s:help_to_link(output) return s:help_to_link(output)
endfunction " }}} endfunction " }}}
" Use {msg} to report information in the current section " Reports a message as a listitem in the current section.
function! health#report_info(msg) abort " {{{ function! health#report_info(msg) abort " {{{
call s:collect_output(s:format_report_message('INFO', a:msg)) call s:collect_output(s:format_report_message('', a:msg))
endfunction " }}} endfunction " }}}
" Reports a successful healthcheck. " Reports a successful healthcheck.

View File

@ -1,20 +1,18 @@
" Vim filetype plugin " Vim filetype plugin
" Language: Neovim checkhealth buffer " Language: Nvim :checkhealth buffer
" Last Change: 2021 Dec 15 " Last Change: 2022 Nov 10
if exists("b:did_ftplugin") if exists("b:did_ftplugin")
finish finish
endif endif
runtime! ftplugin/markdown.vim ftplugin/markdown_*.vim ftplugin/markdown/*.vim runtime! ftplugin/help.vim
setlocal wrap breakindent linebreak setlocal wrap breakindent linebreak
setlocal conceallevel=2 concealcursor=nc
setlocal keywordprg=:help
let &l:iskeyword='!-~,^*,^|,^",192-255' let &l:iskeyword='!-~,^*,^|,^",192-255'
if exists("b:undo_ftplugin") if exists("b:undo_ftplugin")
let b:undo_ftplugin .= "|setl wrap< bri< lbr< cole< cocu< kp< isk<" let b:undo_ftplugin .= "|setl wrap< bri< lbr< kp< isk<"
else else
let b:undo_ftplugin = "setl wrap< bri< lbr< cole< cocu< kp< isk<" let b:undo_ftplugin = "setl wrap< bri< lbr< kp< isk<"
endif endif

View File

@ -359,14 +359,12 @@ local function check_terminal()
\ ..'\%(conemu\|vtpcon\|win32con\)'))) \ ..'\%(conemu\|vtpcon\|win32con\)')))
call health#report_error('command failed: '.cmd."\n".out) call health#report_error('command failed: '.cmd."\n".out)
else else
call health#report_info('key_backspace (kbs) terminfo entry: ' call health#report_info(printf('key_backspace (kbs) terminfo entry: `%s`', (empty(kbs_entry) ? '? (not found)' : kbs_entry)))
\ .(empty(kbs_entry) ? '? (not found)' : kbs_entry)) call health#report_info(printf('key_dc (kdch1) terminfo entry: `%s`', (empty(kbs_entry) ? '? (not found)' : kdch1_entry)))
call health#report_info('key_dc (kdch1) terminfo entry: '
\ .(empty(kbs_entry) ? '? (not found)' : kdch1_entry))
endif endif
for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY'] for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY']
if exists('$'.env_var) if exists('$'.env_var)
call health#report_info(printf("$%s='%s'", env_var, eval('$'.env_var))) call health#report_info(printf('$%s="%s"', env_var, eval('$'.env_var)))
endif endif
endfor endfor
endf endf

View File

@ -1,26 +1,21 @@
" Vim syntax file " Vim syntax file
" Language: Neovim checkhealth buffer " Language: Nvim :checkhealth buffer
" Last Change: 2021 Dec 15 " Last Change: 2022 Nov 10
if exists("b:current_syntax") if exists("b:current_syntax")
finish finish
endif endif
runtime! syntax/markdown.vim runtime! syntax/help.vim
unlet! b:current_syntax unlet! b:current_syntax
syn case match syn case match
" We do not care about markdown syntax errors syn keyword healthError ERROR[:]
if hlexists('markdownError') syn keyword healthWarning WARNING[:]
syn clear markdownError syn keyword healthSuccess OK[:]
endif syn match helpSectionDelim "^======*\n.*$"
syn match healthHeadingChar "=" conceal cchar=contained containedin=helpSectionDelim
syn keyword healthError ERROR[:] containedin=markdownCodeBlock,mkdListItemLine
syn keyword healthWarning WARNING[:] containedin=markdownCodeBlock,mkdListItemLine
syn keyword healthSuccess OK[:] containedin=markdownCodeBlock,mkdListItemLine
syn match healthHelp "|.\{-}|" containedin=markdownCodeBlock,mkdListItemLine contains=healthBar
syn match healthBar "|" contained conceal
hi def link healthError Error hi def link healthError Error
hi def link healthWarning WarningMsg hi def link healthWarning WarningMsg

View File

@ -29,7 +29,7 @@ describe(':checkhealth', function()
-- Do this after startup, otherwise it just breaks $VIMRUNTIME. -- Do this after startup, otherwise it just breaks $VIMRUNTIME.
command("let $VIM='zub'") command("let $VIM='zub'")
command("checkhealth nvim") command("checkhealth nvim")
matches('ERROR: $VIM .* zub', curbuf_contents()) matches('ERROR $VIM .* zub', curbuf_contents())
end) end)
it('completions can be listed via getcompletion()', function() it('completions can be listed via getcompletion()', function()
clear() clear()
@ -55,21 +55,22 @@ describe('health.vim', function()
command("checkhealth full_render") command("checkhealth full_render")
helpers.expect([[ helpers.expect([[
==============================================================================
full_render: health#full_render#check full_render: health#full_render#check
========================================================================
## report 1
- OK: life is fine
- WARNING: no what installed
- ADVICE:
- pip what
- make what
## report 2 report 1 ~
- INFO: stuff is stable - OK life is fine
- ERROR: why no hardcopy - WARNING no what installed
- ADVICE: - ADVICE:
- :help |:hardcopy| - pip what
- :help |:TOhtml| - make what
report 2 ~
- stuff is stable
- ERROR why no hardcopy
- ADVICE:
- :help |:hardcopy|
- :help |:TOhtml|
]]) ]])
end) end)
@ -77,26 +78,29 @@ describe('health.vim', function()
command("checkhealth success1 success2 test_plug") command("checkhealth success1 success2 test_plug")
helpers.expect([[ helpers.expect([[
==============================================================================
success1: health#success1#check success1: health#success1#check
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
==============================================================================
success2: health#success2#check success2: health#success2#check
========================================================================
## another 1
- OK: ok
another 1 ~
- OK ok
==============================================================================
test_plug: require("test_plug.health").check() test_plug: require("test_plug.health").check()
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
]]) ]])
end) end)
@ -106,13 +110,14 @@ describe('health.vim', function()
-- and the Lua healthcheck is used instead. -- and the Lua healthcheck is used instead.
helpers.expect([[ helpers.expect([[
==============================================================================
test_plug: require("test_plug.health").check() test_plug: require("test_plug.health").check()
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
]]) ]])
end) end)
@ -120,13 +125,14 @@ describe('health.vim', function()
command("checkhealth test_plug.submodule") command("checkhealth test_plug.submodule")
helpers.expect([[ helpers.expect([[
==============================================================================
test_plug.submodule: require("test_plug.submodule.health").check() test_plug.submodule: require("test_plug.submodule.health").check()
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
]]) ]])
end) end)
@ -137,30 +143,34 @@ describe('health.vim', function()
local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5) local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5)
local expected = helpers.dedent([[ local expected = helpers.dedent([[
==============================================================================
test_plug: require("test_plug.health").check() test_plug: require("test_plug.health").check()
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
==============================================================================
test_plug.submodule: require("test_plug.submodule.health").check() test_plug.submodule: require("test_plug.submodule.health").check()
========================================================================
## report 1
- OK: everything is fine
## report 2 report 1 ~
- OK: nothing to see here - OK everything is fine
report 2 ~
- OK nothing to see here
==============================================================================
test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
========================================================================
- ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty.
- ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty.
==============================================================================
test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
========================================================================
- ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
function health#check, line 20]]) function health#check, line 25]])
eq(expected, received) eq(expected, received)
end) end)
@ -168,11 +178,12 @@ describe('health.vim', function()
command("checkhealth broken") command("checkhealth broken")
helpers.expect([[ helpers.expect([[
==============================================================================
broken: health#broken#check broken: health#broken#check
========================================================================
- ERROR: Failed to run healthcheck for "broken" plugin. Exception: - ERROR Failed to run healthcheck for "broken" plugin. Exception:
function health#check[20]..health#broken#check, line 1 function health#check[25]..health#broken#check, line 1
caused an error caused an error
]]) ]])
end) end)
@ -180,9 +191,10 @@ describe('health.vim', function()
command("checkhealth test_plug.submodule_empty") command("checkhealth test_plug.submodule_empty")
helpers.expect([[ helpers.expect([[
==============================================================================
test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
========================================================================
- ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty. - ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty.
]]) ]])
end) end)
@ -197,38 +209,38 @@ describe('health.vim', function()
local expected = global_helpers.dedent([[ local expected = global_helpers.dedent([[
==============================================================================
test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
========================================================================
- ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
function health#check, line 20]]) function health#check, line 25]])
eq(expected, received) eq(expected, received)
end) end)
it("highlights OK, ERROR", function() it("highlights OK, ERROR", function()
local screen = Screen.new(72, 10) local screen = Screen.new(50, 12)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
Ok = { foreground = Screen.colors.Grey3, background = 6291200 }, Ok = { foreground = Screen.colors.Grey3, background = 6291200 },
Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
Heading = { bold=true, foreground=Screen.colors.Magenta }, Heading = { foreground = tonumber('0x6a0dad') },
Heading2 = { foreground = Screen.colors.SlateBlue }, Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey },
Bar = { foreground = 0x6a0dad },
Bullet = { bold=true, foreground=Screen.colors.Brown },
}) })
command("checkhealth foo success1") command("checkhealth foo success1")
command("1tabclose") command("set nowrap laststatus=0")
command("set laststatus=0")
screen:expect{grid=[[ screen:expect{grid=[[
^ | ^ |
{Heading:foo: } | {Bar:}|
{Bar:========================================================================}| {Heading:foo: } |
{Bullet: -} {Error:ERROR}: No healthcheck found for "foo" plugin. | |
| - {Error:ERROR} No healthcheck found for "foo" plugin. |
{Heading:success1: health#success1#check} | |
{Bar:========================================================================}| {Bar:}|
{Heading2:## }{Heading:report 1} | {Heading:success1: health#success1#check} |
{Bullet: -} {Ok:OK}: everything is fine | |
| {Heading:report 1} |
- {Ok:OK} everything is fine |
|
]]} ]]}
end) end)
@ -237,9 +249,10 @@ describe('health.vim', function()
-- luacheck: ignore 613 -- luacheck: ignore 613
helpers.expect([[ helpers.expect([[
==============================================================================
non_existent_healthcheck: non_existent_healthcheck:
========================================================================
- ERROR: No healthcheck found for "non_existent_healthcheck" plugin. - ERROR No healthcheck found for "non_existent_healthcheck" plugin.
]]) ]])
end) end)