feat(format): use conform as lsp formatter since it has better format diffs

This commit is contained in:
Folke Lemaitre 2023-10-13 09:45:35 +02:00
parent ea4174d460
commit 4584410e76
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -104,9 +104,17 @@ end
---@param opts? {filter?: lsp.Client.filter, bufnr?: number}
function M.format(opts)
vim.lsp.buf.format(
vim.tbl_deep_extend("force", opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {})
)
opts = vim.tbl_deep_extend("force", {}, opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {})
local ok, conform = pcall(require, "conform")
-- use conform for formatting with LSP when available,
-- since it has better format diffing
if ok then
opts.formatters = {}
opts.lsp_fallback = true
conform.format(opts)
else
vim.lsp.buf.format(opts)
end
end
return M