tries to fix

This commit is contained in:
Dennis 2026-02-06 11:41:55 +01:00
parent ed0201766f
commit 4997c38582

View file

@ -50,12 +50,13 @@
"eslint.config.ts" "eslint.config.ts"
"eslint.config.mts" "eslint.config.mts"
"eslint.config.cts" "eslint.config.cts"
"package.json"
]; ];
settings = { settings = {
validate = "on"; validate = "on";
useESLintClass = false; useESLintClass = false;
experimental = { experimental = {
useFlatConfig = false; useFlatConfig = true;
}; };
codeActionOnSave = { codeActionOnSave = {
enable = false; enable = false;
@ -71,7 +72,7 @@
}; };
nodePath = ""; nodePath = "";
workingDirectory = { workingDirectory = {
mode = "auto"; mode = "location";
}; };
codeAction = { codeAction = {
disableRuleComment = { disableRuleComment = {
@ -113,15 +114,18 @@
end end
''; '';
}; };
before_init.__raw = /* lua */ '' on_new_config.__raw = /* lua */ ''
function(_, config) function(config, new_root_dir)
local eslint_config_files = { -- This function is called when LSP attaches to a new buffer
".eslintrc", -- Set the working directory to the root where eslint config is found
".eslintrc.js", config.settings = config.settings or {}
".eslintrc.cjs", config.settings.workspaceFolder = {
".eslintrc.yaml", uri = new_root_dir,
".eslintrc.yml", name = vim.fn.fnamemodify(new_root_dir, ":t"),
".eslintrc.json", }
-- Detect flat config
local flat_config_files = {
"eslint.config.js", "eslint.config.js",
"eslint.config.mjs", "eslint.config.mjs",
"eslint.config.cjs", "eslint.config.cjs",
@ -129,49 +133,21 @@
"eslint.config.mts", "eslint.config.mts",
"eslint.config.cts", "eslint.config.cts",
} }
-- The "workspaceFolder" is a VSCode concept. It limits how far the
-- server will traverse the file system when locating the ESLint config
-- file (e.g., .eslintrc).
local root_dir = config.root_dir
if root_dir then for _, file in ipairs(flat_config_files) do
config.settings = config.settings or {} local config_path = new_root_dir .. "/" .. file
config.settings.workspaceFolder = { if vim.uv.fs_stat(config_path) then
uri = root_dir, config.settings.experimental = config.settings.experimental or {}
name = vim.fn.fnamemodify(root_dir, ":t"), config.settings.experimental.useFlatConfig = true
} break
-- Support flat config files
-- They contain 'config' in the file name
local flat_config_files = vim.tbl_filter(function(file)
return file:match("config")
end, eslint_config_files)
for _, file in ipairs(flat_config_files) do
local found_files = vim.fn.globpath(root_dir, file, true, true)
-- Filter out files inside node_modules
local filtered_files = {}
for _, found_file in ipairs(found_files) do
if string.find(found_file, "[/\\]node_modules[/\\]") == nil then
table.insert(filtered_files, found_file)
end
end
if #filtered_files > 0 then
config.settings.experimental = config.settings.experimental or {}
config.settings.experimental.useFlatConfig = true
break
end
end end
end
-- Support Yarn2 (PnP) projects -- Support Yarn PnP
local pnp_cjs = root_dir .. "/.pnp.cjs" local pnp_cjs = new_root_dir .. "/.pnp.cjs"
local pnp_js = root_dir .. "/.pnp.js" local pnp_js = new_root_dir .. "/.pnp.js"
if vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js) then if vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js) then
local cmd = config.cmd config.cmd = vim.list_extend({ "yarn", "exec" }, config.cmd or {})
config.cmd = vim.list_extend({ "yarn", "exec" }, cmd)
end
end end
end end
''; '';