1
0

Fix conform format on autosave

This commit is contained in:
Nigel Barink 2024-10-05 23:51:35 +02:00
parent 52c7c5099d
commit bd1e208133
Signed by: Nigel
GPG Key ID: 6893A31C2D84A9D2

View File

@ -1,36 +1,31 @@
return { return {
"stevearc/conform.nvim", "stevearc/conform.nvim",
event = { "BufWritePre"}, config = function()
cmd = { "ConformInfo"}, require("conform").setup(
opts = { {
formatters_by_ft = { formatters_by_ft = {
php = { "pint"}, php = { "pint" },
lua = { "stylua"}, lua = { "stylua" },
javascript = { "prettierd", "prettier", stop_after_first = true }, javascript = { "prettierd", "prettier", stop_after_first = true },
typescript = { "prettierd", "prettier", stop_after_first = true }, typescript = { "prettierd", "prettier", stop_after_first = true },
java = { "clang-format", stop_after_first = true }, java = { "clang-format", },
}, cpp = { "clang-format", },
format_on_save = { timeout_ms = 500 }, },
default_format_ops = { format_on_save = {
lsp_format = "fallback" lsp_fallback = true,
}, },
}, })
config = function () -- Command to run async formatting
require("conform").setup() vim.api.nvim_create_user_command("Format", function(args)
-- Command to run async formatting local range = nil
vim.api.nvim_create_user_command("Format", function(args) if args.count ~= -1 then
local range = nil local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
if args.count ~= -1 then range = {
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] start = { args.line1, 0 },
range = { ["end"] = { args.line2, end_line:len() },
start = { args.line1, 0 }, }
["end"] = { args.line2, end_line:len() }, end
} require("conform").format({ async = true, lsp_format = "fallback", range = range })
end end, { range = true })
require("conform").format({ async = true, lsp_format = "fallback", range = range })
end, { range = true })
end end
} }