Add TSUpdate command to update parsers

This commit is contained in:
Stephan Seitz 2020-07-31 20:27:06 +02:00 committed by Stephan Seitz
parent a855538e0a
commit a872762d82
4 changed files with 43 additions and 4 deletions

View file

@ -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}~

View file

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

View file

@ -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"
}
}
}

View file

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