diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2020-08-01 18:32:12 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2020-08-02 22:58:08 +0200 |
| commit | 70939e71c974541a186f855d422cc8f3a420d672 (patch) | |
| tree | be642fd0e5ecab476c0e38b9ee569f19991ab000 | |
| parent | Add TSUpdate command to update parsers (diff) | |
| download | nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar.gz nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar.bz2 nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar.lz nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar.xz nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.tar.zst nvim-treesitter-70939e71c974541a186f855d422cc8f3a420d672.zip | |
Add TSUninstall
| -rw-r--r-- | doc/nvim-treesitter.txt | 7 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 43 |
2 files changed, 46 insertions, 4 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 5d32f217a..ebe568a1f 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -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}~ diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index a8c79d52d..8d1e351bc 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -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" + } } } |
