diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index d5903cd8..7060c7a5 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -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