From 9204642002ba91f9e0b7d0e5989f373657fe754a Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 22 Dec 2024 14:08:38 +0100 Subject: [PATCH] refactor: deprecate util.path.iterate_parents Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- .github/ci/run_sanitizer.sh | 2 +- lua/lspconfig/util.lua | 23 ++++------------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index af1ceeb8e5..edcf4b5a98 100644 --- a/.github/ci/run_sanitizer.sh +++ b/.github/ci/run_sanitizer.sh @@ -15,7 +15,7 @@ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANC exit 1 fi -SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor)' +SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor)' if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then echo diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 7a47d72214..e3e238079f 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -127,23 +127,6 @@ M.path = (function() end end - -- Iterate the path until we find the rootdir. - local function iterate_parents(path) - local function it(_, v) - if v and not is_fs_root(v) then - v = vim.fs.dirname(v) - else - return - end - if v and vim.loop.fs_realpath(v) then - return v, path - else - return - end - end - return it, path, path - end - local function is_descendant(root, path) if not path then return false @@ -160,7 +143,6 @@ M.path = (function() return { traverse_parents = traverse_parents, - iterate_parents = iterate_parents, is_descendant = is_descendant, } end)() @@ -173,7 +155,7 @@ function M.search_ancestors(startpath, func) return startpath end local guard = 100 - for path in M.path.iterate_parents(startpath) do + for path in vim.fs.parents(startpath) do -- Prevent infinite recursion if our algorithm breaks guard = guard - 1 if guard == 0 then @@ -363,6 +345,9 @@ end --- @deprecated use `vim.fn.has('win32') == 1 and ';' or ':'` instead M.path.path_separator = vim.fn.has('win32') == 1 and ';' or ':' +--- @deprecated use `vim.fs.parents(path)` instead +M.path.iterate_parents = vim.fs.parents + --- @deprecated use `vim.fs.dirname(vim.fs.find('.hg', { path = startpath, upward = true })[1])` instead function M.find_mercurial_ancestor(startpath) return vim.fs.dirname(vim.fs.find('.hg', { path = startpath, upward = true })[1])