diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-29 11:35:00 -0700 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-29 11:37:04 -0700 |
commit | 388d6e2440bccded26d5e67ce6a7039c1953ae70 (patch) | |
tree | 943e96e22065ec32db06b57024c58fb2f6ba6543 /lua/conform/runner.lua | |
parent | 45edf9462d06db0809d4a4a7afc6b7896b63fa35 (diff) |
fix: format_after_save autocmd blocks nvim exit until complete
This fixes one the main issue with a BufWritePost format autocmd:
that if the user does `:wq` vim will exit before the formatting changes
are applied. Now we will block in VimLeavePre until the formatter
completes (or a timeout is reached).
Diffstat (limited to 'lua/conform/runner.lua')
-rw-r--r-- | lua/conform/runner.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index e162b38..33429e9 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -457,8 +457,14 @@ M.format_async = function(bufnr, formatters, range, callback) local function run_next_formatter() local formatter = formatters[idx] if not formatter then + local new_changedtick = vim.b[bufnr].changedtick + -- changedtick gets set to -1 when vim is exiting. We have an autocmd that should store it in + -- last_changedtick before it is set to -1. + if new_changedtick == -1 then + new_changedtick = vim.b[bufnr].last_changedtick or -1 + end -- discard formatting if buffer has changed - if not vim.api.nvim_buf_is_valid(bufnr) or vim.b[bufnr].changedtick ~= changedtick then + if not vim.api.nvim_buf_is_valid(bufnr) or changedtick ~= new_changedtick then callback({ code = M.ERROR_CODE.CONCURRENT_MODIFICATION, message = string.format( |