Skip to content

Commit

Permalink
refactor: deprecate util.path.escape_wildcards
Browse files Browse the repository at this point in the history
Work on #2079.
  • Loading branch information
dundargoc committed Dec 14, 2024
1 parent 3cb6c05 commit d031e0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/ci/run_sanitizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -216,13 +211,18 @@ 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
Expand Down Expand Up @@ -378,6 +378,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])
Expand Down

0 comments on commit d031e0f

Please sign in to comment.