Skip to content

Commit

Permalink
ignore format when changedtick not same close #20
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Jul 18, 2023
1 parent 1d2f9c4 commit 5a20e74
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local function ignored(buf, patterns)
end

local function update_buffer(bufnr, new_lines, srow, erow)
if not new_lines or #new_lines == 0 or not api.nvim_buf_is_valid(bufnr) then
if not new_lines or #new_lines == 0 then
return
end

Expand Down Expand Up @@ -81,6 +81,7 @@ local function do_fmt(buf)
local fmt_configs = filetype[vim.bo[buf].filetype].format
local formatter = require('guard.tools.formatter')
local fname = vim.fn.fnameescape(api.nvim_buf_get_name(buf))
local changedtick = api.nvim_buf_get_changedtick(buf)

coroutine.resume(coroutine.create(function()
local new_lines
Expand Down Expand Up @@ -118,6 +119,9 @@ local function do_fmt(buf)
end

vim.schedule(function()
if not api.nvim_buf_is_valid(buf) or api.nvim_buf_get_changedtick(buf) ~= changedtick then
return
end
update_buffer(buf, new_lines, srow, erow)
end)
end))
Expand Down

0 comments on commit 5a20e74

Please sign in to comment.