Skip to content

Commit 447e35e

Browse files
committed
fix: async LSP bails on no result
There was an inconsistency between the sync and async version of lsp_format: * Sync version invokes all LSP clients even if they don't return a result, as long as they don't return an error. * Async version stops as soon as no result is returned. An example of this happening is when both pylsp and ruff are enabled, and pylsp only being used for refactoring and mypy, with the isort and black plugins disabled. In that case, pylsp gets tried first, returns no result, and conform doesn't even try ruff. It's fine with `format_on_save` (provided the formatting is fast enough), but `format_after_save` is unusable. This commit fixes it by making the async/sync behaviour consistent.
1 parent 619363c commit 447e35e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lua/conform/lsp_format.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ function M.format(options, callback)
125125
end
126126
request(client, method, params, function(err, result, ctx, _)
127127
vim.api.nvim_del_autocmd(auto_id)
128-
if not result then
129-
return callback(err or "No result returned from LSP formatter")
128+
if err then
129+
return callback(err)
130130
elseif not vim.api.nvim_buf_is_valid(bufnr) then
131131
return callback("buffer was deleted")
132132
elseif changedtick ~= require("conform.util").buf_get_changedtick(bufnr) then
@@ -136,6 +136,8 @@ function M.format(options, callback)
136136
vim.api.nvim_buf_get_name(bufnr)
137137
)
138138
)
139+
elseif not result then
140+
do_format(next(clients, idx))
139141
else
140142
local this_did_edit = apply_text_edits(
141143
result,

0 commit comments

Comments
 (0)