aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-05-20 17:38:33 +0200
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit5aa2984a028731bf60d53a7f9773997dfc84e4f7 (patch)
treefad9ce8fac1e6571722e419f99f4aa4f82d9b834
parentfeat!: drop luarocks release (diff)
downloadnvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar.gz
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar.bz2
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar.lz
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar.xz
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.tar.zst
nvim-treesitter-5aa2984a028731bf60d53a7f9773997dfc84e4f7.zip
refactor: use vim.fs.joinpath
-rw-r--r--.github/workflows/update-lockfile.yml2
-rw-r--r--.github/workflows/update-readme.yml2
-rw-r--r--lua/nvim-treesitter/config.lua6
-rw-r--r--lua/nvim-treesitter/install.lua32
-rw-r--r--lua/nvim-treesitter/shell_cmds.lua11
-rw-r--r--lua/nvim-treesitter/utils.lua12
-rwxr-xr-xscripts/write-lockfile.lua2
7 files changed, 28 insertions, 39 deletions
diff --git a/.github/workflows/update-lockfile.yml b/.github/workflows/update-lockfile.yml
index df0f61347..992e1c0d2 100644
--- a/.github/workflows/update-lockfile.yml
+++ b/.github/workflows/update-lockfile.yml
@@ -22,7 +22,7 @@ jobs:
- name: Prepare
env:
- NVIM_TAG: stable
+ NVIM_TAG: nightly
run: |
wget https://github.com/josephburnett/jd/releases/download/v1.7.1/jd-amd64-linux
mv jd-amd64-linux /tmp/jd
diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml
index de416a873..557a3f3c6 100644
--- a/.github/workflows/update-readme.yml
+++ b/.github/workflows/update-readme.yml
@@ -21,7 +21,7 @@ jobs:
- name: Prepare
env:
- NVIM_TAG: stable
+ NVIM_TAG: nightly
run: |
bash ./scripts/ci-install.sh
diff --git a/lua/nvim-treesitter/config.lua b/lua/nvim-treesitter/config.lua
index e43ad13c2..01880a8bc 100644
--- a/lua/nvim-treesitter/config.lua
+++ b/lua/nvim-treesitter/config.lua
@@ -1,5 +1,3 @@
-local utils = require('nvim-treesitter.utils')
-
local M = {}
---@class TSConfig
@@ -15,7 +13,7 @@ local config = {
auto_install = false,
ensure_install = {},
ignore_install = {},
- install_dir = utils.join_path(vim.fn.stdpath('data'), 'site'),
+ install_dir = vim.fs.joinpath(vim.fn.stdpath('data'), 'site'),
}
---Setup call for users to override configuration configurations.
@@ -62,7 +60,7 @@ end
---@param dir_name string
---@return string
function M.get_install_dir(dir_name)
- local dir = utils.join_path(config.install_dir, dir_name)
+ local dir = vim.fs.joinpath(config.install_dir, dir_name)
if not vim.loop.fs_stat(dir) then
local ok, error = pcall(vim.fn.mkdir, dir, 'p', '0755')
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 745c2dd1f..0db61137c 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -1,7 +1,7 @@
local api = vim.api
+local fs = vim.fs
local uv = vim.loop
-local utils = require('nvim-treesitter.utils')
local parsers = require('nvim-treesitter.parsers')
local config = require('nvim-treesitter.config')
local shell = require('nvim-treesitter.shell_cmds')
@@ -208,7 +208,7 @@ end
---@return string|nil
local function get_revision(lang)
if #lockfile == 0 then
- local filename = utils.get_package_path('lockfile.json')
+ local filename = shell.get_package_path('lockfile.json')
local file = assert(io.open(filename, 'r'))
lockfile = vim.json.decode(file:read('*all'))
file:close()
@@ -227,7 +227,7 @@ end
---@param lang string
---@return string|nil
local function get_installed_revision(lang)
- local lang_file = utils.join_path(config.get_install_dir('parser-info'), lang .. '.revision')
+ local lang_file = fs.joinpath(config.get_install_dir('parser-info'), lang .. '.revision')
local file = assert(io.open(lang_file, 'r'))
local revision = file:read('*a')
file:close()
@@ -291,7 +291,7 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
local repo = get_parser_install_info(lang)
local project_name = 'tree-sitter-' .. lang
- local maybe_local_path = vim.fs.normalize(repo.url)
+ local maybe_local_path = fs.normalize(repo.url)
local from_local_path = vim.fn.isdirectory(maybe_local_path) == 1
if from_local_path then
repo.url = maybe_local_path
@@ -302,16 +302,16 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
if from_local_path then
compile_location = repo.url
if repo.location then
- compile_location = utils.join_path(compile_location, repo.location)
+ compile_location = fs.joinpath(compile_location, repo.location)
end
else
local repo_location = project_name
if repo.location then
- repo_location = utils.join_path(repo_location, repo.location)
+ repo_location = fs.joinpath(repo_location, repo.location)
end
- compile_location = utils.join_path(cache_dir, repo_location)
+ compile_location = fs.joinpath(cache_dir, repo_location)
end
- local parser_lib_name = utils.join_path(install_dir, lang) .. '.so'
+ local parser_lib_name = fs.joinpath(install_dir, lang) .. '.so'
generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar
@@ -370,7 +370,7 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
vim.list_extend(command_list, {
{
cmd = function()
- vim.fn.delete(utils.join_path(cache_dir, project_name), 'rf')
+ vim.fn.delete(fs.joinpath(cache_dir, project_name), 'rf')
end,
},
})
@@ -415,14 +415,14 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
shell.select_compile_command(repo, cc, compile_location),
{
cmd = function()
- uv.fs_copyfile(utils.join_path(compile_location, 'parser.so'), parser_lib_name)
+ uv.fs_copyfile(fs.joinpath(compile_location, 'parser.so'), parser_lib_name)
end,
},
{
cmd = function()
local file = assert(
io.open(
- utils.join_path(config.get_install_dir('parser-info') or '', lang .. '.revision'),
+ fs.joinpath(config.get_install_dir('parser-info') or '', lang .. '.revision'),
'w'
)
)
@@ -435,7 +435,7 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
vim.list_extend(command_list, {
{
cmd = function()
- vim.fn.delete(utils.join_path(cache_dir, project_name), 'rf')
+ vim.fn.delete(fs.joinpath(cache_dir, project_name), 'rf')
end,
},
})
@@ -485,8 +485,8 @@ function M.install(languages, options)
for _, lang in ipairs(languages) do
install_lang(lang, cache_dir, install_dir, force, with_sync, generate_from_grammar)
uv.fs_symlink(
- utils.get_package_path('runtime', 'queries', lang),
- utils.join_path(config.get_install_dir('queries'), lang),
+ shell.get_package_path('runtime', 'queries', lang),
+ fs.joinpath(config.get_install_dir('queries'), lang),
{ dir = true, junction = true } -- needed on Windows (non-junction links require admin)
)
end
@@ -555,8 +555,8 @@ function M.uninstall(languages)
vim.log.levels.ERROR
)
else
- local parser = utils.join_path(parser_dir, lang) .. '.so'
- local queries = utils.join_path(query_dir, lang)
+ local parser = fs.joinpath(parser_dir, lang) .. '.so'
+ local queries = fs.joinpath(query_dir, lang)
uninstall(lang, parser, queries)
end
end
diff --git a/lua/nvim-treesitter/shell_cmds.lua b/lua/nvim-treesitter/shell_cmds.lua
index 2dc7f8748..4c631512d 100644
--- a/lua/nvim-treesitter/shell_cmds.lua
+++ b/lua/nvim-treesitter/shell_cmds.lua
@@ -1,5 +1,4 @@
local uv = vim.loop
-local utils = require('nvim-treesitter.utils')
local iswin = uv.os_uname().sysname == 'Windows_NT'
@@ -91,7 +90,7 @@ function M.select_compile_command(repo, cc, compile_location)
err = 'Error during compilation',
opts = {
args = {
- '--makefile=' .. utils.get_package_path('scripts', 'compile_parsers.makefile'),
+ '--makefile=' .. M.get_package_path('scripts', 'compile_parsers.makefile'),
'CC=' .. cc,
},
cwd = compile_location,
@@ -110,7 +109,7 @@ function M.select_download_commands(repo, project_name, cache_dir, revision, pre
local can_use_tar = vim.fn.executable('tar') == 1 and vim.fn.executable('curl') == 1
local is_github = repo.url:find('github.com', 1, true)
local is_gitlab = repo.url:find('gitlab.com', 1, true)
- local project_dir = utils.join_path(cache_dir, project_name)
+ local project_dir = vim.fs.joinpath(cache_dir, project_name)
revision = revision or repo.branch or 'master'
@@ -183,7 +182,7 @@ function M.select_download_commands(repo, project_name, cache_dir, revision, pre
{
cmd = function()
uv.fs_rename(
- utils.join_path(temp_dir, url:match('[^/]-$') .. '-' .. dir_rev),
+ vim.fs.joinpath(temp_dir, url:match('[^/]-$') .. '-' .. dir_rev),
project_dir
)
end,
@@ -228,6 +227,10 @@ function M.select_download_commands(repo, project_name, cache_dir, revision, pre
end
end
+function M.get_package_path(...)
+ return vim.fs.joinpath(vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h:h:h'), ...)
+end
+
--TODO(clason): only needed for iter_cmd_sync -> replace with uv.spawn?
-- Convert path for cmd.exe on Windows (needed when shellslash is set)
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua
deleted file mode 100644
index f9e5a2b86..000000000
--- a/lua/nvim-treesitter/utils.lua
+++ /dev/null
@@ -1,12 +0,0 @@
-local M = {}
-
---TODO(clason): replace by vim.fs._join_paths
-function M.join_path(...)
- return (table.concat({ ... }, '/'):gsub('//+', '/'))
-end
-
-function M.get_package_path(...)
- return M.join_path(vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h:h:h'), ...)
-end
-
-return M
diff --git a/scripts/write-lockfile.lua b/scripts/write-lockfile.lua
index a264af83c..5dac838d6 100755
--- a/scripts/write-lockfile.lua
+++ b/scripts/write-lockfile.lua
@@ -2,7 +2,7 @@
vim.opt.runtimepath:append('.')
-- Load previous lockfile
-local filename = require('nvim-treesitter.utils').get_package_path('lockfile.json')
+local filename = require('nvim-treesitter.shell_cmds').get_package_path('lockfile.json')
local file = assert(io.open(filename, 'r'))
local lockfile = vim.json.decode(file:read('*a'))
file:close()