From c537d90384482d582a41c258516c1e548cebd68c Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 14 Dec 2024 15:52:13 +0100 Subject: [PATCH] refactor: deprecate util.path.escape_wildcards Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- .github/ci/run_sanitizer.sh | 2 +- lua/lspconfig/util.lua | 16 ++++++++++------ test/lspconfig_spec.lua | 15 --------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index 9f6fd3580d..be98e68473 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\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor)' +SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.escape_wildcards|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_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 4bd82b5be8..d76bd5edcd 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -97,10 +97,6 @@ end -- Some path utilities M.path = (function() - local function escape_wildcards(path) - return path:gsub('([%[%]%?%*])', '\\%1') - end - --- @param path string --- @return boolean local function is_fs_root(path) @@ -179,7 +175,6 @@ M.path = (function() local path_separator = iswin and ';' or ':' return { - escape_wildcards = escape_wildcards, is_absolute = is_absolute, join = path_join, traverse_parents = traverse_parents, @@ -216,13 +211,17 @@ function M.get_lsp_clients(filter) return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter) end +local function escape_wildcards(path) + return path:gsub('([%[%]%?%*])', '\\%1') +end + function M.root_pattern(...) local patterns = M.tbl_flatten { ... } return function(startpath) startpath = M.strip_archive_subpath(startpath) for _, pattern in ipairs(patterns) do local match = M.search_ancestors(startpath, function(path) - for _, p in ipairs(vim.fn.glob(M.path.join(M.path.escape_wildcards(path), pattern), true, true)) do + for _, p in ipairs(vim.fn.glob(M.path.join(escape_wildcards(path), pattern), true, true)) do if vim.loop.fs_stat(p) then return path end @@ -378,6 +377,11 @@ function M.path.exists(filename) return stat and stat.type or false end +--- @deprecated +function M.path.escape_wildcards(path) + return path:gsub('([%[%]%?%*])', '\\%1') +end + --- @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]) diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 256faba203..a34dc40edb 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -10,21 +10,6 @@ describe('lspconfig', function() describe('util', function() describe('path', function() - describe('escape_wildcards', function() - it('doesnt escape if not needed', function() - local lspconfig = require 'lspconfig' - - local res = lspconfig.util.path.escape_wildcards '/usr/local/test/fname.lua' - eq('/usr/local/test/fname.lua', res) - end) - it('escapes if needed', function() - local lspconfig = require 'lspconfig' - - local res = lspconfig.util.path.escape_wildcards '/usr/local/test/[sq brackets] fname?*.lua' - eq('/usr/local/test/\\[sq brackets\\] fname\\?\\*.lua', res) - end) - end) - describe('is_absolute', function() it('is absolute', function() local lspconfig = require 'lspconfig'