From 45c5095097702e8316f9409b39b2721db8534db2 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/apex_ls.lua | 2 +- lua/lspconfig/configs/astro.lua | 2 +- lua/lspconfig/configs/cadence.lua | 2 +- lua/lspconfig/configs/drools_lsp.lua | 4 +--- lua/lspconfig/configs/eslint.lua | 4 ++-- lua/lspconfig/configs/foam_ls.lua | 2 +- lua/lspconfig/configs/gitlab_ci_ls.lua | 4 ++-- lua/lspconfig/configs/glint.lua | 2 +- lua/lspconfig/configs/jdtls.lua | 8 ++++---- lua/lspconfig/configs/jsonnet_ls.lua | 4 ++-- lua/lspconfig/configs/mdx_analyzer.lua | 2 +- lua/lspconfig/configs/relay_lsp.lua | 6 +++--- lua/lspconfig/configs/rust_analyzer.lua | 12 ++++++------ lua/lspconfig/configs/turtle_ls.lua | 6 ++---- lua/lspconfig/configs/vala_ls.lua | 2 +- lua/lspconfig/configs/vdmj.lua | 18 +++++++++--------- lua/lspconfig/configs/volar.lua | 2 +- lua/lspconfig/util.lua | 12 ++++++------ scripts/docgen.lua | 2 +- test/lspconfig_spec.lua | 10 ---------- 21 files changed, 47 insertions(+), 61 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/apex_ls.lua b/lua/lspconfig/configs/apex_ls.lua index 150e692ccd..33b774bc24 100644 --- a/lua/lspconfig/configs/apex_ls.lua +++ b/lua/lspconfig/configs/apex_ls.lua @@ -7,7 +7,7 @@ return { on_new_config = function(config) if not config.cmd and config.apex_jar_path then config.cmd = { - vim.env.JAVA_HOME and util.path.join(vim.env.JAVA_HOME, 'bin', 'java') or 'java', + vim.env.JAVA_HOME and (vim.env.JAVA_HOME .. '/bin/java') or 'java', '-cp', config.apex_jar_path, '-Ddebug.internal.errors=true', diff --git a/lua/lspconfig/configs/astro.lua b/lua/lspconfig/configs/astro.lua index a29ec1c1bf..2600356dd5 100644 --- a/lua/lspconfig/configs/astro.lua +++ b/lua/lspconfig/configs/astro.lua @@ -2,7 +2,7 @@ local util = require 'lspconfig.util' local function get_typescript_server_path(root_dir) local project_root = vim.fs.find('node_modules', { path = root_dir, upward = true })[1] - return project_root and (util.path.join(project_root, 'typescript', 'lib')) or '' + return project_root and (project_root .. '/typescript/lib') or '' end return { diff --git a/lua/lspconfig/configs/cadence.lua b/lua/lspconfig/configs/cadence.lua index c9550e83ef..2896f68234 100644 --- a/lua/lspconfig/configs/cadence.lua +++ b/lua/lspconfig/configs/cadence.lua @@ -11,7 +11,7 @@ return { return util.root_pattern 'flow.json'(fname) or vim.env.HOME end, on_new_config = function(new_config, new_root_dir) - new_config.init_options.configPath = util.path.join(new_root_dir, 'flow.json') + new_config.init_options.configPath = new_root_dir .. '/flow.json' end, }, docs = { diff --git a/lua/lspconfig/configs/drools_lsp.lua b/lua/lspconfig/configs/drools_lsp.lua index 77d9d58bf1..fa00e3cbc0 100644 --- a/lua/lspconfig/configs/drools_lsp.lua +++ b/lua/lspconfig/configs/drools_lsp.lua @@ -1,9 +1,7 @@ -local util = require 'lspconfig.util' - local function get_java_bin(config) local java_bin = vim.tbl_get(config, 'drools', 'java', 'bin') if not java_bin then - java_bin = vim.env.JAVA_HOME and util.path.join(vim.env.JAVA_HOME, 'bin', 'java') or 'java' + java_bin = vim.env.JAVA_HOME and (vim.env.JAVA_HOME .. '/bin/java') or 'java' if vim.fn.has 'win32' == 1 then java_bin = java_bin .. '.exe' end diff --git a/lua/lspconfig/configs/eslint.lua b/lua/lspconfig/configs/eslint.lua index 0ff7699c9d..70a2116738 100644 --- a/lua/lspconfig/configs/eslint.lua +++ b/lua/lspconfig/configs/eslint.lua @@ -123,8 +123,8 @@ return { end -- 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') + local pnp_cjs = new_root_dir .. '/.pnp.cjs' + local pnp_js = new_root_dir .. '/.pnp.js' 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 diff --git a/lua/lspconfig/configs/foam_ls.lua b/lua/lspconfig/configs/foam_ls.lua index 265f679c67..e4be876b54 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 vim.loop.fs_stat(util.path.join(path, 'system', 'controlDict')) then + if vim.loop.fs_stat(path .. '/system/controlDict') then return path end end) diff --git a/lua/lspconfig/configs/gitlab_ci_ls.lua b/lua/lspconfig/configs/gitlab_ci_ls.lua index 02c98db289..dfa0ff88bb 100644 --- a/lua/lspconfig/configs/gitlab_ci_ls.lua +++ b/lua/lspconfig/configs/gitlab_ci_ls.lua @@ -1,6 +1,6 @@ local util = require 'lspconfig.util' -local cache_dir = util.path.join(vim.loop.os_homedir(), '.cache/gitlab-ci-ls/') +local cache_dir = vim.loop.os_homedir() .. '/.cache/gitlab-ci-ls/' return { default_config = { cmd = { 'gitlab-ci-ls' }, @@ -8,7 +8,7 @@ return { root_dir = util.root_pattern('.gitlab*', '.git'), init_options = { cache_path = cache_dir, - log_path = util.path.join(cache_dir, 'log/gitlab-ci-ls.log'), + log_path = cache_dir .. '/log/gitlab-ci-ls.log', }, }, docs = { diff --git a/lua/lspconfig/configs/glint.lua b/lua/lspconfig/configs/glint.lua index 370d2797b8..8baa725694 100644 --- a/lua/lspconfig/configs/glint.lua +++ b/lua/lspconfig/configs/glint.lua @@ -6,7 +6,7 @@ return { on_new_config = function(config, new_root_dir) local project_root = vim.fs.find('node_modules', { path = new_root_dir, upward = true })[1] -- Glint should not be installed globally. - local node_bin_path = util.path.join(project_root, 'node_modules', '.bin') + local node_bin_path = project_root .. '/node_modules/.bin' local path = node_bin_path .. util.path.path_separator .. vim.env.PATH if config.cmd_env then config.cmd_env.PATH = path 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/configs/mdx_analyzer.lua b/lua/lspconfig/configs/mdx_analyzer.lua index 311d90de2a..37948d2369 100644 --- a/lua/lspconfig/configs/mdx_analyzer.lua +++ b/lua/lspconfig/configs/mdx_analyzer.lua @@ -2,7 +2,7 @@ local util = require 'lspconfig.util' local function get_typescript_server_path(root_dir) local project_root = vim.fs.find('node_modules', { path = root_dir, upward = true })[1] - return project_root and (util.path.join(project_root, 'node_modules', 'typescript', 'lib')) or '' + return project_root and (project_root .. '/node_modules/typescript/lib') or '' end return { diff --git a/lua/lspconfig/configs/relay_lsp.lua b/lua/lspconfig/configs/relay_lsp.lua index a0ebaf633e..baf5578cb5 100644 --- a/lua/lspconfig/configs/relay_lsp.lua +++ b/lua/lspconfig/configs/relay_lsp.lua @@ -24,8 +24,8 @@ return { root_dir = util.root_pattern('relay.config.*', 'package.json'), on_new_config = function(config, root_dir) local project_root = vim.fs.find('node_modules', { path = root_dir, upward = true })[1] - local node_bin_path = util.path.join(project_root, 'node_modules', '.bin') - local compiler_cmd = { util.path.join(node_bin_path, 'relay-compiler'), '--watch' } + local node_bin_path = project_root .. '/node_modules/.bin' + local compiler_cmd = { node_bin_path .. '/relay-compiler', '--watch' } local path = node_bin_path .. util.path.path_separator .. vim.env.PATH if config.cmd_env then config.cmd_env.PATH = path @@ -35,7 +35,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) + local path_to_config = table.concat({ root_dir, config.path_to_config }, '/') 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 }) diff --git a/lua/lspconfig/configs/rust_analyzer.lua b/lua/lspconfig/configs/rust_analyzer.lua index fbea04e464..5f592d4007 100644 --- a/lua/lspconfig/configs/rust_analyzer.lua +++ b/lua/lspconfig/configs/rust_analyzer.lua @@ -17,12 +17,12 @@ end local function is_library(fname) local user_home = vim.fs.normalize(vim.env.HOME) - local cargo_home = os.getenv 'CARGO_HOME' or util.path.join(user_home, '.cargo') - local registry = util.path.join(cargo_home, 'registry', 'src') - local git_registry = util.path.join(cargo_home, 'git', 'checkouts') + local cargo_home = os.getenv 'CARGO_HOME' or user_home .. '/.cargo' + local registry = cargo_home .. '/registry/src' + local git_registry = cargo_home .. '/git/checkouts' - local rustup_home = os.getenv 'RUSTUP_HOME' or util.path.join(user_home, '.rustup') - local toolchains = util.path.join(rustup_home, 'toolchains') + local rustup_home = os.getenv 'RUSTUP_HOME' or user_home .. '/.rustup' + local toolchains = rustup_home .. '/toolchains' for _, item in ipairs { toolchains, registry, git_registry } do if util.path.is_descendant(item, fname) then @@ -54,7 +54,7 @@ return { '--format-version', '1', '--manifest-path', - util.path.join(cargo_crate_dir, 'Cargo.toml'), + cargo_crate_dir .. '/Cargo.toml', } local result = async.run_command(cmd) diff --git a/lua/lspconfig/configs/turtle_ls.lua b/lua/lspconfig/configs/turtle_ls.lua index 0528b7fc8d..630f836de8 100644 --- a/lua/lspconfig/configs/turtle_ls.lua +++ b/lua/lspconfig/configs/turtle_ls.lua @@ -1,5 +1,3 @@ -local util = require 'lspconfig.util' - local bin_name = 'turtle-language-server' local bin_path = os.getenv 'NVM_BIN' local full_path @@ -16,14 +14,14 @@ if bin_path == nil then end end for _, p in ipairs(paths) do - local candidate = util.path.join(p, bin_name) + local candidate = table.concat({ p, bin_name }, '/') if (vim.loop.fs_stat(candidate) or {}).type == 'file' then full_path = candidate break end end else - full_path = util.path.join(bin_path, bin_name) + full_path = table.concat({ bin_path, bin_name }, '/') end return { diff --git a/lua/lspconfig/configs/vala_ls.lua b/lua/lspconfig/configs/vala_ls.lua index 34317c32ab..26191d9dc6 100644 --- a/lua/lspconfig/configs/vala_ls.lua +++ b/lua/lspconfig/configs/vala_ls.lua @@ -2,7 +2,7 @@ local util = require 'lspconfig.util' local meson_matcher = function(path) local pattern = 'meson.build' - local f = vim.fn.glob(util.path.join(path, pattern)) + local f = vim.fn.glob(table.concat({ path, pattern }, '/')) if f == '' then return nil end diff --git a/lua/lspconfig/configs/vdmj.lua b/lua/lspconfig/configs/vdmj.lua index 2f5b525658..89bf2ccc18 100644 --- a/lua/lspconfig/configs/vdmj.lua +++ b/lua/lspconfig/configs/vdmj.lua @@ -1,16 +1,16 @@ local util = require 'lspconfig.util' local function get_default_mavenrepo() - local repo = util.path.join(vim.env.HOME, '.m2', 'repository', 'dk', 'au', 'ece', 'vdmj') + local repo = vim.env.HOME .. '/.m2/repository/dk/au/ece/vdmj' if vim.loop.fs_stat(repo) then return repo else - return util.path.join(vim.env.HOME, '.m2', 'repository', 'com', 'fujitsu') + return vim.env.HOME .. '/.m2/repository/com/fujitsu' end end local function get_jar_path(config, package, version) - return util.path.join(config.options.mavenrepo, package, version, package .. '-' .. version .. '.jar') + return table.concat({ config.options.mavenrepo, package, version, package .. '-' .. version .. '.jar' }, '/') end local function with_precision(version, is_high_precision) @@ -18,11 +18,11 @@ local function with_precision(version, is_high_precision) end local function get_latest_installed_version(repo) - local path = util.path.join(repo, 'lsp') + local path = repo .. '/lsp' local sort = vim.fn.sort local subdirs = function(file) - local stat = vim.loop.fs_stat(util.path.join(path, file)) + local stat = vim.loop.fs_stat(table.concat({ path, file }, '/')) return stat.type == 'directory' and 1 or 0 end @@ -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 vim.fn.isdirectory(util.path.join(path, '.vscode')) == 1 then + if vim.fn.isdirectory(path .. '/.vscode') == 1 then return path end end) @@ -48,11 +48,11 @@ return { return vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1]) or find_vscode_ancestor(fname) end, options = { - java = vim.env.JAVA_HOME and util.path.join(vim.env.JAVA_HOME, 'bin', 'java') or 'java', + java = vim.env.JAVA_HOME and (vim.env.JAVA_HOME .. '/bin/java') or 'java', java_opts = { '-Xmx3000m', '-Xss1m' }, annotation_paths = {}, mavenrepo = get_default_mavenrepo(), - logfile = util.path.join(vim.fn.stdpath 'cache', 'vdm-lsp.log'), + logfile = vim.fn.stdpath('cache') .. '/vdm-lsp.log', debugger_port = -1, high_precision = false, }, @@ -90,7 +90,7 @@ by neovim. get_jar_path(config, 'vdmj', version), get_jar_path(config, 'annotations', version), get_jar_path(config, 'lsp', version), - util.path.join(root_dir, '.vscode'), + root_dir .. '/.vscode', unpack(config.options.annotation_paths), }, ':') diff --git a/lua/lspconfig/configs/volar.lua b/lua/lspconfig/configs/volar.lua index 529d851c92..1eb0ba3df5 100644 --- a/lua/lspconfig/configs/volar.lua +++ b/lua/lspconfig/configs/volar.lua @@ -2,7 +2,7 @@ local util = require 'lspconfig.util' local function get_typescript_server_path(root_dir) local project_root = vim.fs.find('node_modules', { path = root_dir, upward = true })[1] - return project_root and (util.path.join(project_root, 'typescript', 'lib')) or '' + return project_root and (project_root .. '/typescript/lib') or '' end -- https://github.com/vuejs/language-tools/blob/master/packages/language-server/lib/types.ts 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]) diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 6b73cba621..aac10d0513 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -178,7 +178,7 @@ local function make_lsp_sections() end end, function() - local package_json_name = util.path.join(tempdir, config_name .. '.package.json') + local package_json_name = table.concat({ tempdir, config_name .. '.package.json' }, '/') if docs.package_json then if not ((vim.loop.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)) diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 5ce98ea1a5..c4d75ed6db 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -9,16 +9,6 @@ describe('lspconfig', function() end) describe('util', function() - describe('path', function() - describe('join', function() - it('', function() - local lspconfig = require 'lspconfig' - local res = lspconfig.util.path.join('foo', 'bar', 'baz') - eq('foo/bar/baz', res) - end) - end) - end) - describe('root_pattern', function() it('resolves to a_marker.txt', function() local lspconfig = require 'lspconfig'