health.vim: Show results incrementally.

Also:

- improve precision of "No healthcheck found"
- fix SUGGESTIONS syntax group definition
- fix indentation of SUGGESTIONS
This commit is contained in:
Justin M. Keyes
2016-09-04 22:57:19 -04:00
parent 31257b450b
commit 3c24704ac8
2 changed files with 38 additions and 31 deletions

View File

@@ -11,47 +11,50 @@ function! s:enhance_syntax() abort
syntax keyword healthSuccess SUCCESS
highlight link healthSuccess Function
syntax keyword healthSuggestion SUGGESTION
syntax keyword healthSuggestion SUGGESTIONS
highlight link healthSuggestion String
endfunction
" Runs the specified healthchecks.
" Runs all discovered healthchecks if a:plugin_names is empty.
function! health#check(plugin_names) abort
let report = ''
let healthchecks = empty(a:plugin_names)
\ ? s:discover_health_checks()
\ : s:to_fn_names(a:plugin_names)
if empty(healthchecks)
let report = "ERROR: No healthchecks found."
call setline(1, 'ERROR: No healthchecks found.')
else
tabnew
setlocal filetype=markdown bufhidden=wipe
call s:enhance_syntax()
redraw|echo 'Running healthchecks...'
for c in healthchecks
let report .= printf("\n%s\n%s", c, repeat('=',80))
let output = ''
call append('$', split(printf("\n%s\n%s", c, repeat('=',80)), "\n"))
try
let report .= execute('call '.c.'()')
catch /^Vim\%((\a\+)\)\=:E117/
let report .= execute(
\ 'call health#report_error(''No healthcheck found for "'
\ .s:to_plugin_name(c)
\ .'" plugin.'')')
let output = "\n\n".execute('call '.c.'()')
catch
let report .= execute(
\ 'call health#report_error(''Failed to run healthcheck for "'
\ .s:to_plugin_name(c)
\ .'" plugin. Exception:''."\n".v:exception)')
if v:exception =~# '^Vim\%((\a\+)\)\=:E117.*\V'.c
let output = execute(
\ 'call health#report_error(''No healthcheck found for "'
\ .s:to_plugin_name(c)
\ .'" plugin.'')')
else
let output = execute(
\ 'call health#report_error(''Failed to run healthcheck for "'
\ .s:to_plugin_name(c)
\ .'" plugin. Exception:''."\n".v:exception)')
endif
endtry
let report .= "\n"
call append('$', split(output, "\n") + [''])
redraw
endfor
endif
tabnew
setlocal bufhidden=wipe
set filetype=markdown
call s:enhance_syntax()
call setline(1, split(report, "\n"))
setlocal nomodified
redraw|echo ''
endfunction
" Starts a new report.
@@ -86,10 +89,10 @@ function! s:format_report_message(status, msg, ...) abort " {{{
" Report each suggestion
if len(suggestions) > 0
let output .= "\n - SUGGESTIONS:"
let output .= "\n - SUGGESTIONS:"
endif
for suggestion in suggestions
let output .= "\n - " . s:indent_after_line1(suggestion, 10)
let output .= "\n - " . s:indent_after_line1(suggestion, 10)
endfor
return output

View File

@@ -34,9 +34,9 @@ describe('health.vim', function()
## Baz
- WARNING: Zim
- SUGGESTIONS:
- suggestion 1
- suggestion 2]]),
- SUGGESTIONS:
- suggestion 1
- suggestion 2]]),
result)
end)
@@ -45,9 +45,9 @@ describe('health.vim', function()
it("concatenates multiple reports", function()
helpers.execute("CheckHealth success1 success2")
helpers.expect([[
health#success1#check
================================================================================
## report 1
- SUCCESS: everything is fine
@@ -56,26 +56,30 @@ describe('health.vim', function()
health#success2#check
================================================================================
## another 1
- SUCCESS: ok]])
- SUCCESS: ok
]])
end)
it("gracefully handles broken healthcheck", function()
helpers.execute("CheckHealth broken")
helpers.expect([[
health#broken#check
================================================================================
- ERROR: Failed to run healthcheck for "broken" plugin. Exception:
caused an error]])
caused an error
]])
end)
it("gracefully handles invalid healthcheck", function()
helpers.execute("CheckHealth non_existent_healthcheck")
helpers.expect([[
health#non_existent_healthcheck#check
================================================================================
- ERROR: No healthcheck found for "non_existent_healthcheck" plugin.]])
- ERROR: No healthcheck found for "non_existent_healthcheck" plugin.
]])
end)
end)
end)