aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2020-07-31 20:27:06 +0200
committerStephan Seitz <stephan.lauf@yahoo.de>2020-08-02 22:58:08 +0200
commita872762d8240d9f81402b69fa7f20d1c1bbda919 (patch)
tree4276823cdbc75cc7d80957e9013ba29b1737d114
parentfix decremental selection (diff)
downloadnvim-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
-rw-r--r--doc/nvim-treesitter.txt5
-rw-r--r--lua/nvim-treesitter/info.lua10
-rw-r--r--lua/nvim-treesitter/install.lua29
-rw-r--r--plugin/nvim-treesitter.vim3
4 files changed, 43 insertions, 4 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index 1f455457a..5d32f217a 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -127,6 +127,11 @@ You can use |:TSInstall| `all` to install all parsers.
:TSInstallInfo~
List informations about currently installed parsers
+ *:TSUpdate*
+:TSUpdate {language}~
+
+Update the installed parser of {language} or all installed parsers
+if {language} is omitted.
*:TSBufEnable*
:TSBufEnable {module}~
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"
+ }
}
}
diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim
index 8486f12bd..f7b00d014 100644
--- a/plugin/nvim-treesitter.vim
+++ b/plugin/nvim-treesitter.vim
@@ -13,6 +13,9 @@ lua << EOF
ts_installable_parsers = function()
return table.concat(require'nvim-treesitter.parsers'.available_parsers(), '\n')
end
+ts_installed_parsers = function()
+ return table.concat(require'nvim-treesitter.info'.installed_parsers(), '\n')
+end
ts_available_modules = function()
return table.concat(require'nvim-treesitter.configs'.available_modules(), '\n')
end