261261--- @param tabnr integer
262262function View :save_tab_state (tabnr )
263263 local tabpage = tabnr or vim .api .nvim_get_current_tabpage ()
264- globals .CURSORS [tabpage ] = vim .api .nvim_win_get_cursor (self :get_winnr (tabpage ) or 0 )
264+ globals .CURSORS [tabpage ] = vim .api .nvim_win_get_cursor (self :get_winnr (tabpage , " View:save_tab_state " ) or 0 )
265265end
266266
267267--- @private
@@ -272,7 +272,7 @@ function View:close_internal(tabpage)
272272 end
273273 self :save_tab_state (tabpage )
274274 switch_buf_if_last_buf ()
275- local tree_win = self :get_winnr (tabpage )
275+ local tree_win = self :get_winnr (tabpage , " View:close_internal " )
276276 local current_win = vim .api .nvim_get_current_win ()
277277 for _ , win in pairs (vim .api .nvim_tabpage_list_wins (tabpage )) do
278278 if vim .api .nvim_win_get_config (win ).relative == " " then
@@ -343,7 +343,7 @@ function View:grow()
343343 local padding = self :get_size (self .padding )
344344
345345 -- account for sign/number columns etc.
346- local wininfo = vim .fn .getwininfo (self :get_winnr ())
346+ local wininfo = vim .fn .getwininfo (self :get_winnr (nil , " View:grow " ))
347347 if type (wininfo ) == " table" and type (wininfo [1 ]) == " table" then
348348 padding = padding + wininfo [1 ].textoff
349349 end
@@ -412,7 +412,7 @@ function View:resize(size)
412412 return
413413 end
414414
415- local winnr = self :get_winnr () or 0
415+ local winnr = self :get_winnr (nil , " View:resize " ) or 0
416416
417417 local new_size = self :get_width ()
418418
@@ -495,25 +495,25 @@ function View:is_visible(opts)
495495 return false
496496 end
497497
498- return self :get_winnr () ~= nil and vim .api .nvim_win_is_valid (self :get_winnr () or 0 )
498+ return self :get_winnr (nil , " View:is_visible1 " ) ~= nil and vim .api .nvim_win_is_valid (self :get_winnr (nil , " View:is_visible2 " ) or 0 )
499499end
500500
501501--- @param opts table | nil
502502function View :set_cursor (opts )
503503 if self :is_visible () then
504- pcall (vim .api .nvim_win_set_cursor , self :get_winnr (), opts )
504+ pcall (vim .api .nvim_win_set_cursor , self :get_winnr (nil , " View:set_cursor " ), opts )
505505 end
506506end
507507
508508--- @param winnr number | nil
509509--- @param open_if_closed boolean | nil
510510function View :focus (winnr , open_if_closed )
511- local wnr = winnr or self :get_winnr ()
511+ local wnr = winnr or self :get_winnr (nil , " View:focus1 " )
512512
513513 if vim .api .nvim_win_get_tabpage (wnr or 0 ) ~= vim .api .nvim_win_get_tabpage (0 ) then
514514 self :close ()
515515 self :open ()
516- wnr = self :get_winnr ()
516+ wnr = self :get_winnr (nil , " View:focus2 " )
517517 elseif open_if_closed and not self :is_visible () then
518518 self :open ()
519519 end
@@ -532,7 +532,7 @@ function View:winid(opts)
532532 tabpage = vim .api .nvim_get_current_tabpage ()
533533 end
534534 if self :is_visible ({ tabpage = tabpage }) then
535- return self :get_winnr (tabpage )
535+ return self :get_winnr (tabpage , " View:winid " )
536536 else
537537 return nil
538538 end
@@ -546,12 +546,37 @@ end
546546
547547--- Returns the window number for nvim-tree within the tabpage specified
548548--- @param tabpage number | nil (optional ) the number of the chosen tabpage. Defaults to current tabpage.
549+ --- @param callsite string ? for logging purposes
549550--- @return number | nil
550- function View :get_winnr (tabpage )
551- tabpage = tabpage or vim .api .nvim_get_current_tabpage ()
552- local tabinfo = globals .TABPAGES [tabpage ]
553- if tabinfo and tabinfo .winnr and vim .api .nvim_win_is_valid (tabinfo .winnr ) then
554- return tabinfo .winnr
551+ function View :get_winnr (tabpage , callsite )
552+ if self .explorer .opts .experimental .multi_instance_debug then
553+ local msg = string.format (" View:get_winnr(%3s, %-20.20s)" , tabpage , callsite )
554+
555+ tabpage = tabpage or vim .api .nvim_get_current_tabpage ()
556+ local tabinfo = globals .TABPAGES [tabpage ]
557+
558+ local ret = nil
559+
560+ if not tabinfo then
561+ msg = string.format (" %s t%d no tabinfo" , msg , tabpage )
562+ elseif not tabinfo .winnr then
563+ msg = string.format (" %s t%d no tabinfo.winnr" , msg , tabpage )
564+ elseif not vim .api .nvim_win_is_valid (tabinfo .winnr ) then
565+ msg = string.format (" %s t%d invalid tabinfo.winnr %d" , msg , tabpage , tabinfo .winnr )
566+ else
567+ msg = string.format (" %s t%d w%d" , msg , tabpage , tabinfo .winnr )
568+ ret = tabinfo .winnr
569+ end
570+
571+ log .line (" dev" , " %s" , msg )
572+
573+ return ret
574+ else
575+ tabpage = tabpage or vim .api .nvim_get_current_tabpage ()
576+ local tabinfo = globals .TABPAGES [tabpage ]
577+ if tabinfo and tabinfo .winnr and vim .api .nvim_win_is_valid (tabinfo .winnr ) then
578+ return tabinfo .winnr
579+ end
555580 end
556581end
557582
@@ -562,7 +587,7 @@ function View:get_bufnr()
562587end
563588
564589function View :prevent_buffer_override ()
565- local view_winnr = self :get_winnr ()
590+ local view_winnr = self :get_winnr (nil , " View:get_bufnr " )
566591 local view_bufnr = self :get_bufnr ()
567592
568593 -- need to schedule to let the new buffer populate the window
617642
618643-- used on ColorScheme event
619644function View :reset_winhl ()
620- local winnr = self :get_winnr ()
645+ local winnr = self :get_winnr (nil , " View:reset_winhl1 " )
621646 if winnr and vim .api .nvim_win_is_valid (winnr ) then
622- vim .wo [self :get_winnr ()].winhl = appearance .WIN_HL
647+ vim .wo [self :get_winnr (nil , " View:reset_winhl2 " )].winhl = appearance .WIN_HL
623648 end
624649end
625650
0 commit comments