jones-nvim-config/lua/config/conform.lua

44 lines
1.2 KiB
Lua
Raw Permalink Normal View History

2024-04-08 14:46:05 +00:00
require("conform").setup({
2024-04-28 19:10:40 +00:00
formatters_by_ft = {
lua = { "stylua" },
javascript = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } },
javascriptreact = { "prettierd", "prettier" },
typescriptreact = { "prettierd", "prettier" },
json = { { "prettierd", "prettier" } },
2024-05-05 12:55:15 +00:00
jsonc = { { "prettierd", "prettier" } },
2024-04-28 19:10:40 +00:00
markdown = { { "marksman", "prettier", "prettierd" } },
},
2024-07-29 18:22:28 +00:00
stop_after_first = {
lua = true,
javascript = true,
typescript = true,
javascriptreact = true,
typescriptreact = true,
json = true,
jsonc = true,
markdown = true,
},
2024-04-08 14:46:05 +00:00
})
local M = {}
M.format = function(args)
2024-04-28 19:10:40 +00:00
local range = nil
if args and args.count ~= -1 then
-- Assuming args.line1 and args.line2 are provided and valid
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_fallback = true, range = range })
2024-04-08 14:46:05 +00:00
end
vim.api.nvim_create_user_command("Format", function(args)
2024-04-28 19:10:40 +00:00
M.format(args)
2024-04-08 14:46:05 +00:00
end, { range = true })
return M