aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-05-15 17:15:20 +0200
committerThomas Vigouroux <tomvig38@gmail.com>2020-05-15 17:24:54 +0200
commit0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873 (patch)
tree28a8004e8258f2d5072349f97e847e595fdce478
parentMerge pull request #54 from kyazdani42/feat/expose-api (diff)
downloadnvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar.gz
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar.bz2
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar.lz
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar.xz
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.tar.zst
nvim-treesitter-0ab6bbec67b0bbb9fef197e72bd060f6f2d0f873.zip
install: allow installing multiple parsers at once
This allow commands like so : :TSInstall c rust lua python
-rw-r--r--lua/nvim-treesitter/install.lua46
1 files changed, 22 insertions, 24 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 45aec99ca..637f1dedb 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -80,32 +80,11 @@ local function run_install(cache_folder, package_path, ft, repo)
end
-- TODO(kyazdani): this should work on windows too
-local function install(ft)
+local function install(...)
if fn.has('win32') == 1 then
return api.nvim_err_writeln('This command is not available on windows at the moment.')
end
- if not ft then
- return api.nvim_err_writeln("Usage: install_parser('language')")
- end
-
- 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: ')
- print('\n ') -- mandatory to avoid messing up command line
- if not string.match(yesno, '^y.*') then return end
- end
-
- local parser_config = configs.get_parser_configs()[ft]
- if not parser_config then
- return api.nvim_err_writeln('Parser not available for language '..ft)
- end
-
- local install_info = parser_config.install_info
- vim.validate {
- url={ install_info.url, 'string' },
- 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
@@ -116,7 +95,26 @@ local function install(ft)
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)
+ for _, ft in ipairs({ ... }) do
+ if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then
+ local yesno = fn.input(ft .. ' parser already available: would you like to reinstall ? y/n: ')
+ print('\n ') -- mandatory to avoid messing up command line
+ if not string.match(yesno, '^y.*') then return end
+ end
+
+ local parser_config = configs.get_parser_configs()[ft]
+ if not parser_config then
+ return api.nvim_err_writeln('Parser not available for language '..ft)
+ end
+
+ local install_info = parser_config.install_info
+ vim.validate {
+ url={ install_info.url, 'string' },
+ files={ install_info.files, 'table' }
+ }
+
+ run_install(cache_folder, package_path, ft, install_info)
+ end
end
@@ -141,7 +139,7 @@ M.commands = {
TSInstall = {
run = install,
args = {
- "-nargs=1",
+ "-nargs=+",
"-complete=custom,v:lua.ts_installable_parsers"
},
description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so'