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

This commit is contained in:
Folke Lemaitre committed 2023-10-13 09:45:35 +02:00
1 parent ea4174d460
commit 4584410e76
1 file changed
+11 -3
+11 -3
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