From 5161ff88fa6b7464fc9554b5d456bd08e3644ace Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Sat, 7 Nov 2020 14:31:55 -0800 Subject: lsp: fix formatting_sync with multiple clients (#13233) buf_request_sync returns a table indexed by the client id, so when starting a second client on a separate buffer, result[1] will be nil. Closes #13232. Co-authored-by: francisco souza --- runtime/lua/vim/lsp/buf.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index c015884f5b..0b8e08f36c 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -138,8 +138,9 @@ end function M.formatting_sync(options, timeout_ms) local params = util.make_formatting_params(options) local result = vim.lsp.buf_request_sync(0, "textDocument/formatting", params, timeout_ms) - if not result then return end - result = result[1].result + if not result or vim.tbl_isempty(result) then return end + local _, formatting_result = next(result) + result = formatting_result.result if not result then return end vim.lsp.util.apply_text_edits(result) end -- cgit