diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2020-04-30 22:11:44 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2020-05-01 10:09:48 +0200 |
| commit | 6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee (patch) | |
| tree | c041881f414bb1172199257872f79d4f51498d0f /lua | |
| parent | Merge pull request #33 from kyazdani42/doc/add-documentation (diff) | |
| download | nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar.gz nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar.bz2 nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar.lz nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar.xz nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.tar.zst nvim-treesitter-6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee.zip | |
Add function 'nvim-treesitter/install'.ensure_installed
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index ca84ac036..298a0e9f7 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, |
