aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2024-11-28 22:44:19 +0100
committerGitHub <noreply@github.com>2024-11-28 13:44:19 -0800
commit86dcd4d4ec014c5cb47033c52a54508acd503b97 (patch)
tree94a024bade90965ce0fdc329fc8c63ddb628faed
parentdocs: update configs.md (diff)
downloadnvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar.gz
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar.bz2
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar.lz
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar.xz
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.tar.zst
nvim-lspconfig-86dcd4d4ec014c5cb47033c52a54508acd503b97.zip
refactor: deprecate util.path.is_file #3474
-rw-r--r--.github/ci/run_sanitizer.sh2
-rw-r--r--lua/lspconfig/configs/fennel_ls.lua3
-rw-r--r--lua/lspconfig/configs/turtle_ls.lua2
-rw-r--r--lua/lspconfig/util.lua21
-rw-r--r--scripts/docgen.lua6
-rw-r--r--test/lspconfig_spec.lua29
6 files changed, 18 insertions, 45 deletions
diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh
index b906bf80..09821731 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)'
+SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file)'
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/fennel_ls.lua b/lua/lspconfig/configs/fennel_ls.lua
index f125d54f..269f04f2 100644
--- a/lua/lspconfig/configs/fennel_ls.lua
+++ b/lua/lspconfig/configs/fennel_ls.lua
@@ -6,7 +6,8 @@ return {
filetypes = { 'fennel' },
root_dir = function(dir)
local has_fls_project_cfg = function(path)
- return util.path.is_file(vim.fs.joinpath(path, 'flsproject.fnl'))
+ local fnlpath = vim.fs.joinpath(path, 'flsproject.fnl')
+ return (vim.loop.fs_stat(fnlpath) or {}).type == 'file'
end
return util.search_ancestors(dir, has_fls_project_cfg) or vim.fs.root(0, '.git')
end,
diff --git a/lua/lspconfig/configs/turtle_ls.lua b/lua/lspconfig/configs/turtle_ls.lua
index 21624a82..220953fd 100644
--- a/lua/lspconfig/configs/turtle_ls.lua
+++ b/lua/lspconfig/configs/turtle_ls.lua
@@ -17,7 +17,7 @@ if bin_path == nil then
end
for _, p in ipairs(paths) do
local candidate = util.path.join(p, bin_name)
- if util.path.is_file(candidate) then
+ if (vim.loop.fs_stat(candidate) or {}).type == 'file' then
full_path = candidate
break
end
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 16ffa729..241c7223 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -109,13 +109,6 @@ M.path = (function()
return stat and stat.type == 'directory' or false
end
- --- @param filename string
- --- @return boolean
- local function is_file(filename)
- local stat = uv.fs_stat(filename)
- return stat and stat.type == 'file' or false
- end
-
--- @param path string
--- @return boolean
local function is_fs_root(path)
@@ -196,7 +189,6 @@ M.path = (function()
return {
escape_wildcards = escape_wildcards,
is_dir = is_dir,
- is_file = is_file,
is_absolute = is_absolute,
join = path_join,
traverse_parents = traverse_parents,
@@ -256,7 +248,8 @@ end
function M.find_git_ancestor(startpath)
return M.search_ancestors(startpath, function(path)
-- Support git directories and git files (worktrees)
- if M.path.is_dir(M.path.join(path, '.git')) or M.path.is_file(M.path.join(path, '.git')) then
+ local gitpath = M.path.join(path, '.git')
+ if M.path.is_dir(gitpath) or (uv.fs_stat(gitpath) or {}).type == 'file' then
return path
end
end)
@@ -281,7 +274,8 @@ end
function M.find_package_json_ancestor(startpath)
return M.search_ancestors(startpath, function(path)
- if M.path.is_file(M.path.join(path, 'package.json')) then
+ local jsonpath = M.path.join(path, 'package.json')
+ if (uv.fs_stat(jsonpath) or {}).type == 'file' then
return path
end
end)
@@ -391,6 +385,13 @@ end
--- Deprecated functions
+--- @deprecated use `(vim.loop.fs_stat(path) or {}).type == 'file'` instead
+--- @param path string
+--- @return boolean
+function M.path.is_file(path)
+ return (vim.loop.fs_stat(path) or {}).type == 'file'
+end
+
--- @deprecated use `vim.fs.dirname` instead
M.path.dirname = vim.fs.dirname
diff --git a/scripts/docgen.lua b/scripts/docgen.lua
index 50aef029..ee275f24 100644
--- a/scripts/docgen.lua
+++ b/scripts/docgen.lua
@@ -63,7 +63,7 @@ local function make_section(indentlvl, sep, parts)
end
local function readfile(path)
- assert(util.path.is_file(path))
+ assert((uv.fs_stat(path) or {}).type == 'file')
return io.open(path):read '*a'
end
@@ -181,10 +181,10 @@ local function make_lsp_sections()
function()
local package_json_name = util.path.join(tempdir, config_name .. '.package.json')
if docs.package_json then
- if not util.path.is_file(package_json_name) then
+ if not ((uv.fs_stat(package_json_name) or {}).type == 'file') then
os.execute(string.format('curl -v -L -o %q %q', package_json_name, docs.package_json))
end
- if not util.path.is_file(package_json_name) then
+ if not ((uv.fs_stat(package_json_name) or {}).type == 'file') then
print(string.format('Failed to download package.json for %q at %q', config_name, docs.package_json))
os.exit(1)
return
diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua
index 31d03f1d..8f02960f 100644
--- a/test/lspconfig_spec.lua
+++ b/test/lspconfig_spec.lua
@@ -49,35 +49,6 @@ describe('lspconfig', function()
end)
end)
- describe('is_file', function()
- 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, lspconfig.util.path.is_file(file))
- end)
-
- it('is not present 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() .. '/not_exists.txt'
-
- eq(true, not lspconfig.util.path.is_file(file))
- end)
-
- it('is directory', function()
- local lspconfig = require 'lspconfig'
-
- local cwd = vim.fn.getcwd()
- eq(true, not lspconfig.util.path.is_file(cwd))
- end)
- end)
-
describe('is_absolute', function()
it('is absolute', function()
local lspconfig = require 'lspconfig'