feat(health): make :checkhealth support more split modifiers (#26731)

This commit is contained in:
zeertzjq
2023-12-25 10:21:13 +08:00
committed by GitHub
parent 2ff2785c39
commit 2877672d70
6 changed files with 125 additions and 138 deletions

View File

@@ -266,29 +266,22 @@ M._complete = function()
return vim.tbl_keys(unique)
end
-- Runs the specified healthchecks.
-- Runs all discovered healthchecks if plugin_names is empty.
-- splitmod controls how the healthcheck window opens: "vertical", "horizontal" or "tab"
function M._check(splitmod, plugin_names)
--- Runs the specified healthchecks.
--- Runs all discovered healthchecks if plugin_names is empty.
---
--- @param mods string command modifiers that affect splitting a window.
function M._check(mods, plugin_names)
local healthchecks = plugin_names == '' and get_healthcheck('*') or get_healthcheck(plugin_names)
local emptybuf = vim.fn.bufnr('$') == 1 and vim.fn.getline(1) == '' and 1 == vim.fn.line('$')
local mod = function()
if splitmod == 'vertical' then
return 'vertical sbuffer'
elseif splitmod == 'horizontal' then
return 'horizontal sbuffer'
elseif emptybuf then
-- if this is the default buffer when Nvim starts, open healthcheck directly
return 'buffer'
else
-- if not specified otherwise open healthcheck in a tab
return 'tab sbuffer'
end
end
-- When no command modifiers are used:
-- - If the current buffer is empty, open healthcheck directly.
-- - If not specified otherwise open healthcheck in a tab.
local buf_cmd = #mods > 0 and (mods .. ' sbuffer') or emptybuf and 'buffer' or 'tab sbuffer'
local bufnr = vim.api.nvim_create_buf(true, true)
vim.cmd(mod() .. ' ' .. bufnr)
vim.cmd(buf_cmd .. ' ' .. bufnr)
if vim.fn.bufexists('health://') == 1 then
vim.cmd.bwipe('health://')