mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-05 21:10:15 -04:00
Merge pull request #34 from theHamsta/ensure_installed
Add function 'nvim-treesitter/install'.ensure_installed
This commit is contained in:
commit
1d6ad9b560
2 changed files with 25 additions and 1 deletions
|
|
@ -325,6 +325,9 @@ function M.setup(user_data)
|
|||
if config[mod].keymaps and type(data.keymaps) == 'table' then
|
||||
config[mod].keymaps = data.keymaps
|
||||
end
|
||||
if mod == 'ensure_installed' then
|
||||
require'nvim-treesitter/install'.ensure_installed(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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 = {}
|
||||
|
||||
|
|
@ -39,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
|
||||
|
|
@ -143,6 +146,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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue