Add function 'nvim-treesitter/install'.ensure_installed

This commit is contained in:
Stephan Seitz 2020-04-30 22:11:44 +02:00
parent 5532019122
commit 6b2d76153f

View file

@ -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,