mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-24 05:21:07 +00:00
Merge 870d5a54df into 459a4c3b10
This commit is contained in:
commit
5f2e3cd739
1 changed files with 39 additions and 10 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
|
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
|
||||||
|
vim.g.lazyvim_oxfmt_needs_config = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
local supported = {
|
local supported = {
|
||||||
"javascript",
|
"javascript",
|
||||||
"javascriptreact",
|
"javascriptreact",
|
||||||
|
|
@ -10,17 +18,32 @@ local supported = {
|
||||||
"astro",
|
"astro",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local oxfmt_markers = {
|
||||||
|
".oxfmtrc.json",
|
||||||
|
".oxfmtrc.jsonc",
|
||||||
|
"oxfmt.config.ts",
|
||||||
|
}
|
||||||
|
|
||||||
|
local oxlint_markers = {
|
||||||
|
".oxlintrc.json",
|
||||||
|
".oxlintrc.jsonc",
|
||||||
|
"oxlint.config.ts",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Checks if a oxfmt config file exists for the given context
|
||||||
|
---@module 'conform'
|
||||||
|
---@param ctx conform.Context
|
||||||
|
---@return boolean
|
||||||
|
function M.has_oxfmt_config(ctx)
|
||||||
|
return vim.fs.root(ctx.buf, oxfmt_markers) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
M.has_oxfmt_config = LazyVim.memoize(M.has_oxfmt_config)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
recommended = function()
|
recommended = function()
|
||||||
return LazyVim.extras.wants({
|
return LazyVim.extras.wants({
|
||||||
root = {
|
root = vim.list_extend(vim.list_extend({}, oxlint_markers), oxfmt_markers),
|
||||||
".oxlintrc.json",
|
|
||||||
".oxlintrc.jsonc",
|
|
||||||
"oxlint.config.ts",
|
|
||||||
".oxfmtrc.json",
|
|
||||||
".oxfmtrc.jsonc",
|
|
||||||
"oxfmt.config.ts",
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
@ -33,8 +56,7 @@ return {
|
||||||
root_dir = function(bufnr, on_dir)
|
root_dir = function(bufnr, on_dir)
|
||||||
-- prefer the top-level oxlint config if it exists (monorepo support)
|
-- prefer the top-level oxlint config if it exists (monorepo support)
|
||||||
local git = vim.fs.root(bufnr, ".git")
|
local git = vim.fs.root(bufnr, ".git")
|
||||||
local markers = { ".oxlintrc.json", ".oxlintrc.jsonc", "oxlint.config.ts" }
|
local root = git and vim.fs.root(git, oxlint_markers) or vim.fs.root(bufnr, oxlint_markers)
|
||||||
local root = git and vim.fs.root(git, markers) or vim.fs.root(bufnr, markers)
|
|
||||||
if root then
|
if root then
|
||||||
on_dir(root)
|
on_dir(root)
|
||||||
end
|
end
|
||||||
|
|
@ -63,6 +85,13 @@ return {
|
||||||
opts.formatters_by_ft[ft] = opts.formatters_by_ft[ft] or {}
|
opts.formatters_by_ft[ft] = opts.formatters_by_ft[ft] or {}
|
||||||
table.insert(opts.formatters_by_ft[ft], "oxfmt")
|
table.insert(opts.formatters_by_ft[ft], "oxfmt")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.formatters = opts.formatters or {}
|
||||||
|
opts.formatters.oxfmt = {
|
||||||
|
condition = function(_, ctx)
|
||||||
|
return vim.g.lazyvim_oxfmt_needs_config ~= true or M.has_oxfmt_config(ctx)
|
||||||
|
end,
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue