Files
dotfiles/nvim/.config/nvim/lua/romanzy/plugins/conform.lua
T
2026-11-01 22:49:27 +01:00

56 lines
1.5 KiB
Lua

vim.pack.add({
{
src = "https://github.com/stevearc/conform.nvim",
name = "conform.nvim",
},
})
local dart = require("romanzy.custom.dart")
local autoformat_enabled = true
require("conform").setup({
formatters_by_ft = {
dart = { "dart_format" },
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
typescriptreact = { "prettier" },
markdown = { "prettier" },
c = { filter = function() return false end },
cpp = { filter = function() return false end },
h = { filter = function() return false end }
},
formatters = {
prettier = {
prepend_args = function(_, ctx)
if vim.bo[ctx.buf].filetype == "markdown" then
return { "--prose-wrap=always", "--print-width=80" }
end
return {}
end,
},
dart_format = {
command = function(_, ctx)
return dart.executable(ctx.filename)
end,
},
},
format_on_save = function()
if not autoformat_enabled then
return
end
return {
lsp_format = "fallback",
timeout_ms = 2000,
}
end,
})
return {
toggle_autoformat = function()
autoformat_enabled = not autoformat_enabled
vim.notify("Autoformatting " .. (autoformat_enabled and "enabled" or "disabled"))
end,
}