From 93484d6fa5766bc20e79e227329753c5c492ab5f Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Wed, 20 Apr 2022 13:34:49 +0900 Subject: [PATCH] Version 2.3.2 Continue with the next client when one client has an error fix #37 --- doc/format.txt | 5 ++++- lua/lsp-format/init.lua | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/doc/format.txt b/doc/format.txt index 33b927e..fd20fc3 100644 --- a/doc/format.txt +++ b/doc/format.txt @@ -2,7 +2,7 @@ Author: Lukas Reineke -Version: 2.3.1 +Version: 2.3.2 ============================================================================== CONTENTS *lsp-format* @@ -121,6 +121,9 @@ sync *lsp-format-sync* ============================================================================== 5. CHANGELOG *lsp-format-changelog* +2.3.2 + Continue with the next client when one client has an error + 2.3.1 Fix clear autogroup only for buffer diff --git a/lua/lsp-format/init.lua b/lua/lsp-format/init.lua index e21d5af..332d6b1 100644 --- a/lua/lsp-format/init.lua +++ b/lua/lsp-format/init.lua @@ -63,9 +63,8 @@ M.format = function(options) if #clients > 0 then table.insert(M.queue, { bufnr = bufnr, clients = clients, format_options = format_options }) + M._next() end - - M._next() end M.disable = function(options) @@ -127,22 +126,26 @@ M._handler = function(err, result, ctx) local client = vim.lsp.get_client_by_id(ctx.client_id) local client_name = client and client.name or string.format("client_id=%d", ctx.client_id) vim.api.nvim_err_write(string.format("%s: %d: %s", client_name, err.code, err.message)) + M._next() + return + end + if result == nil then + M._next() return end - if - result == nil - or vim.api.nvim_buf_get_var(ctx.bufnr, "format_changedtick") ~= vim.api.nvim_buf_get_var( - ctx.bufnr, - "changedtick" - ) + if not vim.api.nvim_buf_is_loaded(ctx.bufnr) then + vim.fn.bufload(ctx.bufnr) + vim.api.nvim_buf_set_var(ctx.bufnr, "format_changedtick", vim.api.nvim_buf_get_var(ctx.bufnr, "changedtick")) + elseif + vim.api.nvim_buf_get_var(ctx.bufnr, "format_changedtick") + ~= vim.api.nvim_buf_get_var(ctx.bufnr, "changedtick") or vim.startswith(vim.api.nvim_get_mode().mode, "i") then + M._next() return end - local view = vim.fn.winsaveview() vim.lsp.util.apply_text_edits(result, ctx.bufnr, "utf-16") - vim.fn.winrestview(view) if ctx.bufnr == vim.api.nvim_get_current_buf() then vim.b.format_saving = true vim.cmd [[update]]