diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2020-07-31 20:27:06 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2020-08-02 22:58:08 +0200 |
| commit | a872762d8240d9f81402b69fa7f20d1c1bbda919 (patch) | |
| tree | 4276823cdbc75cc7d80957e9013ba29b1737d114 /lua | |
| parent | fix decremental selection (diff) | |
| download | nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar.gz nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar.bz2 nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar.lz nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar.xz nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.tar.zst nvim-treesitter-a872762d8240d9f81402b69fa7f20d1c1bbda919.zip | |
Add TSUpdate command to update parsers
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/info.lua | 10 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 29 |
2 files changed, 35 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/info.lua b/lua/nvim-treesitter/info.lua index 98b759518..092c7c8c1 100644 --- a/lua/nvim-treesitter/info.lua +++ b/lua/nvim-treesitter/info.lua @@ -76,6 +76,16 @@ local function module_info(mod) end end +function M.installed_parsers() + local installed = {} + for _, p in pairs(parsers.available_parsers()) do + if parsers.has_parser(p) then + table.insert(installed, p) + end + end + return installed +end + M.commands = { TSInstallInfo = { run = install_info, diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 4a957864e..a8c79d52d 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -4,6 +4,7 @@ local luv = vim.loop local utils = require'nvim-treesitter.utils' local parsers = require'nvim-treesitter.parsers' +local info = require'nvim-treesitter.info' local M = {} @@ -122,11 +123,13 @@ end local function install_lang(lang, ask_reinstall, cache_folder, package_path, with_sync) if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then - if not ask_reinstall then return end + if ask_reinstall ~= 'force' then + if not ask_reinstall then return end - local yesno = fn.input(lang .. ' 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 + local yesno = fn.input(lang .. ' 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 end local parser_config = parsers.get_parser_configs()[lang] @@ -176,6 +179,17 @@ local function install(with_sync, ask_reinstall) end end +function M.update(lang) + if lang then + install(false, 'force')(lang) + else + local installed = info.installed_parsers() + for _, lang in pairs(installed) do + install(false, 'force')(lang) + end + end +end + M.ensure_installed = install(false, false) M.commands = { @@ -192,6 +206,13 @@ M.commands = { "-nargs=+", "-complete=custom,v:lua.ts_installable_parsers" } + }, + TSUpdate = { + run = M.update, + args = { + "-nargs=*", + "-complete=custom,v:lua.ts_installed_parsers" + } } } |
