Skip to content

Commit

Permalink
Merge pull request #38 from lukas-reineke/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke authored Apr 20, 2022
2 parents 458fa95 + 93484d6 commit 2fcb2c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 4 additions & 1 deletion doc/format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Author: Lukas Reineke <lukas@reineke.jp>
Version: 2.3.1
Version: 2.3.2

==============================================================================
CONTENTS *lsp-format*
Expand Down Expand Up @@ -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

Expand Down
23 changes: 13 additions & 10 deletions lua/lsp-format/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]]
Expand Down

0 comments on commit 2fcb2c9

Please sign in to comment.