From 217d21c562afce0b8cd00c0547a695196929db83 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 21 Dec 2024 14:08:47 +0100 Subject: [PATCH] refactor: deprecate util.path.join Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- .github/ci/run_sanitizer.sh | 2 +- lua/lspconfig/configs/jdtls.lua | 8 ++++---- lua/lspconfig/configs/jsonnet_ls.lua | 4 ++-- lua/lspconfig/util.lua | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index bba0616234..af1ceeb8e5 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|util\.path\.is_dir|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor)' +SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor)' 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/jdtls.lua b/lua/lspconfig/configs/jdtls.lua index 871f821a99..61133eca0c 100644 --- a/lua/lspconfig/configs/jdtls.lua +++ b/lua/lspconfig/configs/jdtls.lua @@ -8,19 +8,19 @@ local env = { } local function get_cache_dir() - return env.XDG_CACHE_HOME and env.XDG_CACHE_HOME or util.path.join(env.HOME, '.cache') + return env.XDG_CACHE_HOME and env.XDG_CACHE_HOME or env.HOME .. '/.cache' end local function get_jdtls_cache_dir() - return util.path.join(get_cache_dir(), 'jdtls') + return get_cache_dir() .. '/jdtls' end local function get_jdtls_config_dir() - return util.path.join(get_jdtls_cache_dir(), 'config') + return get_jdtls_cache_dir() .. '/config' end local function get_jdtls_workspace_dir() - return util.path.join(get_jdtls_cache_dir(), 'workspace') + return get_jdtls_cache_dir() .. '/workspace' end local function get_jdtls_jvm_args() diff --git a/lua/lspconfig/configs/jsonnet_ls.lua b/lua/lspconfig/configs/jsonnet_ls.lua index 284cd09197..43a53b4d61 100644 --- a/lua/lspconfig/configs/jsonnet_ls.lua +++ b/lua/lspconfig/configs/jsonnet_ls.lua @@ -3,8 +3,8 @@ local util = require 'lspconfig.util' -- common jsonnet library paths local function jsonnet_path(root_dir) local paths = { - util.path.join(root_dir, 'lib'), - util.path.join(root_dir, 'vendor'), + root_dir .. '/lib', + root_dir .. '/vendor', } return table.concat(paths, ':') end diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 213e87f398..c1ad0128e7 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -107,10 +107,6 @@ M.path = (function() end end - local function path_join(...) - return table.concat(M.tbl_flatten { ... }, '/') - end - -- Traverse the path calling cb along the way. local function traverse_parents(path, cb) path = vim.loop.fs_realpath(path) @@ -165,7 +161,6 @@ M.path = (function() local path_separator = iswin and ';' or ':' return { - join = path_join, traverse_parents = traverse_parents, iterate_parents = iterate_parents, is_descendant = is_descendant, @@ -204,7 +199,7 @@ function M.root_pattern(...) startpath = M.strip_archive_subpath(startpath) for _, pattern in ipairs(patterns) do local match = M.search_ancestors(startpath, function(path) - for _, p in ipairs(vim.fn.glob(M.path.join(escape_wildcards(path), pattern), true, true)) do + for _, p in ipairs(vim.fn.glob(table.concat({ escape_wildcards(path), pattern }, '/'), true, true)) do if vim.loop.fs_stat(p) then return path end @@ -363,6 +358,11 @@ function M.path.exists(filename) return stat and stat.type or false end +--- @deprecated use `table.concat({"path1", "path2"})` or regular string concatenation instead +function M.path.join(...) + return table.concat({ ... }, '/') +end + --- @deprecated use `vim.fs.dirname(vim.fs.find('.hg', { path = startpath, upward = true })[1])` instead function M.find_mercurial_ancestor(startpath) return vim.fs.dirname(vim.fs.find('.hg', { path = startpath, upward = true })[1])