From 4382d2ed564b80944345785d780cf1b19fb23ba8 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Tue, 6 Jun 2023 12:42:26 -0300 Subject: feat(health): fold successful healthchecks #22866 Problem: checkhealth can be noisy, but we don't want to omit info. Solution: Fold OK results by default, if 'foldenable' is enabled. Resolves #22796 --- runtime/lua/vim/health.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index ff338b95ea..6e47a22d03 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -2,6 +2,40 @@ local M = {} local s_output = {} +-- Returns the fold text of the current healthcheck section +function M.foldtext() + local foldtext = vim.fn.foldtext() + + if vim.bo.filetype ~= 'checkhealth' then + return foldtext + end + + if vim.b.failedchecks == nil then + vim.b.failedchecks = vim.empty_dict() + end + + if vim.b.failedchecks[foldtext] == nil then + local warning = '- WARNING ' + local warninglen = string.len(warning) + local err = '- ERROR ' + local errlen = string.len(err) + local failedchecks = vim.b.failedchecks + failedchecks[foldtext] = false + + local foldcontent = vim.api.nvim_buf_get_lines(0, vim.v.foldstart - 1, vim.v.foldend, false) + for _, line in ipairs(foldcontent) do + if string.sub(line, 1, warninglen) == warning or string.sub(line, 1, errlen) == err then + failedchecks[foldtext] = true + break + end + end + + vim.b.failedchecks = failedchecks + end + + return vim.b.failedchecks[foldtext] and '+WE' .. foldtext:sub(4) or foldtext +end + -- From a path return a list [{name}, {func}, {type}] representing a healthcheck local function filepath_to_healthcheck(path) path = vim.fs.normalize(path) -- cgit