Skip to content

Commit

Permalink
check changedtick
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Jul 18, 2023
1 parent 27b258a commit b089a5a
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 @@ -84,7 +84,7 @@ local function do_fmt(buf)

coroutine.resume(coroutine.create(function()
local new_lines
-- local changedtick = api.nvim_buf_get_changedtick(buf)
local changedtick = api.nvim_buf_get_changedtick(buf)
for i, config in ipairs(fmt_configs) do
if type(config) == 'string' and formatter[config] then
config = formatter[config]
Expand Down Expand Up @@ -115,10 +115,14 @@ local function do_fmt(buf)
end
new_lines = table.concat(get_prev_lines(buf, srow, erow), '')
end
changedtick = vim.b[buf].changedtick
end
end

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

0 comments on commit b089a5a

Please sign in to comment.