Add TSUninstall

This commit is contained in:
Stephan Seitz 2020-08-01 18:32:12 +02:00 committed by Stephan Seitz
parent a872762d82
commit 70939e71c9
2 changed files with 46 additions and 4 deletions

View file

@ -127,12 +127,19 @@ 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.
*:TSUninstall*
:TSUninstall {language}~
Deletes the parser for corresponding {language}. You can use 'all' for
language to uninstall all parsers.
*:TSBufEnable*
:TSBufEnable {module}~

View file

@ -8,8 +8,8 @@ local info = require'nvim-treesitter.info'
local M = {}
local function iter_cmd(cmd_list, i, lang)
if i == #cmd_list + 1 then return print('Treesitter parser for '..lang..' has been installed') end
local function iter_cmd(cmd_list, i, lang, success_message)
if i == #cmd_list + 1 then return print(success_message) end
local attr = cmd_list[i]
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:close()
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
@ -117,7 +117,7 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
print('Treesitter parser for '..lang..' has been installed')
end
else
iter_cmd(command_list, 1, lang)
iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been installed')
end
end
@ -190,6 +190,34 @@ function M.update(lang)
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.commands = {
@ -213,6 +241,13 @@ M.commands = {
"-nargs=*",
"-complete=custom,v:lua.ts_installed_parsers"
}
},
TSUninstall = {
run = M.uninstall,
args = {
"-nargs=+",
"-complete=custom,v:lua.ts_installed_parsers"
}
}
}