diff --git a/CUSTOMIZE.md b/CUSTOMIZE.md index 763c4b8..c4cf5ab 100644 --- a/CUSTOMIZE.md +++ b/CUSTOMIZE.md @@ -25,6 +25,7 @@ A tool is specified as follows: -- special parse -- function: linter only, parses linter output to neovim diagnostic events -- { name: string, opt: autocmd options }: override default events, for formatter autocmds only the first one is used (passed in from `:fmt`) + health -- function: called in health checks } ``` diff --git a/doc/guard.nvim.txt b/doc/guard.nvim.txt index d04f98c..9e7ab62 100644 --- a/doc/guard.nvim.txt +++ b/doc/guard.nvim.txt @@ -1,4 +1,4 @@ -*guard.nvim.txt* For NVIM v0.8.0 Last change: 2025 May 16 +*guard.nvim.txt* For NVIM v0.8.0 Last change: 2025 June 08 ============================================================================== Table of Contents *guard.nvim-table-of-contents* @@ -194,6 +194,7 @@ A tool is specified as follows: -- special parse -- function: linter only, parses linter output to neovim diagnostic events -- { name: string, opt: autocmd options }: override default events, for formatter autocmds only the first one is used (passed in from `:fmt`) + health -- function: called in health checks } < diff --git a/lua/guard/health.lua b/lua/guard/health.lua index d370648..319cf37 100644 --- a/lua/guard/health.lua +++ b/lua/guard/health.lua @@ -5,28 +5,32 @@ local util = require('guard.util') local events = require('guard.events') local M = {} +local function check_cmd(conf, checked) + if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then + if fn.executable(conf.cmd) == 1 then + ok(conf.cmd .. ' found') + else + error(conf.cmd .. ' not found') + end + table.insert(checked, conf.cmd) + end +end + local function executable_check() local checked = {} for _, item in pairs(filetype) do for _, conf in ipairs(item.formatter or {}) do - if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then - if fn.executable(conf.cmd) == 1 then - ok(conf.cmd .. ' found') - else - error(conf.cmd .. ' not found') - end - table.insert(checked, conf.cmd) + if conf.health then + conf.health() + else + check_cmd(conf, checked) end end - for _, conf in ipairs(item.linter or {}) do - if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then - if fn.executable(conf.cmd) == 1 then - ok(conf.cmd .. ' found') - else - error(conf.cmd .. ' not found') - end - table.insert(checked, conf.cmd) + if conf.health then + conf.health() + else + check_cmd(conf, checked) end end end diff --git a/lua/guard/util.lua b/lua/guard/util.lua index 348a35a..dc47dc3 100644 --- a/lua/guard/util.lua +++ b/lua/guard/util.lua @@ -165,6 +165,7 @@ function M.toolcopy(c) env = c.env, timeout = c.timeout, parse = c.parse, + health = c.health, } end