aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/lsp_format.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-09-29 12:04:30 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-09-29 12:23:26 -0700
commit0c52ee248245f40610a4957b6bc9515ce1fd9ab6 (patch)
tree451e753d11427e91aaf995609eda6653ce9ef10a /lua/conform/lsp_format.lua
parentc5280d586e50ad6193b42df27e494b74a9efc5b7 (diff)
fix: format_after_save blocks on exit for lsp formatting
Diffstat (limited to 'lua/conform/lsp_format.lua')
-rw-r--r--lua/conform/lsp_format.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/lua/conform/lsp_format.lua b/lua/conform/lsp_format.lua
index 0315314..17d835f 100644
--- a/lua/conform/lsp_format.lua
+++ b/lua/conform/lsp_format.lua
@@ -1,4 +1,5 @@
---This module replaces the default vim.lsp.buf.format() so that we can inject our own logic
+local log = require("conform.log")
local util = require("vim.lsp.util")
local M = {}
@@ -75,12 +76,22 @@ function M.format(options, callback)
return callback()
end
local params = set_range(client, util.make_formatting_params(options.formatting_options))
+ local auto_id = vim.api.nvim_create_autocmd("LspDetach", {
+ buffer = bufnr,
+ callback = function(args)
+ if args.data.client_id == client.id then
+ log.warn("LSP %s detached during format request", client.name)
+ callback("LSP detached")
+ end
+ end,
+ })
client.request(method, params, function(err, result, ctx, _)
+ vim.api.nvim_del_autocmd(auto_id)
if not result then
return callback(err or "No result returned from LSP formatter")
elseif not vim.api.nvim_buf_is_valid(bufnr) then
return callback("buffer was deleted")
- elseif vim.b[bufnr].changedtick ~= changedtick then
+ elseif changedtick ~= util.buf_get_changedtick(bufnr) then
return
callback(
string.format(