mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-23 09:18:51 +02:00
feat(conform): show error when user overwrites conform config function
This commit is contained in:
parent
3eb91c64b5
commit
b6e68fa2bf
1 changed files with 71 additions and 55 deletions
|
@ -1,8 +1,41 @@
|
||||||
local Util = require("lazyvim.util")
|
local Util = require("lazyvim.util")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
---@type ConformOpts
|
---@type ConformOpts
|
||||||
local format_opts = {}
|
local format_opts = {}
|
||||||
|
|
||||||
|
---@param opts ConformOpts
|
||||||
|
function M.setup(plugin, opts)
|
||||||
|
local util = require("conform.util")
|
||||||
|
opts.formatters = opts.formatters or {}
|
||||||
|
for name, formatter in pairs(opts.formatters) do
|
||||||
|
if type(formatter) == "table" then
|
||||||
|
local ok, defaults = pcall(require, "conform.formatters." .. name)
|
||||||
|
if ok and type(defaults) == "table" then
|
||||||
|
opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter)
|
||||||
|
end
|
||||||
|
if opts.formatters[name].extra_args then
|
||||||
|
opts.formatters[name].args =
|
||||||
|
util.extend_args(opts.formatters[name].args or {}, opts.formatters[name].extra_args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, key in ipairs({ "format_on_save", "format_after_save" }) do
|
||||||
|
if opts[key] then
|
||||||
|
Util.warn(
|
||||||
|
("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format(
|
||||||
|
key
|
||||||
|
)
|
||||||
|
)
|
||||||
|
opts[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
format_opts = opts.format
|
||||||
|
require("conform").setup(opts)
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
|
@ -39,8 +72,17 @@ return {
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
|
opts = function()
|
||||||
|
local plugin = require("lazy.core.config").plugins["conform.nvim"]
|
||||||
|
if plugin.config ~= M.setup then
|
||||||
|
Util.error({
|
||||||
|
"Don't set `plugin.config` for `conform.nvim`.\n",
|
||||||
|
"This will break **LazyVim** formatting.\n",
|
||||||
|
"Please refer to the docs at https://www.lazyvim.org/plugins/formatting",
|
||||||
|
}, { title = "LazyVim" })
|
||||||
|
end
|
||||||
---@class ConformOpts
|
---@class ConformOpts
|
||||||
opts = {
|
return {
|
||||||
-- LazyVim will use these options when formatting with the conform.nvim formatter
|
-- LazyVim will use these options when formatting with the conform.nvim formatter
|
||||||
format = {
|
format = {
|
||||||
timeout_ms = 1000,
|
timeout_ms = 1000,
|
||||||
|
@ -55,46 +97,20 @@ return {
|
||||||
---@type table<string,table>
|
---@type table<string,table>
|
||||||
formatters = {
|
formatters = {
|
||||||
injected = { options = { ignore_errors = true } },
|
injected = { options = { ignore_errors = true } },
|
||||||
-- -- 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)
|
||||||
-- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
|
-- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
|
||||||
-- end,
|
-- end,
|
||||||
-- },
|
-- },
|
||||||
shfmt = {
|
--
|
||||||
extra_args = { "-i", "2", "-ci" },
|
-- # Example of using shfmt with extra args
|
||||||
},
|
-- shfmt = {
|
||||||
},
|
-- extra_args = { "-i", "2", "-ci" },
|
||||||
},
|
-- },
|
||||||
---@param opts ConformOpts
|
},
|
||||||
config = function(_, opts)
|
}
|
||||||
local util = require("conform.util")
|
end,
|
||||||
opts.formatters = opts.formatters or {}
|
config = M.setup,
|
||||||
for name, formatter in pairs(opts.formatters) do
|
|
||||||
if type(formatter) == "table" then
|
|
||||||
local ok, defaults = pcall(require, "conform.formatters." .. name)
|
|
||||||
if ok and type(defaults) == "table" then
|
|
||||||
opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter)
|
|
||||||
end
|
|
||||||
if opts.formatters[name].extra_args then
|
|
||||||
opts.formatters[name].args =
|
|
||||||
util.extend_args(opts.formatters[name].args or {}, opts.formatters[name].extra_args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, key in ipairs({ "format_on_save", "format_after_save" }) do
|
|
||||||
if opts[key] then
|
|
||||||
Util.warn(
|
|
||||||
("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format(
|
|
||||||
key
|
|
||||||
)
|
|
||||||
)
|
|
||||||
opts[key] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
format_opts = opts.format
|
|
||||||
require("conform").setup(opts)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue