aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWuelner Martínez <wuelner.martinez@outlook.com>2023-02-11 19:43:43 -0600
committerGitHub <noreply@github.com>2023-02-12 09:43:43 +0800
commit641a71e381e23f1d1d6a0722a8b796fda896b55b (patch)
tree1c06a8c91d0aa6bc87f4dc0ec31331b223c5928a /lua
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.gz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.bz2
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.lz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.xz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.zst
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.zip
fix(stylelint_lsp): update root directory pattern (#2447)
* fix(stylelint_lsp): update root directory pattern Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * feat(util): add `add_package_json_to_config_files_if_field_exists` function Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(stylelint_lsp): update update root directory pattern implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(eslint): update update root directory pattern implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(util): update `is_windows` detection Co-authored-by: Raphael <glephunter@gmail.com> * fix(util): update new function name Co-authored-by: Raphael <glephunter@gmail.com> * fix(server_configurations): update new function name implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(stylelint_lsp): fix duplicate equals Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> --------- Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> Co-authored-by: Raphael <glephunter@gmail.com>
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/server_configurations/eslint.lua16
-rw-r--r--lua/lspconfig/server_configurations/stylelint_lsp.lua18
-rw-r--r--lua/lspconfig/util.lua19
3 files changed, 33 insertions, 20 deletions
diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua
index dc71e94f..af0cdd14 100644
--- a/lua/lspconfig/server_configurations/eslint.lua
+++ b/lua/lspconfig/server_configurations/eslint.lua
@@ -1,6 +1,5 @@
local util = require 'lspconfig.util'
local lsp = vim.lsp
-local is_windows = vim.fn.has 'win32' == 1
local function fix_all(opts)
opts = opts or {}
@@ -36,7 +35,7 @@ end
local bin_name = 'vscode-eslint-language-server'
local cmd = { bin_name, '--stdio' }
-if is_windows then
+if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
@@ -50,18 +49,7 @@ local root_file = {
'eslint.config.js',
}
-local root_with_package = util.find_package_json_ancestor(vim.fn.expand '%:p:h')
-
-if root_with_package then
- -- only add package.json if it contains eslintConfig field
- local path_sep = is_windows and '\\' or '/'
- for line in io.lines(root_with_package .. path_sep .. 'package.json') do
- if line:find 'eslintConfig' then
- table.insert(root_file, 'package.json')
- break
- end
- end
-end
+root_file = util.insert_package_json(root_file, 'eslintConfig')
return {
default_config = {
diff --git a/lua/lspconfig/server_configurations/stylelint_lsp.lua b/lua/lspconfig/server_configurations/stylelint_lsp.lua
index d471d267..314bb89f 100644
--- a/lua/lspconfig/server_configurations/stylelint_lsp.lua
+++ b/lua/lspconfig/server_configurations/stylelint_lsp.lua
@@ -7,6 +7,19 @@ if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
+local root_file = {
+ '.stylelintrc',
+ '.stylelintrc.cjs',
+ '.stylelintrc.js',
+ '.stylelintrc.json',
+ '.stylelintrc.yaml',
+ '.stylelintrc.yml',
+ 'stylelint.config.cjs',
+ 'stylelint.config.js',
+}
+
+root_file = util.insert_package_json(root_file, 'stylelint')
+
return {
default_config = {
cmd = cmd,
@@ -22,7 +35,7 @@ return {
'typescript',
'typescriptreact',
},
- root_dir = util.root_pattern('.stylelintrc', 'package.json'),
+ root_dir = util.root_pattern(unpack(root_file)),
settings = {},
},
docs = {
@@ -47,8 +60,5 @@ require'lspconfig'.stylelint_lsp.setup{
}
```
]],
- default_config = {
- root_dir = [[ root_pattern('.stylelintrc', 'package.json') ]],
- },
},
}
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 698cd2d9..ae2b1ada 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -4,6 +4,8 @@ local api = vim.api
local lsp = vim.lsp
local uv = vim.loop
+local is_windows = uv.os_uname().sysname == 'Windows_NT'
+
local M = {}
M.default_config = {
@@ -94,8 +96,6 @@ end
-- Some path utilities
M.path = (function()
- local is_windows = uv.os_uname().version:match 'Windows'
-
local function escape_wildcards(path)
return path:gsub('([%[%]%?%*])', '\\%1')
end
@@ -487,6 +487,21 @@ 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')
+
+ 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
+ return table.insert(config_files, 'package.json')
+ end
+ end
+ end
+ return config_files
+end
+
function M.get_active_clients_list_by_ft(filetype)
local clients = vim.lsp.get_active_clients()
local clients_list = {}