format RON files

This commit is contained in:
Christian Nieves
2025-02-11 12:53:27 -06:00
parent 53fdcbb4dc
commit 4d94c9cad7

View File

@ -2,39 +2,51 @@ local use_google = require("utils").use_google
vim.g.disable_autoformat = false vim.g.disable_autoformat = false
vim.api.nvim_create_user_command("FormatDisable", function(args) vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then if args.bang then
-- FormatDisable! will disable formatting just for this buffer -- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true vim.b.disable_autoformat = true
else else
vim.g.disable_autoformat = true vim.g.disable_autoformat = true
end end
end, { end, {
desc = "Disable autoformat-on-save", desc = "Disable autoformat-on-save",
bang = true, bang = true,
}) })
vim.api.nvim_create_user_command("FormatEnable", function() vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false vim.b.disable_autoformat = false
vim.g.disable_autoformat = false vim.g.disable_autoformat = false
end, { end, {
desc = "Re-enable autoformat-on-save", desc = "Re-enable autoformat-on-save",
}) })
vim.api.nvim_create_autocmd("BufWritePre", { vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*", pattern = "*",
callback = function(args) callback = function(args)
if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then
return return
end end
require("conform").format({ bufnr = args.buf }) require("conform").format({ bufnr = args.buf })
end, end,
}) })
vim.api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
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_format = "fallback", range = range })
end, { range = true })
return { return {
{ {
"stevearc/conform.nvim", "stevearc/conform.nvim",
event = { "BufWritePre" }, event = { "BufWritePre" },
cmd = { "ConformInfo", "FormatDisable", "FormatEnable" }, cmd = { "ConformInfo", "FormatDisable", "FormatEnable" },
keys = { keys = {
-- stylua: ignore -- stylua: ignore
{ "<leader>fmt", function() require("conform").format({ async = true, lsp_fallback = true }) end, mode = "", desc = "Format buffer", }, { "<leader>fmt", function() require("conform").format({ async = true, lsp_fallback = true }) end, mode = "", desc = "Format buffer", },
{ "<leader>fj", ":%!python -m json.tool" }, { "<leader>fj", ":%!python -m json.tool" },
@ -45,29 +57,35 @@ return {
opts = { opts = {
log_level = vim.log.levels.DEBUG, log_level = vim.log.levels.DEBUG,
formatters_by_ft = { formatters_by_ft = {
rust = { "rustfmt", lsp_format = "fallback" }, rust = { "rustfmt", lsp_format = "fallback" },
-- Conform will run multiple formatters sequentially -- Conform will run multiple formatters sequentially
-- go = { "goimports", "gofmt" }, -- go = { "goimports", "gofmt" },
-- Use a sub-list to run only the first available formatter -- Use a sub-list to run only the first available formatter
-- javascript = { { "prettierd", "prettier" } }, -- javascript = { { "prettierd", "prettier" } },
lua = { "stylua" }, lua = { "stylua" },
-- Conform will run multiple formatters sequentially -- Conform will run multiple formatters sequentially
python = { "isort", "black" }, python = { "isort", "black" },
-- Use a sub-list to run only the first available formatter -- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } }, javascript = { { "prettierd", "prettier" } },
gdscript = { "gdformat" }, gdscript = { "gdformat" },
dashboard = {}, ron = { "ronfmt" },
-- Use the "*" filetype to run formatters on all filetypes. dashboard = {},
-- ["*"] = { "codespell" }, -- Use the "*" filetype to run formatters on all filetypes.
-- Use the "_" filetype to run formatters on filetypes that don't -- ["*"] = { "codespell" },
-- have other formatters configured. -- Use the "_" filetype to run formatters on filetypes that don't
["_"] = { "trim_whitespace" }, -- have other formatters configured.
}, ["_"] = { "trim_whitespace" },
formatters = { },
gdformat = { formatters = {
prepend_args = { "-l", "100" }, ronfmt = {
}, command = "ronfmt",
}, args = { "$FILENAME" },
}, stdin = false,
}, },
gdformat = {
prepend_args = { "-l", "100" },
},
},
},
},
} }