Skip to content

Commit 736f8a6

Browse files
committed
fix: safely close tree window with pcall and debug logging
1 parent a4dd5ad commit 736f8a6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ Specify minimum notification level, uses the values from |vim.log.levels|
15691569
`ERROR`: hard errors e.g. failure to read from the file system.
15701570
`WARNING`: non-fatal errors e.g. unable to system open a file.
15711571
`INFO:` information only e.g. file copy path confirmation.
1572-
`DEBUG:` not used.
1572+
`DEBUG:` information for troubleshooting, e.g. failures in some window closing operations.
15731573

15741574
*nvim-tree.notify.absolute_path*
15751575
Whether to use absolute paths or item names in fs action notifications.

lua/nvim-tree/view.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local events = require "nvim-tree.events"
22
local utils = require "nvim-tree.utils"
33
local log = require "nvim-tree.log"
4+
local notify = require "nvim-tree.notify"
45

56
---@class OpenInWinOpts
67
---@field hijack_current_buf boolean|nil default true
@@ -227,7 +228,11 @@ local function close(tabpage)
227228
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
228229
end
229230
if vim.api.nvim_win_is_valid(tree_win or 0) then
230-
vim.api.nvim_win_close(tree_win or 0, true)
231+
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
232+
if not success then
233+
notify.debug("Failed to close window: " .. error)
234+
return
235+
end
231236
end
232237
events._dispatch_on_tree_close()
233238
return

0 commit comments

Comments
 (0)