Skip to content

Commit

Permalink
fix: stable ordering when specifying multiple formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 29, 2023
1 parent 9bb703e commit 69c4495
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lua/conform/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ M.setup = function(opts)
return
end
local client = vim.lsp.get_client_by_id(ctx.client_id)
assert(client)
local restore = require("conform.util").save_win_positions(ctx.bufnr)
vim.lsp.util.apply_text_edits(result, ctx.bufnr, client.offset_encoding)
restore()
Expand All @@ -96,6 +97,7 @@ end
---@param bufnr integer
---@return boolean
local function supports_lsp_format(bufnr)
---@diagnostic disable-next-line: deprecated
for _, client in ipairs(vim.lsp.get_active_clients({ bufnr = bufnr })) do
if client.supports_method("textDocument/formatting", { bufnr = bufnr }) then
return true
Expand All @@ -112,6 +114,7 @@ local function list_formatters_for_buffer(bufnr)
bufnr = vim.api.nvim_get_current_buf()
end
local formatters = {}
local seen = {}
local run_options = {
run_all_formatters = false,
format_on_save = true,
Expand All @@ -130,17 +133,18 @@ local function list_formatters_for_buffer(bufnr)
ft_formatters = ft_formatters.formatters
end
for _, formatter in ipairs(ft_formatters) do
formatters[formatter] = true
if not seen[formatter] then
table.insert(formatters, formatter)
seen[formatter] = true
end
end
end
end

---@type conform.FormatterInfo[]
local all_info = {}
for formatter in pairs(formatters) do
local info = M.get_formatter_info(formatter)
table.insert(all_info, info)
end
local all_info = vim.tbl_map(function(f)
return M.get_formatter_info(f, bufnr)
end, formatters)

return all_info, run_options
end
Expand Down

0 comments on commit 69c4495

Please sign in to comment.