Skip to content

Commit b426bc3

Browse files
committed
feat(stylelint_lsp): do not use lspconfig.util
1 parent c8bede6 commit b426bc3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lsp/stylelint_lsp.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
--- })
2121
--- ```
2222

23-
local util = require 'lspconfig.util'
24-
25-
local root_file = {
23+
local root_markers = {
2624
'.stylelintrc',
2725
'.stylelintrc.mjs',
2826
'.stylelintrc.cjs',
@@ -35,8 +33,6 @@ local root_file = {
3533
'stylelint.config.js',
3634
}
3735

38-
root_file = util.insert_package_json(root_file, 'stylelint')
39-
4036
return {
4137
cmd = { 'stylelint-lsp', '--stdio' },
4238
filetypes = {
@@ -49,6 +45,21 @@ return {
4945
'vue',
5046
'wxss',
5147
},
52-
root_markers = root_file,
48+
root_dir = function(bufnr, on_dir)
49+
local iswin = vim.uv.os_uname().version:match 'Windows'
50+
local package_json_dir = vim.fs.root(bufnr, 'package.json')
51+
52+
-- Append `package.json` only if contains 'stylelint'
53+
if package_json_dir then
54+
local path_sep = iswin and '\\' or '/'
55+
for line in io.lines(package_json_dir .. path_sep .. 'package.json') do
56+
if line:find('stylelint') then
57+
root_markers[#root_markers + 1] = 'package.json'
58+
end
59+
end
60+
end
61+
62+
on_dir(vim.fs.root(bufnr, root_markers))
63+
end,
5364
settings = {},
5465
}

0 commit comments

Comments
 (0)