From 736f8a6dacb2b48ef9bc4a9c5c1a86673f748614 Mon Sep 17 00:00:00 2001 From: Kyle Beede Date: Fri, 13 Sep 2024 22:11:53 -0700 Subject: [PATCH] fix: safely close tree window with pcall and debug logging --- doc/nvim-tree-lua.txt | 2 +- lua/nvim-tree/view.lua | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 2297d82685d..29293fbaf0a 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1569,7 +1569,7 @@ Specify minimum notification level, uses the values from |vim.log.levels| `ERROR`: hard errors e.g. failure to read from the file system. `WARNING`: non-fatal errors e.g. unable to system open a file. `INFO:` information only e.g. file copy path confirmation. -`DEBUG:` not used. +`DEBUG:` information for troubleshooting, e.g. failures in some window closing operations. *nvim-tree.notify.absolute_path* Whether to use absolute paths or item names in fs action notifications. diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index f30eb2720a4..315da3d0d19 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -1,6 +1,7 @@ local events = require "nvim-tree.events" local utils = require "nvim-tree.utils" local log = require "nvim-tree.log" +local notify = require "nvim-tree.notify" ---@class OpenInWinOpts ---@field hijack_current_buf boolean|nil default true @@ -227,7 +228,11 @@ local function close(tabpage) vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win)) end if vim.api.nvim_win_is_valid(tree_win or 0) then - vim.api.nvim_win_close(tree_win or 0, true) + local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true) + if not success then + notify.debug("Failed to close window: " .. error) + return + end end events._dispatch_on_tree_close() return