mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 01:38:54 +02:00
feat(conform): use conform.nvim opts.format
options for formatting with conform
This commit is contained in:
parent
3f1bf70b14
commit
6fd66f486e
1 changed files with 23 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
local Util = require("lazyvim.util")
|
||||||
|
|
||||||
|
---@type ConformOpts
|
||||||
|
local format_opts = {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
|
@ -23,7 +28,7 @@ return {
|
||||||
priority = 100,
|
priority = 100,
|
||||||
primary = true,
|
primary = true,
|
||||||
format = function(buf)
|
format = function(buf)
|
||||||
require("conform").format({ bufnr = buf })
|
require("conform").format(Util.merge(format_opts, { bufnr = buf }))
|
||||||
end,
|
end,
|
||||||
sources = function(buf)
|
sources = function(buf)
|
||||||
local ret = require("conform").list_formatters(buf)
|
local ret = require("conform").list_formatters(buf)
|
||||||
|
@ -34,7 +39,12 @@ return {
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
|
---@class ConformOpts
|
||||||
opts = {
|
opts = {
|
||||||
|
-- LazyVim will use these options when formatting with the conform.nvim formatter
|
||||||
|
format = {
|
||||||
|
timeout_ms = 1000,
|
||||||
|
},
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { "stylua" },
|
lua = { "stylua" },
|
||||||
fish = { "fish_indent" },
|
fish = { "fish_indent" },
|
||||||
|
@ -53,6 +63,7 @@ return {
|
||||||
-- },
|
-- },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
---@param opts ConformOpts
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
opts.formatters = opts.formatters or {}
|
opts.formatters = opts.formatters or {}
|
||||||
for name, formatter in pairs(opts.formatters) do
|
for name, formatter in pairs(opts.formatters) do
|
||||||
|
@ -63,6 +74,17 @@ return {
|
||||||
end
|
end
|
||||||
end
|
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)
|
require("conform").setup(opts)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue