mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 11:20:07 -04:00
Add TSUpdate command to update parsers
This commit is contained in:
parent
a855538e0a
commit
a872762d82
4 changed files with 43 additions and 4 deletions
|
|
@ -127,6 +127,11 @@ You can use |:TSInstall| `all` to install all parsers.
|
||||||
:TSInstallInfo~
|
:TSInstallInfo~
|
||||||
|
|
||||||
List informations about currently installed parsers
|
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*
|
||||||
:TSBufEnable {module}~
|
:TSBufEnable {module}~
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,16 @@ local function module_info(mod)
|
||||||
end
|
end
|
||||||
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 = {
|
M.commands = {
|
||||||
TSInstallInfo = {
|
TSInstallInfo = {
|
||||||
run = install_info,
|
run = install_info,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ local luv = vim.loop
|
||||||
|
|
||||||
local utils = require'nvim-treesitter.utils'
|
local utils = require'nvim-treesitter.utils'
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
local parsers = require'nvim-treesitter.parsers'
|
||||||
|
local info = require'nvim-treesitter.info'
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
@ -122,11 +123,13 @@ end
|
||||||
|
|
||||||
local function install_lang(lang, ask_reinstall, cache_folder, package_path, with_sync)
|
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 #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: ')
|
local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ')
|
||||||
print('\n ') -- mandatory to avoid messing up command line
|
print('\n ') -- mandatory to avoid messing up command line
|
||||||
if not string.match(yesno, '^y.*') then return end
|
if not string.match(yesno, '^y.*') then return end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local parser_config = parsers.get_parser_configs()[lang]
|
local parser_config = parsers.get_parser_configs()[lang]
|
||||||
|
|
@ -176,6 +179,17 @@ local function install(with_sync, ask_reinstall)
|
||||||
end
|
end
|
||||||
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.ensure_installed = install(false, false)
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
|
|
@ -192,6 +206,13 @@ M.commands = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
"-complete=custom,v:lua.ts_installable_parsers"
|
"-complete=custom,v:lua.ts_installable_parsers"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TSUpdate = {
|
||||||
|
run = M.update,
|
||||||
|
args = {
|
||||||
|
"-nargs=*",
|
||||||
|
"-complete=custom,v:lua.ts_installed_parsers"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ lua << EOF
|
||||||
ts_installable_parsers = function()
|
ts_installable_parsers = function()
|
||||||
return table.concat(require'nvim-treesitter.parsers'.available_parsers(), '\n')
|
return table.concat(require'nvim-treesitter.parsers'.available_parsers(), '\n')
|
||||||
end
|
end
|
||||||
|
ts_installed_parsers = function()
|
||||||
|
return table.concat(require'nvim-treesitter.info'.installed_parsers(), '\n')
|
||||||
|
end
|
||||||
ts_available_modules = function()
|
ts_available_modules = function()
|
||||||
return table.concat(require'nvim-treesitter.configs'.available_modules(), '\n')
|
return table.concat(require'nvim-treesitter.configs'.available_modules(), '\n')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue