mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 10:50:06 -04:00
Add TSUninstall
This commit is contained in:
parent
a872762d82
commit
70939e71c9
2 changed files with 46 additions and 4 deletions
|
|
@ -127,12 +127,19 @@ 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*
|
||||||
:TSUpdate {language}~
|
:TSUpdate {language}~
|
||||||
|
|
||||||
Update the installed parser of {language} or all installed parsers
|
Update the installed parser of {language} or all installed parsers
|
||||||
if {language} is omitted.
|
if {language} is omitted.
|
||||||
|
|
||||||
|
*:TSUninstall*
|
||||||
|
:TSUninstall {language}~
|
||||||
|
|
||||||
|
Deletes the parser for corresponding {language}. You can use 'all' for
|
||||||
|
language to uninstall all parsers.
|
||||||
|
|
||||||
*:TSBufEnable*
|
*:TSBufEnable*
|
||||||
:TSBufEnable {module}~
|
:TSBufEnable {module}~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ local info = require'nvim-treesitter.info'
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function iter_cmd(cmd_list, i, lang)
|
local function iter_cmd(cmd_list, i, lang, success_message)
|
||||||
if i == #cmd_list + 1 then return print('Treesitter parser for '..lang..' has been installed') end
|
if i == #cmd_list + 1 then return print(success_message) end
|
||||||
|
|
||||||
local attr = cmd_list[i]
|
local attr = cmd_list[i]
|
||||||
if attr.info then print(attr.info) end
|
if attr.info then print(attr.info) end
|
||||||
|
|
@ -19,7 +19,7 @@ local function iter_cmd(cmd_list, i, lang)
|
||||||
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
|
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
|
||||||
handle:close()
|
handle:close()
|
||||||
if code ~= 0 then return api.nvim_err_writeln(attr.err) end
|
if code ~= 0 then return api.nvim_err_writeln(attr.err) end
|
||||||
iter_cmd(cmd_list, i + 1, lang)
|
iter_cmd(cmd_list, i + 1, lang, success_message)
|
||||||
end))
|
end))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
||||||
print('Treesitter parser for '..lang..' has been installed')
|
print('Treesitter parser for '..lang..' has been installed')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
iter_cmd(command_list, 1, lang)
|
iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been installed')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -190,6 +190,34 @@ function M.update(lang)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.uninstall(lang)
|
||||||
|
if lang == 'all' then
|
||||||
|
local installed = info.installed_parsers()
|
||||||
|
for _, lang in pairs(installed) do
|
||||||
|
M.uninstall(lang)
|
||||||
|
end
|
||||||
|
elseif lang then
|
||||||
|
local package_path, err = utils.get_package_path()
|
||||||
|
if err then
|
||||||
|
print(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local parser_lib = package_path.."/parser/"..lang..".so"
|
||||||
|
|
||||||
|
local command_list = {
|
||||||
|
{
|
||||||
|
cmd = 'rm',
|
||||||
|
opts = {
|
||||||
|
args = { parser_lib },
|
||||||
|
},
|
||||||
|
info = "Uninstalling parser for "..lang,
|
||||||
|
err = "Could not delete "..parser_lib,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been uninstalled')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.ensure_installed = install(false, false)
|
M.ensure_installed = install(false, false)
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
|
|
@ -213,6 +241,13 @@ M.commands = {
|
||||||
"-nargs=*",
|
"-nargs=*",
|
||||||
"-complete=custom,v:lua.ts_installed_parsers"
|
"-complete=custom,v:lua.ts_installed_parsers"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TSUninstall = {
|
||||||
|
run = M.uninstall,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,v:lua.ts_installed_parsers"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue