fix(conform): make lsp_fallback option user configurable

This commit is contained in:
Iordanis Petkakis 2024-02-27 12:36:22 +02:00
parent 78e6405f90
commit a966881ae7
2 changed files with 8 additions and 2 deletions

View file

@ -84,6 +84,7 @@ return {
timeout_ms = 3000, timeout_ms = 3000,
async = false, -- not recommended to change async = false, -- not recommended to change
quiet = false, -- not recommended to change quiet = false, -- not recommended to change
lsp_fallback = true, -- not recommended to change
}, },
---@type table<string, conform.FormatterUnit[]> ---@type table<string, conform.FormatterUnit[]>
formatters_by_ft = { formatters_by_ft = {

View file

@ -109,13 +109,18 @@ end
---@param opts? lsp.Client.format ---@param opts? lsp.Client.format
function M.format(opts) function M.format(opts)
opts = 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 {},
require("lazyvim.util").opts("conform.nvim").format or {}
)
local ok, conform = pcall(require, "conform") local ok, conform = pcall(require, "conform")
-- use conform for formatting with LSP when available, -- use conform for formatting with LSP when available,
-- since it has better format diffing -- since it has better format diffing
if ok then if ok then
opts.formatters = {} opts.formatters = {}
opts.lsp_fallback = true
conform.format(opts) conform.format(opts)
else else
vim.lsp.buf.format(opts) vim.lsp.buf.format(opts)