mirror of
https://github.com/chenasraf/nvim-treesitter.git
synced 2026-05-17 17:38:02 +00:00
refactor: use vim.fs.joinpath
This commit is contained in:
2
.github/workflows/update-lockfile.yml
vendored
2
.github/workflows/update-lockfile.yml
vendored
@@ -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
|
||||
|
||||
2
.github/workflows/update-readme.yml
vendored
2
.github/workflows/update-readme.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
|
||||
- name: Prepare
|
||||
env:
|
||||
NVIM_TAG: stable
|
||||
NVIM_TAG: nightly
|
||||
run: |
|
||||
bash ./scripts/ci-install.sh
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user