diff --git a/doc/guard.nvim.txt b/doc/guard.nvim.txt index 15aa0a4..cbbee90 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 August 24 +*guard.nvim.txt* For NVIM v0.8.0 Last change: 2025 October 11 ============================================================================== Table of Contents *guard.nvim-table-of-contents* diff --git a/lua/guard/format.lua b/lua/guard/format.lua index e116620..739bfd2 100644 --- a/lua/guard/format.lua +++ b/lua/guard/format.lua @@ -150,7 +150,7 @@ local function do_fmt(buf) if config.fn then return config.fn(buf, range, acc) else - local result = spawn.transform(util.get_cmd(config, fname, buf), cwd, config, acc) + local result = spawn.transform(util.get_cmd(config, fname), cwd, config, acc) if type(result) == 'table' then -- indicates error errno = result @@ -193,36 +193,36 @@ local function do_fmt(buf) -- wait until substitution is finished coroutine.yield() - impure:each(function(config) - if errno then - return - end - - vim.system(util.get_cmd(config, fname, buf), { - text = true, - cwd = cwd, - env = config.env or {}, - }, function(result) - if result.code ~= 0 and #result.stderr > 0 then - errno = result - ---@diagnostic disable-next-line: inject-field - errno.cmd = config.cmd - coroutine.resume(co) - else - coroutine.resume(co) + if impure and #impure:totable() > 0 then + impure:each(function(config) + if errno then + return end - end) - coroutine.yield() - end) + vim.system(util.get_cmd(config, fname), { + text = true, + cwd = cwd, + env = config.env or {}, + }, function(result) + if result.code ~= 0 and #result.stderr > 0 then + errno = result + ---@diagnostic disable-next-line: inject-field + errno.cmd = config.cmd + coroutine.resume(co) + else + coroutine.resume(co) + end + end) - if errno then - fail(('%s exited with code %d\n%s'):format(errno.cmd, errno.code, errno.stderr)) - return - end + coroutine.yield() + end) - -- refresh buffer - if impure and #impure:totable() > 0 then + if errno then + fail(('%s exited with code %d\n%s'):format(errno.cmd, errno.code, errno.stderr)) + return + end + + -- refresh buffer vim.schedule(function() api.nvim_buf_call(buf, function() local views = save_views(buf)