mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 03:10:04 -04:00
refactor: use vim.fs.joinpath
This commit is contained in:
parent
fdafc019bb
commit
52976802a5
7 changed files with 28 additions and 39 deletions
2
.github/workflows/update-lockfile.yml
vendored
2
.github/workflows/update-lockfile.yml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
|
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
env:
|
env:
|
||||||
NVIM_TAG: stable
|
NVIM_TAG: nightly
|
||||||
run: |
|
run: |
|
||||||
wget https://github.com/josephburnett/jd/releases/download/v1.7.1/jd-amd64-linux
|
wget https://github.com/josephburnett/jd/releases/download/v1.7.1/jd-amd64-linux
|
||||||
mv jd-amd64-linux /tmp/jd
|
mv jd-amd64-linux /tmp/jd
|
||||||
|
|
|
||||||
2
.github/workflows/update-readme.yml
vendored
2
.github/workflows/update-readme.yml
vendored
|
|
@ -15,7 +15,7 @@ jobs:
|
||||||
|
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
env:
|
env:
|
||||||
NVIM_TAG: stable
|
NVIM_TAG: nightly
|
||||||
run: |
|
run: |
|
||||||
bash ./scripts/ci-install-ubuntu-latest.sh
|
bash ./scripts/ci-install-ubuntu-latest.sh
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
local utils = require('nvim-treesitter.utils')
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class TSConfig
|
---@class TSConfig
|
||||||
|
|
@ -15,7 +13,7 @@ local config = {
|
||||||
auto_install = false,
|
auto_install = false,
|
||||||
ensure_install = {},
|
ensure_install = {},
|
||||||
ignore_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.
|
---Setup call for users to override configuration configurations.
|
||||||
|
|
@ -62,7 +60,7 @@ end
|
||||||
---@param dir_name string
|
---@param dir_name string
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_install_dir(dir_name)
|
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
|
if not vim.loop.fs_stat(dir) then
|
||||||
local ok, error = pcall(vim.fn.mkdir, dir, 'p', '0755')
|
local ok, error = pcall(vim.fn.mkdir, dir, 'p', '0755')
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
local fs = vim.fs
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
local utils = require('nvim-treesitter.utils')
|
|
||||||
local parsers = require('nvim-treesitter.parsers')
|
local parsers = require('nvim-treesitter.parsers')
|
||||||
local config = require('nvim-treesitter.config')
|
local config = require('nvim-treesitter.config')
|
||||||
local shell = require('nvim-treesitter.shell_cmds')
|
local shell = require('nvim-treesitter.shell_cmds')
|
||||||
|
|
@ -208,7 +208,7 @@ end
|
||||||
---@return string|nil
|
---@return string|nil
|
||||||
local function get_revision(lang)
|
local function get_revision(lang)
|
||||||
if #lockfile == 0 then
|
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'))
|
local file = assert(io.open(filename, 'r'))
|
||||||
lockfile = vim.json.decode(file:read('*all'))
|
lockfile = vim.json.decode(file:read('*all'))
|
||||||
file:close()
|
file:close()
|
||||||
|
|
@ -227,7 +227,7 @@ end
|
||||||
---@param lang string
|
---@param lang string
|
||||||
---@return string|nil
|
---@return string|nil
|
||||||
local function get_installed_revision(lang)
|
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 file = assert(io.open(lang_file, 'r'))
|
||||||
local revision = file:read('*a')
|
local revision = file:read('*a')
|
||||||
file:close()
|
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 repo = get_parser_install_info(lang)
|
||||||
|
|
||||||
local project_name = 'tree-sitter-' .. 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
|
local from_local_path = vim.fn.isdirectory(maybe_local_path) == 1
|
||||||
if from_local_path then
|
if from_local_path then
|
||||||
repo.url = maybe_local_path
|
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
|
if from_local_path then
|
||||||
compile_location = repo.url
|
compile_location = repo.url
|
||||||
if repo.location then
|
if repo.location then
|
||||||
compile_location = utils.join_path(compile_location, repo.location)
|
compile_location = fs.joinpath(compile_location, repo.location)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local repo_location = project_name
|
local repo_location = project_name
|
||||||
if repo.location then
|
if repo.location then
|
||||||
repo_location = utils.join_path(repo_location, repo.location)
|
repo_location = fs.joinpath(repo_location, repo.location)
|
||||||
end
|
end
|
||||||
compile_location = utils.join_path(cache_dir, repo_location)
|
compile_location = fs.joinpath(cache_dir, repo_location)
|
||||||
end
|
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
|
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, {
|
vim.list_extend(command_list, {
|
||||||
{
|
{
|
||||||
cmd = function()
|
cmd = function()
|
||||||
vim.fn.delete(utils.join_path(cache_dir, project_name), 'rf')
|
vim.fn.delete(fs.joinpath(cache_dir, project_name), 'rf')
|
||||||
end,
|
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),
|
shell.select_compile_command(repo, cc, compile_location),
|
||||||
{
|
{
|
||||||
cmd = function()
|
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,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cmd = function()
|
cmd = function()
|
||||||
local file = assert(
|
local file = assert(
|
||||||
io.open(
|
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'
|
'w'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -435,7 +435,7 @@ local function install_lang(lang, cache_dir, install_dir, force, with_sync, gene
|
||||||
vim.list_extend(command_list, {
|
vim.list_extend(command_list, {
|
||||||
{
|
{
|
||||||
cmd = function()
|
cmd = function()
|
||||||
vim.fn.delete(utils.join_path(cache_dir, project_name), 'rf')
|
vim.fn.delete(fs.joinpath(cache_dir, project_name), 'rf')
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -485,8 +485,8 @@ function M.install(languages, options)
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
install_lang(lang, cache_dir, install_dir, force, with_sync, generate_from_grammar)
|
install_lang(lang, cache_dir, install_dir, force, with_sync, generate_from_grammar)
|
||||||
uv.fs_symlink(
|
uv.fs_symlink(
|
||||||
utils.get_package_path('runtime', 'queries', lang),
|
shell.get_package_path('runtime', 'queries', lang),
|
||||||
utils.join_path(config.get_install_dir('queries'), lang),
|
fs.joinpath(config.get_install_dir('queries'), lang),
|
||||||
{ dir = true, junction = true } -- needed on Windows (non-junction links require admin)
|
{ dir = true, junction = true } -- needed on Windows (non-junction links require admin)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -555,8 +555,8 @@ function M.uninstall(languages)
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
local parser = utils.join_path(parser_dir, lang) .. '.so'
|
local parser = fs.joinpath(parser_dir, lang) .. '.so'
|
||||||
local queries = utils.join_path(query_dir, lang)
|
local queries = fs.joinpath(query_dir, lang)
|
||||||
uninstall(lang, parser, queries)
|
uninstall(lang, parser, queries)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
local utils = require('nvim-treesitter.utils')
|
|
||||||
|
|
||||||
local iswin = uv.os_uname().sysname == 'Windows_NT'
|
local iswin = uv.os_uname().sysname == 'Windows_NT'
|
||||||
|
|
||||||
|
|
@ -90,7 +89,7 @@ function M.select_compile_command(repo, cc, compile_location)
|
||||||
err = 'Error during compilation',
|
err = 'Error during compilation',
|
||||||
opts = {
|
opts = {
|
||||||
args = {
|
args = {
|
||||||
'--makefile=' .. utils.get_package_path('scripts', 'compile_parsers.makefile'),
|
'--makefile=' .. M.get_package_path('scripts', 'compile_parsers.makefile'),
|
||||||
'CC=' .. cc,
|
'CC=' .. cc,
|
||||||
},
|
},
|
||||||
cwd = compile_location,
|
cwd = compile_location,
|
||||||
|
|
@ -109,7 +108,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 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_github = repo.url:find('github.com', 1, true)
|
||||||
local is_gitlab = repo.url:find('gitlab.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'
|
revision = revision or repo.branch or 'master'
|
||||||
|
|
||||||
|
|
@ -182,7 +181,7 @@ function M.select_download_commands(repo, project_name, cache_dir, revision, pre
|
||||||
{
|
{
|
||||||
cmd = function()
|
cmd = function()
|
||||||
uv.fs_rename(
|
uv.fs_rename(
|
||||||
utils.join_path(temp_dir, url:match('[^/]-$') .. '-' .. dir_rev),
|
vim.fs.joinpath(temp_dir, url:match('[^/]-$') .. '-' .. dir_rev),
|
||||||
project_dir
|
project_dir
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
|
|
@ -227,6 +226,10 @@ function M.select_download_commands(repo, project_name, cache_dir, revision, pre
|
||||||
end
|
end
|
||||||
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?
|
--TODO(clason): only needed for iter_cmd_sync -> replace with uv.spawn?
|
||||||
|
|
||||||
-- Convert path for cmd.exe on Windows (needed when shellslash is set)
|
-- 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('.')
|
vim.opt.runtimepath:append('.')
|
||||||
|
|
||||||
-- Load previous lockfile
|
-- 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 file = assert(io.open(filename, 'r'))
|
||||||
local lockfile = vim.json.decode(file:read('*a'))
|
local lockfile = vim.json.decode(file:read('*a'))
|
||||||
file:close()
|
file:close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue