diff options
| author | dundargoc <gocdundar@gmail.com> | 2024-11-27 12:26:00 +0100 |
|---|---|---|
| committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2024-11-27 14:56:17 +0100 |
| commit | 2a11b98741d168790cf6fa6798e991b3f78bf314 (patch) | |
| tree | 568b531425172c7efaff914fbc39d46c1a7b2bfa | |
| parent | refactor: group deprecated functions at the end (diff) | |
| download | nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar.gz nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar.bz2 nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar.lz nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar.xz nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.tar.zst nvim-lspconfig-2a11b98741d168790cf6fa6798e991b3f78bf314.zip | |
refactor: deprecate `util.path.exists`
Use `vim.uv.fs_stat` instead.
Work on https://github.com/neovim/nvim-lspconfig/issues/2079.
| -rw-r--r-- | .github/ci/run_sanitizer.sh | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs/eslint.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs/foam_ls.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs/relay_lsp.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs/vdmj.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs/volar.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 32 | ||||
| -rw-r--r-- | test/lspconfig_spec.lua | 30 |
8 files changed, 24 insertions, 50 deletions
diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index 07d4723c..b906bf80 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)' +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 diff --git a/lua/lspconfig/configs/eslint.lua b/lua/lspconfig/configs/eslint.lua index 283498c8..c3a06954 100644 --- a/lua/lspconfig/configs/eslint.lua +++ b/lua/lspconfig/configs/eslint.lua @@ -125,7 +125,7 @@ return { -- Support Yarn2 (PnP) projects local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs') local pnp_js = util.path.join(new_root_dir, '.pnp.js') - if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then + if vim.loop.fs_stat(pnp_cjs) or vim.loop.fs_stat(pnp_js) then config.cmd = vim.list_extend({ 'yarn', 'exec' }, config.cmd) end end, diff --git a/lua/lspconfig/configs/foam_ls.lua b/lua/lspconfig/configs/foam_ls.lua index 1a991b61..265f679c 100644 --- a/lua/lspconfig/configs/foam_ls.lua +++ b/lua/lspconfig/configs/foam_ls.lua @@ -6,7 +6,7 @@ return { filetypes = { 'foam', 'OpenFOAM' }, root_dir = function(fname) return util.search_ancestors(fname, function(path) - if util.path.exists(util.path.join(path, 'system', 'controlDict')) then + if vim.loop.fs_stat(util.path.join(path, 'system', 'controlDict')) then return path end end) diff --git a/lua/lspconfig/configs/relay_lsp.lua b/lua/lspconfig/configs/relay_lsp.lua index 9f2b3776..66e00384 100644 --- a/lua/lspconfig/configs/relay_lsp.lua +++ b/lua/lspconfig/configs/relay_lsp.lua @@ -36,7 +36,7 @@ return { if config.path_to_config then config.path_to_config = vim.fs.normalize(config.path_to_config) local path_to_config = util.path.join(root_dir, config.path_to_config) - if util.path.exists(path_to_config) then + if vim.loop.fs_stat(path_to_config) then vim.list_extend(config.cmd, { config.path_to_config }) vim.list_extend(compiler_cmd, { config.path_to_config }) else diff --git a/lua/lspconfig/configs/vdmj.lua b/lua/lspconfig/configs/vdmj.lua index ecb04a92..d7abe4c9 100644 --- a/lua/lspconfig/configs/vdmj.lua +++ b/lua/lspconfig/configs/vdmj.lua @@ -2,7 +2,7 @@ local util = require 'lspconfig.util' local function get_default_mavenrepo() local repo = util.path.join(vim.env.HOME, '.m2', 'repository', 'dk', 'au', 'ece', 'vdmj') - if util.path.exists(repo) then + if vim.loop.fs_stat(repo) then return repo else return util.path.join(vim.env.HOME, '.m2', 'repository', 'com', 'fujitsu') diff --git a/lua/lspconfig/configs/volar.lua b/lua/lspconfig/configs/volar.lua index 888cd165..d4a65e4c 100644 --- a/lua/lspconfig/configs/volar.lua +++ b/lua/lspconfig/configs/volar.lua @@ -91,7 +91,7 @@ local function get_typescript_server_path(root_dir) local found_ts = '' local function check_dir(path) found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib') - if util.path.exists(found_ts) then + if vim.loop.fs_stat(found_ts) then return path end end 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 @@ -103,22 +103,17 @@ M.path = (function() 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 diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 36eca3bc..31d03f1d 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -24,36 +24,6 @@ describe('lspconfig', function() eq('/usr/local/test/\\[sq brackets\\] fname\\?\\*.lua', res) end) end) - describe('exists', function() - it('is present directory', function() - local lspconfig = require 'lspconfig' - - local cwd = vim.fn.getcwd() - eq(true, lspconfig.util.path.exists(cwd) ~= false) - end) - - it('is not present directory', function() - local lspconfig = require 'lspconfig' - local not_exist_dir = vim.fn.getcwd() .. '/not/exists' - eq(true, lspconfig.util.path.exists(not_exist_dir) == false) - end) - - it('is 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() .. '/root_marker.txt' - eq(true, lspconfig.util.path.exists(file) ~= false) - 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' - assert.is_false(lspconfig.util.path.exists(file)) - end) - end) describe('is_dir', function() it('is directory', function() |
