From 2a11b98741d168790cf6fa6798e991b3f78bf314 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Wed, 27 Nov 2024 12:26:00 +0100 Subject: refactor: deprecate `util.path.exists` Use `vim.uv.fs_stat` instead. Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- lua/lspconfig/util.lua | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'lua/lspconfig/util.lua') diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 3e859a8f..16ffa729 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -102,23 +102,18 @@ 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) + return stat and stat.type == 'directory' or false end --- @param filename string --- @return boolean local function is_file(filename) - return exists(filename) == 'file' + local stat = uv.fs_stat(filename) + return stat and stat.type == 'file' or false end --- @param path string @@ -203,7 +198,6 @@ M.path = (function() is_dir = is_dir, is_file = is_file, is_absolute = is_absolute, - exists = exists, join = path_join, traverse_parents = traverse_parents, iterate_parents = iterate_parents, @@ -246,7 +240,7 @@ function M.root_pattern(...) 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 - if M.path.exists(p) then + if uv.fs_stat(p) then return path end end @@ -395,10 +389,20 @@ function M.strip_archive_subpath(path) return path end ----@deprecated use `vim.fs.dirname` instead -M.dirname = vim.fs.dirname +--- Deprecated functions + +--- @deprecated use `vim.fs.dirname` instead +M.path.dirname = vim.fs.dirname --- @deprecated use `vim.fs.normalize` instead -M.sanitize = vim.fs.normalize +M.path.sanitize = vim.fs.normalize + +--- @deprecated use `vim.loop.fs_stat` instead +--- @param filename string +--- @return string|false +function M.path.exists(filename) + local stat = uv.fs_stat(filename) + return stat and stat.type or false +end return M -- cgit v1.2.3-70-g09d2