diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index cf8181c3f6..ad9edeaf16 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -371,6 +371,24 @@ local function get_summary() return s end +---Emit progress messages +---@param len integer +---@return fun(status: 'success'|'running', idx: integer, fmt: string, ...: any): nil +local function progress_report(len) + local progress = { kind = 'progress', title = 'checkhealth' } + + return function(status, idx, fmt, ...) + progress.status = status + progress.percent = status == 'success' and nil or math.floor(idx / len * 100) + -- percent=0 omits the reporting of percentage, so use 1% instead + -- progress.percent = progress.percent == 0 and 1 or progress.percent + progress.id = vim.api.nvim_echo({ { fmt:format(...) } }, false, progress) + -- extui/ui2 shows all messages at once after the healthchecks are finished. + -- This 1ms wait ensures the messages are shown separately + vim.wait(1) + end +end + --- Runs the specified healthchecks. --- Runs all discovered healthchecks if plugin_names is empty. --- @@ -419,10 +437,13 @@ function M._check(mods, plugin_names) vim.fn.setline(1, 'ERROR: No healthchecks found.') return end - vim.cmd.redraw() - vim.print('Running healthchecks...') + local total_checks = #vim.tbl_keys(healthchecks) + local progress_msg = progress_report(total_checks) + local check_idx = 1 for name, value in vim.spairs(healthchecks) do + progress_msg('running', check_idx, 'checking %s', name) + check_idx = check_idx + 1 local func = value[1] local type = value[2] s_output = {} @@ -475,9 +496,7 @@ function M._check(mods, plugin_names) vim.cmd.redraw() end - -- Clear the 'Running healthchecks...' message. - vim.cmd.redraw() - vim.print('') + progress_msg('success', 0, 'checks done') -- Quit with 'q' inside healthcheck buffers. vim._with({ buf = bufnr }, function() diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 036ede7820..05112461e1 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -228,6 +228,7 @@ describe('vim.health', function() h2 = { foreground = tonumber('0x6a0dad') }, Ok = { foreground = Screen.colors.LightGreen }, Error = { foreground = Screen.colors.Red }, + Done = { foreground = Screen.colors.NvimDarkGreen }, Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey }, }) command('checkhealth foo success1') @@ -245,7 +246,7 @@ describe('vim.health', function() | {h2:report 1} | - ✅ {Ok:OK} everything is fine | - | + {Done:checkhealth}: checks done | ]], } end) @@ -312,6 +313,7 @@ describe(':checkhealth window', function() screen:set_default_attr_ids { h1 = { reverse = true }, h2 = { foreground = tonumber('0x6a0dad') }, + Done = { foreground = Screen.colors.NvimDarkGreen }, [1] = { foreground = Screen.colors.Blue, bold = true }, [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [32] = { foreground = Screen.colors.PaleGreen2 }, @@ -335,7 +337,7 @@ describe(':checkhealth window', function() | {h2:report 2} | ## grid 3 - | + {Done:checkhealth}: checks done | ]], } end) @@ -345,6 +347,7 @@ describe(':checkhealth window', function() screen:set_default_attr_ids { h1 = { reverse = true }, h2 = { foreground = tonumber('0x6a0dad') }, + Done = { foreground = Screen.colors.NvimDarkGreen }, [1] = { foreground = Screen.colors.Blue, bold = true }, [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [32] = { foreground = Screen.colors.PaleGreen2 }, @@ -362,7 +365,7 @@ describe(':checkhealth window', function() %s | {1:~ }|*18 ## grid 3 - | + {Done:checkhealth}: checks done | ## grid 4 ^ | {14: }|*3 @@ -423,7 +426,7 @@ describe(':checkhealth window', function() %s | ~ |*10 ## grid 3 - | + checkhealth: checks done | ## grid 4 ^ | |