summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/install.lua
diff options
context:
space:
mode:
authorFlorian Beeres <yuuki@protonmail.com>2020-09-18 09:44:07 +0200
committerGitHub <noreply@github.com>2020-09-18 09:44:07 +0200
commit18adc9e17661c6ff690598e3f6e0f34708353dd3 (patch)
tree30a376555f4e324aafc9072f81f4803af889beab /lua/nvim-treesitter/install.lua
parentb2e1ea1edf2cb42d20a941595cd0b4fcb871a0b5 (diff)
Make :TSInstall work in Nix by adding a second module installation target (#473)
* Ignore tags file in project root * Make :TSInstall work with Nix This commit adds logic to determine where to install parsers, meaning the *.so files. Until now the package path of the nvim-treesitter plugin was used. But when installed with Nix, the plugin lands in "/nix/store", which is read-only. With this commit $XDG_DATA_HOME/nvim/site/parser/*.go will be used as the parser installation path. The directory will be created if it doesn't exist. * Add generate_join function The generate_join function is used to create two other functions, one to join path segments, the other to join strings with a space for error messages.
Diffstat (limited to 'lua/nvim-treesitter/install.lua')
-rw-r--r--lua/nvim-treesitter/install.lua25
1 files changed, 13 insertions, 12 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 0d2d7481..4c52fd41 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -117,18 +117,15 @@ local function select_mv_cmd(compile_location, parser_lib_name)
end
end
-local function run_install(cache_folder, package_path, lang, repo, with_sync)
+local function run_install(cache_folder, install_folder, lang, repo, with_sync)
parsers.reset_cache()
- local path_sep = '/'
- if fn.has('win32') == 1 then
- path_sep = '\\'
- end
+ local path_sep = utils.get_path_sep()
local project_name = 'tree-sitter-'..lang
-- compile_location only needed for typescript installs.
local compile_location = cache_folder..path_sep..(repo.location or project_name)
- local parser_lib_name = package_path..path_sep.."parser"..path_sep..lang..".so"
+ local parser_lib_name = install_folder..path_sep..lang..".so"
local compilers = { "cc", "gcc", "clang" }
local cc = select_executable(compilers)
@@ -170,7 +167,7 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
end
end
-local function install_lang(lang, ask_reinstall, cache_folder, package_path, with_sync)
+local function install_lang(lang, ask_reinstall, cache_folder, install_folder, with_sync)
if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then
if ask_reinstall ~= 'force' then
if not ask_reinstall then return end
@@ -192,7 +189,7 @@ local function install_lang(lang, ask_reinstall, cache_folder, package_path, wit
files={ install_info.files, 'table' }
}
- run_install(cache_folder, package_path, lang, install_info, with_sync)
+ run_install(cache_folder, install_folder, lang, install_info, with_sync)
end
local function install(with_sync, ask_reinstall)
@@ -202,10 +199,12 @@ local function install(with_sync, ask_reinstall)
return api.nvim_err_writeln('Git is required on your system to run this command')
end
- local package_path = utils.get_package_path()
local cache_folder, err = utils.get_cache_dir()
if err then return api.nvim_err_writeln(err) end
+ local install_folder, err = utils.get_parser_install_dir()
+ if err then return api.nvim_err_writeln(err) end
+
local languages
local ask
if ... == 'all' then
@@ -217,7 +216,7 @@ local function install(with_sync, ask_reinstall)
end
for _, lang in ipairs(languages) do
- install_lang(lang, ask, cache_folder, package_path, with_sync)
+ install_lang(lang, ask, cache_folder, install_folder, with_sync)
end
end
end
@@ -267,8 +266,10 @@ function M.uninstall(lang)
M.uninstall(lang)
end
elseif lang then
- local package_path = utils.get_package_path()
- local parser_lib = package_path..path_sep.."parser"..path_sep..lang..".so"
+ local install_dir, err = utils.get_parser_install_dir()
+ if err then return api.nvim_err_writeln(err) end
+
+ local parser_lib = install_dir..path_sep..lang..".so"
local command_list = {
select_uninstall_rm_cmd(lang, parser_lib)