Skip to content

Commit

Permalink
refactor: deprecate util.path.exists
Browse files Browse the repository at this point in the history
Use `vim.uv.fs_stat` instead.

Work on neovim#2079.
  • Loading branch information
dundargoc committed Nov 27, 2024
1 parent d651732 commit 0526867
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 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)'
SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists)'

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
29 changes: 19 additions & 10 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,24 @@ M.path = (function()
return path:gsub('([%[%]%?%*])', '\\%1')
end

--- @param filename string
--- @return string|false
local function exists(filename)
local stat = uv.fs_stat(filename)
return stat and stat.type or false
end

--- @param filename string
--- @return boolean
local function is_dir(filename)
return exists(filename) == 'directory'
local stat = uv.fs_stat(filename)
if not stat then
return false
end
return stat.type == 'directory'
end

--- @param filename string
--- @return boolean
local function is_file(filename)
return exists(filename) == 'file'
local stat = uv.fs_stat(filename)
if not stat then
return false
end
return stat.type == 'file'
end

--- @param path string
Expand Down Expand Up @@ -395,10 +396,18 @@ function M.strip_archive_subpath(path)
return path
end

---@deprecated use `vim.fs.dirname` instead
--- @deprecated use `vim.fs.dirname` instead
M.dirname = vim.fs.dirname

--- @deprecated use `vim.fs.normalize` instead
M.sanitize = vim.fs.normalize

--- @deprecated use `vim.loop.fs_stat` instead
--- @param filename string
--- @return string|false
function M.exists(filename)
local stat = uv.fs_stat(filename)
return stat and stat.type or false
end

return M

0 comments on commit 0526867

Please sign in to comment.