Skip to content

Commit 0a437b3

Browse files
committed
vim: nvim-tree: more logging
1 parent bca6ed8 commit 0a437b3

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ local function open_file_in_tab(filename)
190190
if M.quit_on_open then
191191
local explorer = core.get_explorer()
192192
if explorer then
193-
explorer.view:close()
193+
explorer.view:close(nil, "open-file.open_file_in_tab")
194194
end
195195
end
196196
if M.relative_path then
@@ -203,7 +203,7 @@ local function drop(filename)
203203
if M.quit_on_open then
204204
local explorer = core.get_explorer()
205205
if explorer then
206-
explorer.view:close()
206+
explorer.view:close(nil, "open-file.drop")
207207
end
208208
end
209209
if M.relative_path then
@@ -216,7 +216,7 @@ local function tab_drop(filename)
216216
if M.quit_on_open then
217217
local explorer = core.get_explorer()
218218
if explorer then
219-
explorer.view:close()
219+
explorer.view:close(nil, "open-file.tab_drop")
220220
end
221221
end
222222
if M.relative_path then
@@ -447,7 +447,7 @@ function M.fn(mode, filename)
447447
end
448448

449449
if M.quit_on_open and explorer then
450-
explorer.view:close()
450+
explorer.view:close(nil, "open-file.fn")
451451
end
452452
end
453453

lua/nvim-tree/actions/tree/toggle.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function M.fn(opts, no_focus, cwd, bang)
4444

4545
if explorer and explorer.view:is_visible() then
4646
-- close
47-
explorer.view:close()
47+
explorer.view:close(nil, "toggle.fn")
4848
else
4949
-- open
5050
lib.open({

lua/nvim-tree/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts)
247247
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
248248
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
249249
if explorer then
250-
explorer.view:close(cur_tabpage)
250+
explorer.view:close(cur_tabpage, "api.edit " .. mode)
251251
end
252252
end
253253

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function Explorer:create_autocmds()
107107
pattern = "NvimTree_*",
108108
callback = function()
109109
if utils.is_nvim_tree_buf(0) then
110-
self.view:close()
110+
self.view:close(nil, "WinLeave")
111111
end
112112
end,
113113
})

lua/nvim-tree/explorer/view.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ function View:create_buffer(bufnr)
133133
if self.explorer.opts.experimental.multi_instance then
134134
local tabid = tab
135135
self.bufnr_by_tab[tabid] = globals.BUFNR_PER_TAB[tabid]
136+
136137
log.line("dev", "buffer channel attaching t%d b%d", tabid, self.bufnr_by_tab[tabid])
137-
vim.api.nvim_buf_attach(self.bufnr_by_tab[tabid], true, {
138+
vim.api.nvim_buf_attach(self.bufnr_by_tab[tabid], false, {
138139
on_detach = function(op, bnr)
139140
log.line("dev", "buffer channel %s t%d b%d", op, tabid, bnr)
141+
self.bufnr_by_tab[tabid] = nil
140142
end,
141143
})
142144
end
@@ -291,6 +293,9 @@ end
291293
---@private
292294
---@param tabpage integer
293295
function View:close_internal(tabpage)
296+
if self.explorer.opts.experimental.multi_instance then
297+
log.line("dev", "View:close_internal(t%s)", tabpage)
298+
end
294299
if not self:is_visible({ tabpage = tabpage }) then
295300
return
296301
end
@@ -305,6 +310,9 @@ function View:close_internal(tabpage)
305310
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
306311
end
307312
if vim.api.nvim_win_is_valid(tree_win or 0) then
313+
if self.explorer.opts.experimental.multi_instance then
314+
log.line("dev", "View:close_internal(t%s) w%s", tabpage, tree_win)
315+
end
308316
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
309317
if not success then
310318
notify.debug("Failed to close window: " .. error)
@@ -327,7 +335,12 @@ function View:close_all_tabs()
327335
end
328336

329337
---@param tabpage integer|nil
330-
function View:close(tabpage)
338+
---@param callsite string
339+
function View:close(tabpage, callsite)
340+
if self.explorer.opts.experimental.multi_instance then
341+
log.line("dev", "View:close(t%s, %s)", tabpage, callsite)
342+
end
343+
331344
if self.explorer.opts.tab.sync.close then
332345
self:close_all_tabs()
333346
elseif tabpage then
@@ -503,7 +516,7 @@ function View:abandon_current_window(callsite)
503516
log.line("dev", "View:abandon_current_window(%-20.20s) t%d w%s b%s member b%s %s",
504517
callsite,
505518
tab,
506-
globals.TABPAGES and globals.TABPAGES.winnr or nil,
519+
globals.TABPAGES[tab] and globals.TABPAGES[tab].winnr or nil,
507520
globals.BUFNR_PER_TAB[tab],
508521
self.bufnr_by_tab[tab],
509522
(globals.BUFNR_PER_TAB[tab] == self.bufnr_by_tab[tab]) and "" or "MISMATCH")
@@ -575,7 +588,7 @@ function View:focus(winnr, open_if_closed)
575588
local wnr = winnr or self:get_winnr(nil, "View:focus1")
576589

577590
if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then
578-
self:close()
591+
self:close(nil, "View:focus")
579592
self:open()
580593
wnr = self:get_winnr(nil, "View:focus2")
581594
elseif open_if_closed and not self:is_visible() then

0 commit comments

Comments
 (0)