mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
Use bang for TSInstall commands
This commit is contained in:
parent
9bcf658ca4
commit
b46580fb66
2 changed files with 22 additions and 24 deletions
|
|
@ -279,15 +279,9 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function install_lang(lang, ask_reinstall, 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 #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then
|
||||||
if ask_reinstall ~= 'force' then
|
if bang ~= '!' then return 1 end
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local parser_config = parsers.get_parser_configs()[lang]
|
local parser_config = parsers.get_parser_configs()[lang]
|
||||||
|
|
@ -302,16 +296,16 @@ local function install_lang(lang, ask_reinstall, cache_folder, install_folder, w
|
||||||
}
|
}
|
||||||
|
|
||||||
run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar)
|
run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar)
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function install(options)
|
local function install(options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
local with_sync = options.with_sync
|
local with_sync = options.with_sync
|
||||||
local ask_reinstall = options.ask_reinstall
|
|
||||||
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 (...)
|
return function (bang, ...)
|
||||||
if fn.executable('git') == 0 then
|
if fn.executable('git') == 0 then
|
||||||
return api.nvim_err_writeln('Git is required on your system to run this command')
|
return api.nvim_err_writeln('Git is required on your system to run this command')
|
||||||
end
|
end
|
||||||
|
|
@ -323,16 +317,12 @@ local function install(options)
|
||||||
if err then return api.nvim_err_writeln(err) end
|
if err then return api.nvim_err_writeln(err) end
|
||||||
|
|
||||||
local languages
|
local languages
|
||||||
local ask
|
|
||||||
if ... == 'all' then
|
if ... == 'all' then
|
||||||
languages = parsers.available_parsers()
|
languages = parsers.available_parsers()
|
||||||
ask = false
|
|
||||||
elseif ... == 'maintained' then
|
elseif ... == 'maintained' then
|
||||||
languages = parsers.maintained_parsers()
|
languages = parsers.maintained_parsers()
|
||||||
ask = false
|
|
||||||
else
|
else
|
||||||
languages = vim.tbl_flatten({...})
|
languages = vim.tbl_flatten({...})
|
||||||
ask = ask_reinstall
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if exclude_configured_parsers then
|
if exclude_configured_parsers then
|
||||||
|
|
@ -343,17 +333,21 @@ local function install(options)
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local skipped = 0
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
install_lang(lang, ask, cache_folder, install_folder, with_sync, generate_from_grammar)
|
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
|
end
|
||||||
|
|
||||||
function M.update(lang)
|
function M.update(bang, lang)
|
||||||
M.lockfile = {}
|
M.lockfile = {}
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
if lang and lang ~= 'all' then
|
if lang and lang ~= 'all' then
|
||||||
install({ ask_reinstall = 'force' })(lang)
|
install({})('!', lang)
|
||||||
else
|
else
|
||||||
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
||||||
and outdated_parsers()
|
and outdated_parsers()
|
||||||
|
|
@ -363,14 +357,13 @@ function M.update(lang)
|
||||||
end
|
end
|
||||||
for _, lang in pairs(parsers_to_update) do
|
for _, lang in pairs(parsers_to_update) do
|
||||||
install({
|
install({
|
||||||
ask_reinstall = 'force',
|
|
||||||
exclude_configured_parsers = true
|
exclude_configured_parsers = true
|
||||||
})(lang)
|
})('!', lang)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.uninstall(lang)
|
function M.uninstall(bang,lang)
|
||||||
local path_sep = '/'
|
local path_sep = '/'
|
||||||
if fn.has('win32') == 1 then
|
if fn.has('win32') == 1 then
|
||||||
path_sep = '\\'
|
path_sep = '\\'
|
||||||
|
|
@ -436,23 +429,26 @@ M.ensure_installed = install({ exclude_configured_parsers = true })
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
TSInstall = {
|
TSInstall = {
|
||||||
run = install({ ask_reinstall = true }),
|
run = install({ }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TSInstallFromGrammar = {
|
TSInstallFromGrammar = {
|
||||||
run = install({ ask_reinstall = true, generate_from_grammar = true }),
|
run = install({ generate_from_grammar = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TSInstallSync = {
|
TSInstallSync = {
|
||||||
run = install({ with_sync = true, ask_reinstall = true }),
|
run = install({ with_sync = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -460,6 +456,7 @@ M.commands = {
|
||||||
run = M.update,
|
run = M.update,
|
||||||
args = {
|
args = {
|
||||||
"-nargs=*",
|
"-nargs=*",
|
||||||
|
"-bang",
|
||||||
"-complete=custom,nvim_treesitter#installed_parsers",
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -467,6 +464,7 @@ 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(<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