mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat(extra): add oxfmt formatter
This commit is contained in:
parent
31caef21fd
commit
f35dffdf24
1 changed files with 60 additions and 0 deletions
60
lua/lazyvim/plugins/extras/formatting/oxfmt.lua
Normal file
60
lua/lazyvim/plugins/extras/formatting/oxfmt.lua
Normal file
|
|
@ -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,
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue