Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lsp/oxfmt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ return {
-- Oxfmt resolves configuration by walking upward and using the nearest config file
-- to the file being processed. We therefore compute the root directory by locating
-- the closest `.oxfmtrc.json` / `.oxfmtrc.jsonc` / `oxfmt.config.ts` (or `package.json` fallback) above the buffer.
local root_markers =
util.insert_package_json({ '.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.ts' }, 'oxfmt', fname)
local root_markers = util.insert_package_json(
{ '.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.ts' },
{ 'oxfmt', 'vite%-plus' },
fname
)
root_markers = util.root_markers_with_field(root_markers, { 'vite.config.ts' }, 'vite%-plus', fname)
on_dir(vim.fs.dirname(vim.fs.find(root_markers, { path = fname, upward = true })[1]))
end,
}
13 changes: 12 additions & 1 deletion lsp/oxlint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
--- The default `on_attach` function provides an `:LspOxlintFixAll` command which
--- can be used to fix all fixable diagnostics. See the `eslint` config entry for
--- an example of how to use this to automatically fix all errors on write.
local util = require 'lspconfig.util'

local function oxlint_conf_mentions_typescript(root_dir)
local fn = vim.fs.joinpath(root_dir, '.oxlintrc.json')
Expand Down Expand Up @@ -49,7 +50,17 @@ return {
'svelte',
'astro',
},
root_markers = { '.oxlintrc.json', '.oxlintrc.jsonc', 'oxlint.config.ts' },
root_dir = function(bufnr, on_dir)
local fname = vim.api.nvim_buf_get_name(bufnr)

local root_markers = util.insert_package_json(
{ '.oxlintrc.json', '.oxlintrc.jsonc', 'oxlint.config.ts' },
{ 'oxlint', 'vite%-plus' },
fname
)
root_markers = util.root_markers_with_field(root_markers, { 'vite.config.ts' }, 'vite%-plus', fname)
on_dir(vim.fs.dirname(vim.fs.find(root_markers, { path = fname, upward = true })[1]))
end,
workspace_required = true,
on_attach = function(client, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, 'LspOxlintFixAll', function()
Expand Down
7 changes: 5 additions & 2 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ end
---
--- @param root_files string[] List of root-marker files to append to.
--- @param new_names string[] Potential root-marker filenames (e.g. `{ 'package.json', 'package.json5' }`) to inspect for the given `field`.
--- @param field string Field to search for in the given `new_names` files.
--- @param field string | string[] Field(s) to search for in the given `new_names` files.
--- @param fname string Full path of the current buffer name to start searching upwards from.
function M.root_markers_with_field(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
local found = vim.fs.find(new_names, { path = path, upward = true, type = 'file' })
local fields = type(field) == 'string' and { field } or field

for _, f in ipairs(found or {}) do
-- Match the given `field`.
local file = assert(io.open(f, 'r'))
for line in file:lines() do
if line:find(field) then
if vim.iter(fields):any(function(s)
return line:find(s)
end) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
Expand Down