aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2020-08-25 20:00:47 +0200
committerStephan Seitz <stephan.lauf@yahoo.de>2020-08-27 22:20:30 +0200
commitce7efd34c688ae8d548cf384b215975ef3e6fd98 (patch)
treefbd42e849148a7a6a039ce18e9c539a2709f7407
parentfix(health): only check installed parsers (diff)
downloadnvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar.gz
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar.bz2
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar.lz
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar.xz
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.tar.zst
nvim-treesitter-ce7efd34c688ae8d548cf384b215975ef3e6fd98.zip
Add Windows support (mingw)
-rw-r--r--lua/nvim-treesitter/install.lua18
-rw-r--r--lua/nvim-treesitter/utils.lua17
2 files changed, 20 insertions, 15 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index eac4af7e0..9993cd8f7 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -58,6 +58,10 @@ local function iter_cmd_sync(cmd_list)
return true
end
+local function select_executable(executables)
+ return vim.tbl_filter(function(c) return fn.executable(c) == 1 end, executables)[1]
+end
+
local function run_install(cache_folder, package_path, lang, repo, with_sync)
parsers.reset_cache()
@@ -66,6 +70,14 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
-- compile_location only needed for typescript installs.
local compile_location = cache_folder..'/'..(repo.location or project_name)
local parser_lib_name = package_path.."/parser/"..lang..".so"
+
+ local compilers = { "cc", "gcc", "clang" }
+ local cc = select_executable(compilers)
+ if not cc then
+ api.nvim_err_writeln('No C compiler found! "'..table.concat(compilers, '", "')..'" are not executable.')
+ return
+ end
+
local command_list = {
{
cmd = 'rm',
@@ -83,7 +95,7 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
},
},
{
- cmd = 'cc',
+ cmd = cc,
info = 'Compiling...',
err = 'Error during compilation',
opts = {
@@ -148,12 +160,8 @@ local function install_lang(lang, ask_reinstall, cache_folder, package_path, wit
run_install(cache_folder, package_path, lang, install_info, with_sync)
end
--- TODO(kyazdani): this should work on windows too
local function install(with_sync, ask_reinstall)
return function (...)
- if fn.has('win32') == 1 then
- return api.nvim_err_writeln('This command is not available on windows at the moment.')
- end
if fn.executable('git') == 0 then
return api.nvim_err_writeln('Git is required on your system to run this command')
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua
index d3d183395..a39dd054a 100644
--- a/lua/nvim-treesitter/utils.lua
+++ b/lua/nvim-treesitter/utils.lua
@@ -19,7 +19,9 @@ end
function M.get_package_path()
for _, path in pairs(api.nvim_list_runtime_paths()) do
- if string.match(path, '.*/nvim%-treesitter') then
+ local last_segment = vim.fn.fnamemodify(path, ":t")
+ local penultimate_segment = vim.fn.fnamemodify(path, ":t:t")
+ if last_segment == "nvim-treesitter" or (last_segment == "" and penultimate_segment == "nvim-treesitter") then
return path
end
end
@@ -28,20 +30,15 @@ function M.get_package_path()
end
function M.get_cache_dir()
- local home = fn.get(fn.environ(), 'HOME')
- local xdg_cache = fn.get(fn.environ(), 'XDG_CACHE_HOME')
+ local cache_dir = fn.stdpath('data')
- if xdg_cache == 0 then
- xdg_cache = home .. '/.cache'
- end
-
- if luv.fs_access(xdg_cache, 'RW') then
- return xdg_cache
+ if luv.fs_access(cache_dir, 'RW') then
+ return cache_dir
elseif luv.fs_access('/tmp', 'RW') then
return '/tmp'
end
- return nil, 'Invalid cache rights, $XDG_CACHE_HOME or /tmp should be read/write'
+ return nil, 'Invalid cache rights, '..fn.stdpath('data')..' or /tmp should be read/write'
end
-- Gets a property at path