aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2023-04-12 11:52:32 +0800
committerGitHub <noreply@github.com>2023-04-12 11:52:32 +0800
commit6fe69025b8825029ea9bf291ab3b1750f9bcb39e (patch)
tree7de8870070292ddacc9bf80c43c138eef7f865a3 /lua
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar.gz
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar.bz2
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar.lz
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar.xz
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.tar.zst
nvim-lspconfig-6fe69025b8825029ea9bf291ab3b1750f9bcb39e.zip
fix(eslint): get root patterns by given path (#2556)
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/server_configurations/eslint.lua7
-rw-r--r--lua/lspconfig/util.lua7
2 files changed, 8 insertions, 6 deletions
diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua
index af0cdd14..c3b2d746 100644
--- a/lua/lspconfig/server_configurations/eslint.lua
+++ b/lua/lspconfig/server_configurations/eslint.lua
@@ -49,8 +49,6 @@ local root_file = {
'eslint.config.js',
}
-root_file = util.insert_package_json(root_file, 'eslintConfig')
-
return {
default_config = {
cmd = cmd,
@@ -66,7 +64,10 @@ return {
'astro',
},
-- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
- root_dir = util.root_pattern(unpack(root_file)),
+ root_dir = function(fname)
+ root_file = util.insert_package_json(root_file, 'eslintConfig', fname)
+ return util.root_pattern(unpack(root_file))(fname)
+ end,
-- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation.
settings = {
validate = 'on',
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 8725413b..5aff4f39 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -487,15 +487,16 @@ function M.find_package_json_ancestor(startpath)
end)
end
-function M.insert_package_json(config_files, field)
- local root_with_package = M.find_package_json_ancestor(vim.fn.expand '%:p:h')
+function M.insert_package_json(config_files, field, fname)
+ local path = vim.fn.fnamemodify(fname, ':h')
+ local root_with_package = M.find_package_json_ancestor(path)
if root_with_package then
-- only add package.json if it contains field parameter
local path_sep = is_windows and '\\' or '/'
for line in io.lines(root_with_package .. path_sep .. 'package.json') do
if line:find(field) then
- table.insert(config_files, 'package.json')
+ config_files[#config_files + 1] = 'package.json'
break
end
end