From 21fdaa1cc2bf369a06bc5c5ca8d936de79a2b829 Mon Sep 17 00:00:00 2001 From: xiaoshihou Date: Fri, 16 May 2025 18:48:03 +0100 Subject: [PATCH 1/3] chore: also count empty string as nil --- lua/guard/lint.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/guard/lint.lua b/lua/guard/lint.lua index bab9744..05a6025 100644 --- a/lua/guard/lint.lua +++ b/lua/guard/lint.lua @@ -156,7 +156,11 @@ end ---@param nr any? ---@param off number local function normalize(nr, off) - return tonumber(nr or off) - off + if not nr or nr == '' then + return 0 + else + return tonumber(nr) - off + end end local function json_get_offset(mes, attr, off) From dcb2ee0497ec7c791e092ec0e1933f99dd32c73a Mon Sep 17 00:00:00 2001 From: xiaoshihou Date: Sun, 8 Jun 2025 10:02:32 +0100 Subject: [PATCH 2/3] chore: add custom health check capabilities --- CUSTOMIZE.md | 1 + lua/guard/health.lua | 34 +++++++++++++++++++--------------- lua/guard/util.lua | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) 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/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 From 55cb8be8a955c360666d6bf7bd7130606c4ac9e7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 8 Jun 2025 09:03:09 +0000 Subject: [PATCH 3/3] chore(doc): auto generate docs --- doc/guard.nvim.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 } <