Skip to content

Commit ddbcbcb

Browse files
committed
(feat): update oxfmt and oxlint to detect vite plus
1 parent 4b7fbaa commit ddbcbcb

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

lsp/oxfmt.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ return {
5151
-- Oxfmt resolves configuration by walking upward and using the nearest config file
5252
-- to the file being processed. We therefore compute the root directory by locating
5353
-- the closest `.oxfmtrc.json` / `.oxfmtrc.jsonc` / `oxfmt.config.ts` (or `package.json` fallback) above the buffer.
54-
local root_markers =
55-
util.insert_package_json({ '.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.ts' }, 'oxfmt', fname)
54+
local root_markers = util.insert_package_json(
55+
{ '.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.ts' },
56+
{ 'oxfmt', 'vite%-plus' },
57+
fname
58+
)
5659
on_dir(vim.fs.dirname(vim.fs.find(root_markers, { path = fname, upward = true })[1]))
5760
end,
5861
}

lsp/oxlint.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
--- The default `on_attach` function provides an `:LspOxlintFixAll` command which
1818
--- can be used to fix all fixable diagnostics. See the `eslint` config entry for
1919
--- an example of how to use this to automatically fix all errors on write.
20+
local util = require 'lspconfig.util'
2021

2122
local function oxlint_conf_mentions_typescript(root_dir)
2223
local fn = vim.fs.joinpath(root_dir, '.oxlintrc.json')
@@ -49,7 +50,17 @@ return {
4950
'svelte',
5051
'astro',
5152
},
52-
root_markers = { '.oxlintrc.json', '.oxlintrc.jsonc', 'oxlint.config.ts' },
53+
root_dir = function(bufnr, on_dir)
54+
local fname = vim.api.nvim_buf_get_name(bufnr)
55+
56+
local root_markers = util.insert_package_json(
57+
{ '.oxlintrc.json', '.oxlintrc.jsonc', 'oxlint.config.ts' },
58+
{ 'oxfmt', 'vite%-plus' },
59+
fname
60+
)
61+
on_dir(vim.fs.dirname(vim.fs.find(root_markers, { path = fname, upward = true })[1]))
62+
end,
63+
5364
workspace_required = true,
5465
on_attach = function(client, bufnr)
5566
vim.api.nvim_buf_create_user_command(bufnr, 'LspOxlintFixAll', function()

lua/lspconfig/util.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ end
5555
---
5656
--- @param root_files string[] List of root-marker files to append to.
5757
--- @param new_names string[] Potential root-marker filenames (e.g. `{ 'package.json', 'package.json5' }`) to inspect for the given `field`.
58-
--- @param field string Field to search for in the given `new_names` files.
58+
--- @param field string | string[] Field(s) to search for in the given `new_names` files.
5959
--- @param fname string Full path of the current buffer name to start searching upwards from.
6060
function M.root_markers_with_field(root_files, new_names, field, fname)
6161
local path = vim.fn.fnamemodify(fname, ':h')
6262
local found = vim.fs.find(new_names, { path = path, upward = true, type = 'file' })
63+
local fields = type(field) == 'string' and { field } or field
6364

6465
for _, f in ipairs(found or {}) do
6566
-- Match the given `field`.
6667
local file = assert(io.open(f, 'r'))
6768
for line in file:lines() do
68-
if line:find(field) then
69+
if vim.iter(fields):any(function(s)
70+
return line:find(s)
71+
end) then
6972
root_files[#root_files + 1] = vim.fs.basename(f)
7073
break
7174
end

0 commit comments

Comments
 (0)