From f675f8c430ae3012f6d140899c2cec3b59e9cb43 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 13 Dec 2024 14:02:48 +0100 Subject: refactor: deprecate util.find_package_json_ancestor Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- lua/lspconfig/util.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'lua/lspconfig/util.lua') diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 7b894ee3..a5cf67fd 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -246,18 +246,9 @@ function M.find_git_ancestor(startpath) end) end -function M.find_package_json_ancestor(startpath) - return M.search_ancestors(startpath, function(path) - local jsonpath = M.path.join(path, 'package.json') - if (vim.loop.fs_stat(jsonpath) or {}).type == 'file' then - return path - end - end) -end - 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) + local root_with_package = vim.fs.find('package.json', { path = path, upward = true })[1] if root_with_package then -- only add package.json if it contains field parameter @@ -397,4 +388,9 @@ function M.find_node_modules_ancestor(startpath) return vim.fs.find('node_modules', { path = startpath, upward = true })[1] end +--- @deprecated use `vim.fs.find('package.json', { path = startpath, upward = true })[1]` instead +function M.find_package_json_ancestor(startpath) + return vim.fs.find('package.json', { path = startpath, upward = true })[1] +end + return M -- cgit v1.2.3-70-g09d2