tries to fix
This commit is contained in:
parent
ed0201766f
commit
4997c38582
1 changed files with 27 additions and 51 deletions
|
|
@ -50,12 +50,13 @@
|
|||
"eslint.config.ts"
|
||||
"eslint.config.mts"
|
||||
"eslint.config.cts"
|
||||
"package.json"
|
||||
];
|
||||
settings = {
|
||||
validate = "on";
|
||||
useESLintClass = false;
|
||||
experimental = {
|
||||
useFlatConfig = false;
|
||||
useFlatConfig = true;
|
||||
};
|
||||
codeActionOnSave = {
|
||||
enable = false;
|
||||
|
|
@ -71,7 +72,7 @@
|
|||
};
|
||||
nodePath = "";
|
||||
workingDirectory = {
|
||||
mode = "auto";
|
||||
mode = "location";
|
||||
};
|
||||
codeAction = {
|
||||
disableRuleComment = {
|
||||
|
|
@ -113,15 +114,18 @@
|
|||
end
|
||||
'';
|
||||
};
|
||||
before_init.__raw = /* lua */ ''
|
||||
function(_, config)
|
||||
local eslint_config_files = {
|
||||
".eslintrc",
|
||||
".eslintrc.js",
|
||||
".eslintrc.cjs",
|
||||
".eslintrc.yaml",
|
||||
".eslintrc.yml",
|
||||
".eslintrc.json",
|
||||
on_new_config.__raw = /* lua */ ''
|
||||
function(config, new_root_dir)
|
||||
-- This function is called when LSP attaches to a new buffer
|
||||
-- Set the working directory to the root where eslint config is found
|
||||
config.settings = config.settings or {}
|
||||
config.settings.workspaceFolder = {
|
||||
uri = new_root_dir,
|
||||
name = vim.fn.fnamemodify(new_root_dir, ":t"),
|
||||
}
|
||||
|
||||
-- Detect flat config
|
||||
local flat_config_files = {
|
||||
"eslint.config.js",
|
||||
"eslint.config.mjs",
|
||||
"eslint.config.cjs",
|
||||
|
|
@ -129,49 +133,21 @@
|
|||
"eslint.config.mts",
|
||||
"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
|
||||
config.settings = config.settings or {}
|
||||
config.settings.workspaceFolder = {
|
||||
uri = root_dir,
|
||||
name = vim.fn.fnamemodify(root_dir, ":t"),
|
||||
}
|
||||
|
||||
-- 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
|
||||
for _, file in ipairs(flat_config_files) do
|
||||
local config_path = new_root_dir .. "/" .. file
|
||||
if vim.uv.fs_stat(config_path) then
|
||||
config.settings.experimental = config.settings.experimental or {}
|
||||
config.settings.experimental.useFlatConfig = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Support Yarn2 (PnP) projects
|
||||
local pnp_cjs = root_dir .. "/.pnp.cjs"
|
||||
local pnp_js = root_dir .. "/.pnp.js"
|
||||
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" }, cmd)
|
||||
end
|
||||
-- Support Yarn PnP
|
||||
local pnp_cjs = new_root_dir .. "/.pnp.cjs"
|
||||
local pnp_js = new_root_dir .. "/.pnp.js"
|
||||
if vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js) then
|
||||
config.cmd = vim.list_extend({ "yarn", "exec" }, config.cmd or {})
|
||||
end
|
||||
end
|
||||
'';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue