aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Teoi <ateoi@users.noreply.github.com>2023-06-06 12:42:26 -0300
committerGitHub <noreply@github.com>2023-06-06 08:42:26 -0700
commit4382d2ed564b80944345785d780cf1b19fb23ba8 (patch)
tree09e78758b63fa808b86fc12c4ad8f89bde9dca74
parent9d9af4fe2775a2f74cfc8d7963f0cc768ed08bfa (diff)
downloadrneovim-4382d2ed564b80944345785d780cf1b19fb23ba8.tar.gz
rneovim-4382d2ed564b80944345785d780cf1b19fb23ba8.tar.bz2
rneovim-4382d2ed564b80944345785d780cf1b19fb23ba8.zip
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
-rw-r--r--runtime/doc/news.txt3
-rw-r--r--runtime/ftplugin/checkhealth.vim3
-rw-r--r--runtime/lua/vim/health.lua34
-rw-r--r--test/functional/plugin/health_spec.lua18
4 files changed, 57 insertions, 1 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 537a737dc8..af5263bcf5 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -106,6 +106,9 @@ The following changes to existing APIs or features add new behavior.
• `:source` without arguments treats a buffer with its 'filetype' set to "lua"
as Lua code regardless of its extension.
+• |:checkhealth| buffer now implements |folding|. The initial folding status is
+ defined by the 'foldenable' option.
+
==============================================================================
REMOVED FEATURES *news-removed*
diff --git a/runtime/ftplugin/checkhealth.vim b/runtime/ftplugin/checkhealth.vim
index 62a1970b4a..4b530e6f7c 100644
--- a/runtime/ftplugin/checkhealth.vim
+++ b/runtime/ftplugin/checkhealth.vim
@@ -9,6 +9,9 @@ endif
runtime! ftplugin/help.vim
setlocal wrap breakindent linebreak
+setlocal foldexpr=getline(v:lnum-1)=~'^=\\{78}$'?'>1':(getline(v:lnum)=~'^=\\{78}'?0:'=')
+setlocal foldmethod=expr
+setlocal foldtext=v:lua.require('vim.health').foldtext()
let &l:iskeyword='!-~,^*,^|,^",192-255'
if exists("b:undo_ftplugin")
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)
diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua
index 488a213a9e..50b1d03f36 100644
--- a/test/functional/plugin/health_spec.lua
+++ b/test/functional/plugin/health_spec.lua
@@ -136,7 +136,7 @@ describe('health.vim', function()
Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey },
})
command("checkhealth foo success1")
- command("set nowrap laststatus=0")
+ command("set nofoldenable nowrap laststatus=0")
screen:expect{grid=[[
^ |
{Bar:──────────────────────────────────────────────────}|
@@ -153,6 +153,22 @@ describe('health.vim', function()
]]}
end)
+ it("fold healthchecks", function()
+ local screen = Screen.new(50, 7)
+ screen:attach()
+ command("checkhealth foo success1")
+ command("set nowrap laststatus=0")
+ screen:expect{grid=[[
+ ^ |
+ ──────────────────────────────────────────────────|
+ +WE 4 lines: foo: ·······························|
+ ──────────────────────────────────────────────────|
+ +-- 8 lines: test_plug.success1: require("test_pl|
+ ~ |
+ |
+ ]]}
+ end)
+
it("gracefully handles invalid healthcheck", function()
command("checkhealth non_existent_healthcheck")
-- luacheck: ignore 613