diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2022-12-27 20:39:33 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-12-31 13:59:18 +0100 |
| commit | 29304e16bbb74559a22cb78ef7c59f086a9cc9e2 (patch) | |
| tree | 04a6834888f4a267bcd171c2b63d75c694759089 /lua | |
| parent | feat: also reload parsers after uninstallation (diff) | |
| download | nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar.gz nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar.bz2 nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar.lz nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar.xz nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.tar.zst nvim-treesitter-29304e16bbb74559a22cb78ef7c59f086a9cc9e2.zip | |
fix: show errors when reload after installation fails
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 13 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 0b9eaa512..87f930b8f 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -232,7 +232,7 @@ end ---Recurses through all modules including submodules ---@param accumulator function called for each module ----@param root {[string]: TSModule} root configuration table to start at +---@param root {[string]: TSModule}|nil root configuration table to start at ---@param path string|nil prefix path local function recurse_modules(accumulator, root, path) root = root or config.modules @@ -529,7 +529,7 @@ function M.reattach_module(mod_name, bufnr, lang) end ---Gets available modules ----@param root {[string]:TSModule} table to find modules +---@param root {[string]:TSModule}|nil table to find modules function M.available_modules(root) local modules = {} diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 1b16d5e01..c0128130b 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -44,15 +44,18 @@ end ---@param lang string ---@return function -local function reattach_if_possible_fn(lang) +local function reattach_if_possible_fn(lang, error_on_fail) 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) + local ok, err = pcall(vim.treesitter.language.require_language, lang) + if not ok and error_on_fail then + vim.notify("Could not load parser for " .. lang .. ": " .. vim.inspect(err)) + end for _, mod in ipairs(require("nvim-treesitter.configs").available_modules()) do if ok then - require("nvim-treesitter.configs").reattach_module(mod, buf) + require("nvim-treesitter.configs").reattach_module(mod, buf, lang) else require("nvim-treesitter.configs").detach_module(mod, buf) end @@ -404,7 +407,7 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync, end, }, { -- auto-attach modules after installation - cmd = reattach_if_possible_fn(lang), + cmd = reattach_if_possible_fn(lang, true), }, }) if not from_local_path then @@ -605,7 +608,7 @@ function M.uninstall(...) end, }, { -- auto-reattach or detach modules after uninstallation - cmd = reattach_if_possible_fn(lang), + cmd = reattach_if_possible_fn(lang, false), }, } M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been uninstalled") |
