install: allow installing multiple parsers at once

This allow commands like so :
  :TSInstall c rust lua python
This commit is contained in:
Thomas Vigouroux 2020-05-15 17:15:20 +02:00
parent 9c32111191
commit 0ab6bbec67
No known key found for this signature in database
GPG key ID: 88204BFB627E648D

View file

@ -80,17 +80,24 @@ local function run_install(cache_folder, package_path, ft, repo)
end end
-- TODO(kyazdani): this should work on windows too -- TODO(kyazdani): this should work on windows too
local function install(ft) local function install(...)
if fn.has('win32') == 1 then if fn.has('win32') == 1 then
return api.nvim_err_writeln('This command is not available on windows at the moment.') return api.nvim_err_writeln('This command is not available on windows at the moment.')
end end
if not ft then if fn.executable('git') == 0 then
return api.nvim_err_writeln("Usage: install_parser('language')") return api.nvim_err_writeln('Git is required on your system to run this command')
end end
local package_path, err = utils.get_package_path()
if err then return api.nvim_err_writeln(err) end
local cache_folder, err = utils.get_cache_dir()
if err then return api.nvim_err_writeln(err) end
for _, ft in ipairs({ ... }) do
if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then
local yesno = fn.input('Parser already available: would you like to reinstall ? y/n: ') local yesno = fn.input(ft .. ' parser already available: would you like to reinstall ? y/n: ')
print('\n ') -- mandatory to avoid messing up command line print('\n ') -- mandatory to avoid messing up command line
if not string.match(yesno, '^y.*') then return end if not string.match(yesno, '^y.*') then return end
end end
@ -106,18 +113,9 @@ local function install(ft)
files={ install_info.files, 'table' } files={ install_info.files, 'table' }
} }
if fn.executable('git') == 0 then
return api.nvim_err_writeln('Git is required on your system to run this command')
end
local package_path, err = utils.get_package_path()
if err then return api.nvim_err_writeln(err) end
local cache_folder, err = utils.get_cache_dir()
if err then return api.nvim_err_writeln(err) end
run_install(cache_folder, package_path, ft, install_info) run_install(cache_folder, package_path, ft, install_info)
end end
end
M.ensure_installed = function(languages) M.ensure_installed = function(languages)
@ -141,7 +139,7 @@ M.commands = {
TSInstall = { TSInstall = {
run = install, run = install,
args = { args = {
"-nargs=1", "-nargs=+",
"-complete=custom,v:lua.ts_installable_parsers" "-complete=custom,v:lua.ts_installable_parsers"
}, },
description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so' description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so'