Skip to content

Commit 641e567

Browse files
authored
feat(util): support "package.json5" #3794
Problem: Root detection fails when using `package.json5`. #3710 Solution: Modify `insert_package_json` to support `package.json5`.
1 parent 48f4475 commit 641e567

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lua/lspconfig/util.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ end
4646

4747
function M.insert_package_json(config_files, field, fname)
4848
local path = vim.fn.fnamemodify(fname, ':h')
49-
local root_with_package = vim.fs.dirname(vim.fs.find('package.json', { path = path, upward = true })[1])
49+
local root_with_package = vim.fs.find({ 'package.json', 'package.json5' }, { path = path, upward = true })[1]
5050

5151
if root_with_package then
5252
-- only add package.json if it contains field parameter
53-
local path_sep = iswin and '\\' or '/'
54-
for line in io.lines(root_with_package .. path_sep .. 'package.json') do
53+
for line in io.lines(root_with_package) do
5554
if line:find(field) then
56-
config_files[#config_files + 1] = 'package.json'
55+
config_files[#config_files + 1] = vim.fs.basename(root_with_package)
5756
break
5857
end
5958
end

0 commit comments

Comments
 (0)