mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-13 08:50:11 -04:00
TSUpdate does not install if up to date
This commit is contained in:
parent
b46580fb66
commit
76ea2b8871
4 changed files with 126 additions and 88 deletions
|
|
@ -184,10 +184,15 @@ Supported options:
|
||||||
COMMANDS *nvim-treesitter-commands*
|
COMMANDS *nvim-treesitter-commands*
|
||||||
|
|
||||||
*:TSInstall*
|
*:TSInstall*
|
||||||
:TSInstall| {language} ...~
|
:TSInstall {language} ...~
|
||||||
|
|
||||||
Install one or more treesitter parsers.
|
Install one or more treesitter parsers.
|
||||||
You can use |:TSInstall| `all` to install all parsers.
|
You can use |:TSInstall| `all` to install all parsers. Use |:TSInstall!| to
|
||||||
|
force the reinstallation of already installed parsers.
|
||||||
|
*:TSInstallSync*
|
||||||
|
:TSInstallSync {language} ...~
|
||||||
|
|
||||||
|
Perform the |:TSInstall| operation synchronously.
|
||||||
|
|
||||||
*:TSInstallInfo*
|
*:TSInstallInfo*
|
||||||
:TSInstallInfo~
|
:TSInstallInfo~
|
||||||
|
|
@ -195,10 +200,16 @@ You can use |:TSInstall| `all` to install all parsers.
|
||||||
List informations about currently installed parsers
|
List informations about currently installed parsers
|
||||||
|
|
||||||
*:TSUpdate*
|
*:TSUpdate*
|
||||||
:TSUpdate {language}~
|
:TSUpdate {language} ...~
|
||||||
|
|
||||||
Update the installed parser of {language} or all installed parsers
|
Update the installed parser for one more {language} or all installed parsers
|
||||||
if {language} is omitted.
|
if {language} is omitted. The specified parser is installed if it is not already
|
||||||
|
installed.
|
||||||
|
|
||||||
|
*:TSUpdateSync*
|
||||||
|
:TSUpdateSync {language} ...~
|
||||||
|
|
||||||
|
Perform the |:TSUpdate| operation synchronously.
|
||||||
|
|
||||||
*:TSUninstall*
|
*:TSUninstall*
|
||||||
:TSUninstall {language}~
|
:TSUninstall {language}~
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ function M.setup(user_data)
|
||||||
|
|
||||||
local ensure_installed = user_data.ensure_installed or {}
|
local ensure_installed = user_data.ensure_installed or {}
|
||||||
if #ensure_installed > 0 then
|
if #ensure_installed > 0 then
|
||||||
require'nvim-treesitter.install'.ensure_installed(ensure_installed)
|
require'nvim-treesitter.install'.ensure_installed('',ensure_installed)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.modules.ensure_installed = nil
|
config.modules.ensure_installed = nil
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ local function get_installed_revision(lang)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function is_installed(lang)
|
||||||
|
return #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0
|
||||||
|
end
|
||||||
|
|
||||||
local function needs_update(lang)
|
local function needs_update(lang)
|
||||||
return not get_revision(lang) or get_revision(lang) ~= get_installed_revision(lang)
|
return not get_revision(lang) or get_revision(lang) ~= get_installed_revision(lang)
|
||||||
end
|
end
|
||||||
|
|
@ -280,9 +284,7 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
|
||||||
end
|
end
|
||||||
|
|
||||||
local function install_lang(bang, lang, cache_folder, install_folder, with_sync, generate_from_grammar)
|
local function install_lang(bang, lang, cache_folder, install_folder, with_sync, generate_from_grammar)
|
||||||
if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then
|
if is_installed(lang) and bang ~= '!' then return 1 end
|
||||||
if bang ~= '!' then return 1 end
|
|
||||||
end
|
|
||||||
|
|
||||||
local parser_config = parsers.get_parser_configs()[lang]
|
local parser_config = parsers.get_parser_configs()[lang]
|
||||||
if not parser_config then
|
if not parser_config then
|
||||||
|
|
@ -305,93 +307,113 @@ local function install(options)
|
||||||
local generate_from_grammar = options.generate_from_grammar
|
local generate_from_grammar = options.generate_from_grammar
|
||||||
local exclude_configured_parsers = options.exclude_configured_parsers
|
local exclude_configured_parsers = options.exclude_configured_parsers
|
||||||
|
|
||||||
return function (bang, ...)
|
return function (bang)
|
||||||
if fn.executable('git') == 0 then
|
return function (...)
|
||||||
return api.nvim_err_writeln('Git is required on your system to run this command')
|
if fn.executable('git') == 0 then
|
||||||
|
return api.nvim_err_writeln('Git is required on your system to run this command')
|
||||||
|
end
|
||||||
|
|
||||||
|
local cache_folder, err = utils.get_cache_dir()
|
||||||
|
if err then return api.nvim_err_writeln(err) end
|
||||||
|
|
||||||
|
local install_folder, err = utils.get_parser_install_dir()
|
||||||
|
if err then return api.nvim_err_writeln(err) end
|
||||||
|
|
||||||
|
local languages
|
||||||
|
if ... == 'all' then
|
||||||
|
languages = parsers.available_parsers()
|
||||||
|
elseif ... == 'maintained' then
|
||||||
|
languages = parsers.maintained_parsers()
|
||||||
|
else
|
||||||
|
languages = vim.tbl_flatten({...})
|
||||||
|
end
|
||||||
|
|
||||||
|
if exclude_configured_parsers then
|
||||||
|
languages = utils.difference(languages, configs.get_ignored_parser_installs())
|
||||||
|
end
|
||||||
|
|
||||||
|
if #languages > 1 then
|
||||||
|
reset_progress_counter()
|
||||||
|
end
|
||||||
|
|
||||||
|
local skipped = 0
|
||||||
|
for _, lang in ipairs(languages) do
|
||||||
|
skipped = skipped + install_lang(bang, lang, cache_folder, install_folder, with_sync, generate_from_grammar)
|
||||||
|
end
|
||||||
|
if skipped > 0 then
|
||||||
|
print('Parsers already installed. Use :TSInstall! to force reinstallation.')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local cache_folder, err = utils.get_cache_dir()
|
function M.update(options)
|
||||||
if err then return api.nvim_err_writeln(err) end
|
options = options or {}
|
||||||
|
return function(bang)
|
||||||
local install_folder, err = utils.get_parser_install_dir()
|
return function (...)
|
||||||
if err then return api.nvim_err_writeln(err) end
|
M.lockfile = {}
|
||||||
|
|
||||||
local languages
|
|
||||||
if ... == 'all' then
|
|
||||||
languages = parsers.available_parsers()
|
|
||||||
elseif ... == 'maintained' then
|
|
||||||
languages = parsers.maintained_parsers()
|
|
||||||
else
|
|
||||||
languages = vim.tbl_flatten({...})
|
|
||||||
end
|
|
||||||
|
|
||||||
if exclude_configured_parsers then
|
|
||||||
languages = utils.difference(languages, configs.get_ignored_parser_installs())
|
|
||||||
end
|
|
||||||
|
|
||||||
if #languages > 1 then
|
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
end
|
if ... and ... ~= 'all' then
|
||||||
|
local languages = vim.tbl_flatten({...})
|
||||||
local skipped = 0
|
local installed = 0
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
skipped = skipped + install_lang(bang, lang, cache_folder, install_folder, with_sync, generate_from_grammar)
|
if (not is_installed(lang)) or (needs_update(lang)) then
|
||||||
end
|
installed = installed + 1
|
||||||
if skipped > 0 then
|
install({ with_sync = options.with_sync })('!')(lang)
|
||||||
print('Parsers already installed. Use :TSInstall! to force reinstallation.')
|
end
|
||||||
|
end
|
||||||
|
if installed == 0 then
|
||||||
|
print('Parsers are up-to-date!')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
||||||
|
and outdated_parsers()
|
||||||
|
or info.installed_parsers()
|
||||||
|
if #parsers_to_update == 0 then
|
||||||
|
print('All parsers are up-to-date!')
|
||||||
|
end
|
||||||
|
for _, lang in pairs(parsers_to_update) do
|
||||||
|
install({
|
||||||
|
exclude_configured_parsers = true,
|
||||||
|
with_sync = options.with_sync
|
||||||
|
})('!')(lang)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.update(bang, lang)
|
function M.uninstall(bang)
|
||||||
M.lockfile = {}
|
return function (lang)
|
||||||
reset_progress_counter()
|
local path_sep = '/'
|
||||||
if lang and lang ~= 'all' then
|
if fn.has('win32') == 1 then
|
||||||
install({})('!', lang)
|
path_sep = '\\'
|
||||||
else
|
|
||||||
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
|
||||||
and outdated_parsers()
|
|
||||||
or info.installed_parsers()
|
|
||||||
if #parsers_to_update == 0 then
|
|
||||||
print('All parsers are up-to-date!')
|
|
||||||
end
|
end
|
||||||
for _, lang in pairs(parsers_to_update) do
|
|
||||||
install({
|
if vim.tbl_contains({'all', 'maintained'}, lang) then
|
||||||
exclude_configured_parsers = true
|
reset_progress_counter()
|
||||||
})('!', lang)
|
local installed = info.installed_parsers()
|
||||||
|
if lang == "maintained" then
|
||||||
|
local maintained = parsers.maintained_parsers()
|
||||||
|
installed = vim.tbl_filter(function(l) return vim.tbl_contains(maintained, l) end, installed)
|
||||||
|
end
|
||||||
|
for _, langitem in pairs(installed) do
|
||||||
|
M.uninstall(langitem)
|
||||||
|
end
|
||||||
|
elseif lang then
|
||||||
|
local install_dir, err = utils.get_parser_install_dir()
|
||||||
|
if err then return api.nvim_err_writeln(err) end
|
||||||
|
|
||||||
|
local parser_lib = install_dir..path_sep..lang..".so"
|
||||||
|
|
||||||
|
local command_list = {
|
||||||
|
shell.select_rm_file_cmd(parser_lib, "Uninstalling parser for "..lang)
|
||||||
|
}
|
||||||
|
M.iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been uninstalled')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.uninstall(bang,lang)
|
|
||||||
local path_sep = '/'
|
|
||||||
if fn.has('win32') == 1 then
|
|
||||||
path_sep = '\\'
|
|
||||||
end
|
|
||||||
|
|
||||||
if vim.tbl_contains({'all', 'maintained'}, lang) then
|
|
||||||
reset_progress_counter()
|
|
||||||
local installed = info.installed_parsers()
|
|
||||||
if lang == "maintained" then
|
|
||||||
local maintained = parsers.maintained_parsers()
|
|
||||||
installed = vim.tbl_filter(function(l) return vim.tbl_contains(maintained, l) end, installed)
|
|
||||||
end
|
|
||||||
for _, lang in pairs(installed) do
|
|
||||||
M.uninstall(lang)
|
|
||||||
end
|
|
||||||
elseif lang then
|
|
||||||
local install_dir, err = utils.get_parser_install_dir()
|
|
||||||
if err then return api.nvim_err_writeln(err) end
|
|
||||||
|
|
||||||
local parser_lib = install_dir..path_sep..lang..".so"
|
|
||||||
|
|
||||||
local command_list = {
|
|
||||||
shell.select_rm_file_cmd(parser_lib, "Uninstalling parser for "..lang)
|
|
||||||
}
|
|
||||||
M.iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been uninstalled')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.write_lockfile(verbose, skip_langs)
|
function M.write_lockfile(verbose, skip_langs)
|
||||||
local sorted_parsers = {}
|
local sorted_parsers = {}
|
||||||
-- Load previous lockfile
|
-- Load previous lockfile
|
||||||
|
|
@ -453,10 +475,16 @@ M.commands = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TSUpdate = {
|
TSUpdate = {
|
||||||
run = M.update,
|
run = M.update({}),
|
||||||
|
args = {
|
||||||
|
"-nargs=*",
|
||||||
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSUpdateSync = {
|
||||||
|
run = M.update({ with_sync = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=*",
|
"-nargs=*",
|
||||||
"-bang",
|
|
||||||
"-complete=custom,nvim_treesitter#installed_parsers",
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -464,7 +492,6 @@ M.commands = {
|
||||||
run = M.uninstall,
|
run = M.uninstall,
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
"-bang",
|
|
||||||
"-complete=custom,nvim_treesitter#installed_parsers",
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ local M = {}
|
||||||
|
|
||||||
function M.setup_commands(mod, commands)
|
function M.setup_commands(mod, commands)
|
||||||
for command_name, def in pairs(commands) do
|
for command_name, def in pairs(commands) do
|
||||||
local call_fn = string.format("lua require'nvim-treesitter.%s'.commands.%s.run('<bang>',<f-args>)", mod, command_name)
|
local call_fn = string.format("lua require'nvim-treesitter.%s'.commands.%s.run('<bang>')(<f-args>)", mod, command_name)
|
||||||
local parts = vim.tbl_flatten({
|
local parts = vim.tbl_flatten({
|
||||||
"command!",
|
"command!",
|
||||||
def.args,
|
def.args,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue