mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-27 11:19:02 +02:00
fix(conform): use formatters
for both custom and overriding formatters
This commit is contained in:
parent
0e5ff5c0ab
commit
6bb0d1b66f
1 changed files with 6 additions and 11 deletions
|
@ -1,10 +1,3 @@
|
||||||
-- When `conform.nvim` is enabled, it will automatically be used as the
|
|
||||||
-- formatter for all files that it supports.
|
|
||||||
-- When no conform formatter is available for a filetype, LSP format
|
|
||||||
-- will be used instead.
|
|
||||||
--
|
|
||||||
-- LazyVim adds a custom `formatter_opts` option to allow overriding the
|
|
||||||
-- default options for each formatter.
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
|
@ -25,9 +18,10 @@ return {
|
||||||
fish = { "fish_indent" },
|
fish = { "fish_indent" },
|
||||||
sh = { "shfmt" },
|
sh = { "shfmt" },
|
||||||
},
|
},
|
||||||
-- LazyVim extension to easily override formatter options
|
-- LazyVim will merge the options you set here with builtin formatters.
|
||||||
|
-- You can also define any custom formatters here.
|
||||||
---@type table<string,table>
|
---@type table<string,table>
|
||||||
formatter_opts = {
|
formatters = {
|
||||||
-- -- Example of using dprint only when a dprint.json file is present
|
-- -- Example of using dprint only when a dprint.json file is present
|
||||||
-- dprint = {
|
-- dprint = {
|
||||||
-- condition = function(ctx)
|
-- condition = function(ctx)
|
||||||
|
@ -38,8 +32,9 @@ return {
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
opts.formatters = opts.formatters or {}
|
opts.formatters = opts.formatters or {}
|
||||||
for f, o in pairs(opts.formatter_opts or {}) do
|
for f, o in pairs(opts.formatters) do
|
||||||
opts.formatters[f] = vim.tbl_deep_extend("force", require("conform.formatters." .. f), o)
|
local ok, formatter = pcall(require, "conform.formatters." .. f)
|
||||||
|
opts.formatters[f] = vim.tbl_deep_extend("force", {}, ok and formatter or {}, o)
|
||||||
end
|
end
|
||||||
require("conform").setup(opts)
|
require("conform").setup(opts)
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue