From 6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Thu, 30 Apr 2020 22:11:44 +0200 Subject: Add function 'nvim-treesitter/install'.ensure_installed --- lua/nvim-treesitter/install.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index ca84ac03..298a0e9f 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -3,6 +3,7 @@ local fn = vim.fn local luv = vim.loop local configs = require'nvim-treesitter/configs' local parsers = configs.get_parser_configs() +local has_parser = require'nvim-treesitter/parsers'.has_parser local M = {} @@ -143,6 +144,24 @@ local function install(ft) run_install(cache_folder, package_path, ft, install_info) end + +M.ensure_installed = function(languages) + if type(languages) == 'string' then + if languages == 'all' then + languages = configs.available_parsers() + else + languages = {languages} + end + end + + for _, ft in ipairs(languages) do + if not has_parser(ft) then + install(ft) + end + end +end + + M.commands = { TSInstall = { run = install, -- cgit v1.2.3 From 0b4cdba3e49d77d5914af38e29c46229d9cd059a Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Fri, 1 May 2020 10:30:25 +0200 Subject: Avoid global handle to enable installing multiple parsers in parallel --- lua/nvim-treesitter/install.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 298a0e9f..77e0fccc 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -40,9 +40,11 @@ local function iter_cmd(cmd_list, i, ft) local attr = cmd_list[i] if attr.info then print(attr.info) end + local handle + handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) handle:close() - if code ~= 0 then return api.nvim_err_writeln(attr.err) end + if code ~= 0 then return api.nvim_err_writeln(attr.err) end iter_cmd(cmd_list, i + 1, ft) end)) end -- cgit v1.2.3