diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index 09821731d0..f2fadb9c5c 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)' +SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir)' 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/configs/vdmj.lua b/lua/lspconfig/configs/vdmj.lua index d7abe4c940..a9621a74fe 100644 --- a/lua/lspconfig/configs/vdmj.lua +++ b/lua/lspconfig/configs/vdmj.lua @@ -34,7 +34,7 @@ end -- Special case, as vdmj store particular settings under root_dir/.vscode local function find_vscode_ancestor(startpath) return util.search_ancestors(startpath, function(path) - if util.path.is_dir(util.path.join(path, '.vscode')) then + if vim.fn.isdirectory(util.path.join(path, '.vscode')) == 1 then return path end end) diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 241c72238b..f8ffe57e41 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -102,13 +102,6 @@ M.path = (function() return path:gsub('([%[%]%?%*])', '\\%1') end - --- @param filename string - --- @return boolean - local function is_dir(filename) - local stat = uv.fs_stat(filename) - return stat and stat.type == 'directory' or false - end - --- @param path string --- @return boolean local function is_fs_root(path) @@ -188,7 +181,6 @@ M.path = (function() return { escape_wildcards = escape_wildcards, - is_dir = is_dir, is_absolute = is_absolute, join = path_join, traverse_parents = traverse_parents, @@ -249,7 +241,7 @@ function M.find_git_ancestor(startpath) return M.search_ancestors(startpath, function(path) -- Support git directories and git files (worktrees) local gitpath = M.path.join(path, '.git') - if M.path.is_dir(gitpath) or (uv.fs_stat(gitpath) or {}).type == 'file' then + if vim.fn.isdirectory(gitpath) == 1 or (uv.fs_stat(gitpath) or {}).type == 'file' then return path end end) @@ -258,7 +250,7 @@ end function M.find_mercurial_ancestor(startpath) return M.search_ancestors(startpath, function(path) -- Support Mercurial directories - if M.path.is_dir(M.path.join(path, '.hg')) then + if vim.fn.isdirectory(M.path.join(path, '.hg')) == 1 then return path end end) @@ -266,7 +258,7 @@ end function M.find_node_modules_ancestor(startpath) return M.search_ancestors(startpath, function(path) - if M.path.is_dir(M.path.join(path, 'node_modules')) then + if vim.fn.isdirectory(M.path.join(path, 'node_modules')) == 1 then return path end end) @@ -385,6 +377,13 @@ end --- Deprecated functions +--- @deprecated use `vim.fn.isdirectory(path) == 1` instead +--- @param filename string +--- @return boolean +function M.path.is_dir(filename) + return vim.fn.isdirectory(filename) == 1 +end + --- @deprecated use `(vim.loop.fs_stat(path) or {}).type == 'file'` instead --- @param path string --- @return boolean diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 8f02960f12..256faba203 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -25,30 +25,6 @@ describe('lspconfig', function() end) end) - describe('is_dir', function() - it('is directory', function() - local lspconfig = require 'lspconfig' - local cwd = vim.fn.getcwd() - assert.is_true(lspconfig.util.path.is_dir(cwd)) - end) - - it('is not present directory', function() - local lspconfig = require 'lspconfig' - local not_exist_dir = vim.fn.getcwd() .. '/not/exists' - eq(true, not lspconfig.util.path.is_dir(not_exist_dir)) - end) - - it('is file', function() - local lspconfig = require 'lspconfig' - - -- change the working directory to test directory - vim.api.nvim_command 'cd ./test/test_dir/' - local file = vim.fn.getcwd() .. '/root_marker.txt' - - eq(true, not lspconfig.util.path.is_dir(file)) - end) - end) - describe('is_absolute', function() it('is absolute', function() local lspconfig = require 'lspconfig'