Skip to content

Commit

Permalink
Version 2.2.1
Browse files Browse the repository at this point in the history
Fix `exclude` command argument when calling with more than one value
  • Loading branch information
lukas-reineke committed Apr 18, 2022
1 parent 73f7889 commit db45b37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 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.2.0
Version: 2.2.1

==============================================================================
CONTENTS *lsp-format*
Expand Down Expand Up @@ -96,6 +96,9 @@ the `order` list. (same logic as |vim.lsp.buf.formatting_seq_sync()|)
==============================================================================
4. CHANGELOG *lsp-format-changelog*

2.2.1
Fix `exclude` command argument when calling with more than one value

2.2.0
Add `exclude` option

Expand Down
80 changes: 42 additions & 38 deletions lua/lsp-format/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,63 @@ M.setup = function(format_options)
vim.api.nvim_err_write(string.format("%s: %d: %s", client_name, err.code, err.message))
return
end
if result == nil then
return
end
if
vim.api.nvim_buf_get_var(ctx.bufnr, "format_changedtick")
== vim.api.nvim_buf_get_var(ctx.bufnr, "changedtick")
and not vim.startswith(vim.api.nvim_get_mode().mode, "i")
result == nil
or 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
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]]
vim.b.format_saving = false
end
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]]
vim.b.format_saving = false
end
M._next()
end
end

M.format = function(format_options_string)
if not vim.b.format_saving and not M.disabled and not M.disabled_filetypes[vim.bo.filetype] then
local bufnr = vim.api.nvim_get_current_buf()
local format_options = M.format_options[vim.bo.filetype] or {}
for _, option in ipairs(vim.split(format_options_string or "", " ")) do
local key, value = unpack(vim.split(option, "="))
if key == "order" then
value = vim.split(value, ",")
end
format_options[key] = value or true
if vim.b.format_saving or M.disabled or M.disabled_filetypes[vim.bo.filetype] then
return
end

local bufnr = vim.api.nvim_get_current_buf()
local format_options = M.format_options[vim.bo.filetype] or {}
for _, option in ipairs(vim.split(format_options_string or "", " ")) do
local key, value = unpack(vim.split(option, "="))
if key == "order" or key == "exclude" then
value = vim.split(value, ",")
end
format_options[key] = value or true
end

local clients = vim.tbl_values(vim.lsp.buf_get_clients())
for i, client in pairs(clients) do
if vim.tbl_contains(format_options.exclude or {}, client.name) then
table.remove(clients, i)
end
local clients = vim.tbl_values(vim.lsp.buf_get_clients())
for i, client in pairs(clients) do
if vim.tbl_contains(format_options.exclude or {}, client.name) then
table.remove(clients, i)
end
end

for _, client_name in pairs(format_options.order or {}) do
for i, client in pairs(clients) do
if client.name == client_name then
table.insert(clients, table.remove(clients, i))
break
end
for _, client_name in pairs(format_options.order or {}) do
for i, client in pairs(clients) do
if client.name == client_name then
table.insert(clients, table.remove(clients, i))
break
end
end
end

table.insert(M.queue, { bufnr = bufnr, clients = clients, format_options = format_options })
table.insert(M.queue, { bufnr = bufnr, clients = clients, format_options = format_options })

M._next()
end
M._next()
end

M._format = function(bufnr, client, format_options)
Expand Down

0 comments on commit db45b37

Please sign in to comment.