mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 03:40:04 -04:00
feat: also reload parsers after uninstallation
This commit is contained in:
parent
c2301adfcb
commit
0598450eb8
1 changed files with 24 additions and 11 deletions
|
|
@ -42,6 +42,26 @@ local function get_job_status()
|
||||||
.. "]"
|
.. "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return function
|
||||||
|
local function reattach_if_possible_fn(lang)
|
||||||
|
return function()
|
||||||
|
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if parsers.get_buf_lang(buf) == lang then
|
||||||
|
vim._ts_remove_language(lang)
|
||||||
|
local ok = pcall(vim.treesitter.language.require_language, lang)
|
||||||
|
for _, mod in ipairs(require("nvim-treesitter.configs").available_modules()) do
|
||||||
|
if ok then
|
||||||
|
require("nvim-treesitter.configs").reattach_module(mod, buf)
|
||||||
|
else
|
||||||
|
require("nvim-treesitter.configs").detach_module(mod, buf)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param lang string
|
---@param lang string
|
||||||
---@param validate boolean|nil
|
---@param validate boolean|nil
|
||||||
---@return InstallInfo
|
---@return InstallInfo
|
||||||
|
|
@ -384,17 +404,7 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{ -- auto-attach modules after installation
|
{ -- auto-attach modules after installation
|
||||||
cmd = function()
|
cmd = reattach_if_possible_fn(lang),
|
||||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
|
||||||
if parsers.get_buf_lang(buf) == lang then
|
|
||||||
vim._ts_remove_language(lang)
|
|
||||||
vim.treesitter.language.require_language(lang)
|
|
||||||
for _, mod in ipairs(require("nvim-treesitter.configs").available_modules()) do
|
|
||||||
require("nvim-treesitter.configs").reattach_module(mod, buf)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if not from_local_path then
|
if not from_local_path then
|
||||||
|
|
@ -594,6 +604,9 @@ function M.uninstall(...)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{ -- auto-reattach or detach modules after uninstallation
|
||||||
|
cmd = reattach_if_possible_fn(lang),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been uninstalled")
|
M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been uninstalled")
|
||||||
elseif #all_parsers > 0 then
|
elseif #all_parsers > 0 then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue