File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,28 @@ local root_file = {
47
47
' eslint.config.cts' ,
48
48
}
49
49
50
+ --- Find the closest directory containing the ESLint library.
51
+ --- Using the repository root as the ESLint library location is a common practice
52
+ --- but handling different versions in monorepos can cause the LSP not to point to
53
+ --- the correct instance.
54
+ ---
55
+ --- @return string | nil (path ) The path to the closest directory containing the ESLint library , or nil if not found.
56
+ local function get_eslint_closest_dir ()
57
+ local cwd = vim .fn .getcwd ()
58
+ local eslint_node_modules = vim .fn .finddir (' node_modules/eslint' , cwd .. ' ;' )
59
+
60
+ if eslint_node_modules == ' ' then
61
+ return nil
62
+ end
63
+
64
+ if eslint_node_modules == ' node_modules/eslint' then
65
+ return cwd
66
+ end
67
+
68
+ -- Strip the node_modules/eslint part
69
+ return eslint_node_modules :match ' (.*)/node_modules/eslint'
70
+ end
71
+
50
72
return {
51
73
default_config = {
52
74
cmd = { ' vscode-eslint-language-server' , ' --stdio' },
@@ -102,6 +124,8 @@ return {
102
124
},
103
125
},
104
126
on_new_config = function (config , new_root_dir )
127
+ new_root_dir = get_eslint_closest_dir () or new_root_dir
128
+
105
129
-- The "workspaceFolder" is a VSCode concept. It limits how far the
106
130
-- server will traverse the file system when locating the ESLint config
107
131
-- file (e.g., .eslintrc).
You can’t perform that action at this time.
0 commit comments