From f35dffdf244ee70c0d47942167a8fb00b4ec5d56 Mon Sep 17 00:00:00 2001 From: Idris Gadi Date: Thu, 5 Mar 2026 17:07:10 +0530 Subject: [PATCH] feat(extra): add oxfmt formatter --- .../plugins/extras/formatting/oxfmt.lua | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lua/lazyvim/plugins/extras/formatting/oxfmt.lua diff --git a/lua/lazyvim/plugins/extras/formatting/oxfmt.lua b/lua/lazyvim/plugins/extras/formatting/oxfmt.lua new file mode 100644 index 00000000..cfd7783c --- /dev/null +++ b/lua/lazyvim/plugins/extras/formatting/oxfmt.lua @@ -0,0 +1,60 @@ +---@diagnostic disable: inject-field +if lazyvim_docs then + -- Enable the option to require an oxfmt config file. + -- If no oxfmt config file is found, the formatter will not be used. + -- Note: oxfmt is Prettier-compatible but uses its own config files + -- (.oxfmtrc.json or .oxfmtrc.jsonc), not Prettier configs. + vim.g.lazyvim_oxfmt_needs_config = false +end + +-- https://oxc.rs/docs/guide/usage/formatter.html#supported-languages +local supported = { + "css", + "graphql", + "handlebars", + "html", + "javascript", + "javascriptreact", + "json", + "jsonc", + "less", + "markdown", + "markdown.mdx", + "scss", + "typescript", + "typescriptreact", + "vue", + "yaml", +} + +---@param ctx conform.Context +local function has_config(ctx) + return vim.fs.find({ ".oxfmtrc.json", ".oxfmtrc.jsonc" }, { path = ctx.filename, upward = true })[1] ~= nil +end + +return { + { + "mason-org/mason.nvim", + opts = { ensure_installed = { "oxfmt" } }, + }, + + { + "stevearc/conform.nvim", + optional = true, + ---@param opts conform.setupOpts + opts = function(_, opts) + opts.formatters_by_ft = opts.formatters_by_ft or {} + for _, ft in ipairs(supported) do + opts.formatters_by_ft[ft] = opts.formatters_by_ft[ft] or {} + table.insert(opts.formatters_by_ft[ft], "oxfmt") + end + + opts.formatters = opts.formatters or {} + opts.formatters.oxfmt = { + condition = function(_, ctx) + return vim.g.lazyvim_oxfmt_needs_config ~= true or has_config(ctx) + end, + } + end, + }, +}