Skip to content

Commit 71f580c

Browse files
chore: add custom health check capability (#213)
* chore: also count empty string as nil * chore: add custom health check capabilities * chore(doc): auto generate docs --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 37e2a5b commit 71f580c

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

CUSTOMIZE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ A tool is specified as follows:
2525
-- special
2626
parse -- function: linter only, parses linter output to neovim diagnostic
2727
events -- { name: string, opt: autocmd options }: override default events, for formatter autocmds only the first one is used (passed in from `:fmt`)
28+
health -- function: called in health checks
2829
}
2930
```
3031

doc/guard.nvim.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*guard.nvim.txt* For NVIM v0.8.0 Last change: 2025 May 16
1+
*guard.nvim.txt* For NVIM v0.8.0 Last change: 2025 June 08
22

33
==============================================================================
44
Table of Contents *guard.nvim-table-of-contents*
@@ -194,6 +194,7 @@ A tool is specified as follows:
194194
-- special
195195
parse -- function: linter only, parses linter output to neovim diagnostic
196196
events -- { name: string, opt: autocmd options }: override default events, for formatter autocmds only the first one is used (passed in from `:fmt`)
197+
health -- function: called in health checks
197198
}
198199
<
199200

lua/guard/health.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ local util = require('guard.util')
55
local events = require('guard.events')
66
local M = {}
77

8+
local function check_cmd(conf, checked)
9+
if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then
10+
if fn.executable(conf.cmd) == 1 then
11+
ok(conf.cmd .. ' found')
12+
else
13+
error(conf.cmd .. ' not found')
14+
end
15+
table.insert(checked, conf.cmd)
16+
end
17+
end
18+
819
local function executable_check()
920
local checked = {}
1021
for _, item in pairs(filetype) do
1122
for _, conf in ipairs(item.formatter or {}) do
12-
if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then
13-
if fn.executable(conf.cmd) == 1 then
14-
ok(conf.cmd .. ' found')
15-
else
16-
error(conf.cmd .. ' not found')
17-
end
18-
table.insert(checked, conf.cmd)
23+
if conf.health then
24+
conf.health()
25+
else
26+
check_cmd(conf, checked)
1927
end
2028
end
21-
2229
for _, conf in ipairs(item.linter or {}) do
23-
if conf.cmd and not vim.tbl_contains(checked, conf.cmd) then
24-
if fn.executable(conf.cmd) == 1 then
25-
ok(conf.cmd .. ' found')
26-
else
27-
error(conf.cmd .. ' not found')
28-
end
29-
table.insert(checked, conf.cmd)
30+
if conf.health then
31+
conf.health()
32+
else
33+
check_cmd(conf, checked)
3034
end
3135
end
3236
end

lua/guard/util.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function M.toolcopy(c)
165165
env = c.env,
166166
timeout = c.timeout,
167167
parse = c.parse,
168+
health = c.health,
168169
}
169170
end
170171

0 commit comments

Comments
 (0)