@@ -31,6 +31,7 @@ local DEFAULT_PADDING = 1
3131--- @field private width (fun (): integer )| integer | string
3232--- @field private max_width integer
3333--- @field private padding integer
34+ --- @field private bufnr_by_tab table<integer , integer> for diagnostics during multi instance
3435local View = Class :extend ()
3536
3637--- @class View
@@ -53,6 +54,7 @@ function View:new(args)
5354 self .preserve_window_proportions = self .explorer .opts .view .preserve_window_proportions
5455 self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
5556 self .live_filter = { prev_focused_node = nil , }
57+ self .bufnr_by_tab = {}
5658
5759 self .winopts = {
5860 relativenumber = self .explorer .opts .view .relativenumber ,
@@ -127,16 +129,17 @@ function View:create_buffer(bufnr)
127129
128130 local tab = vim .api .nvim_get_current_tabpage ()
129131 globals .BUFNR_PER_TAB [tab ] = bufnr or vim .api .nvim_create_buf (false , false )
130- vim .api .nvim_buf_set_name (self :get_bufnr (), " NvimTree_" .. tab )
132+ self .bufnr_by_tab [tab ] = globals .BUFNR_PER_TAB [tab ]
133+ vim .api .nvim_buf_set_name (self :get_bufnr (" View:create_buffer1" ), " NvimTree_" .. tab )
131134
132- bufnr = self :get_bufnr ()
135+ bufnr = self :get_bufnr (" View:create_buffer2 " )
133136 for _ , option in ipairs (BUFFER_OPTIONS ) do
134137 vim .api .nvim_set_option_value (option .name , option .value , { buf = bufnr })
135138 end
136139
137- require (" nvim-tree.keymap" ).on_attach (self :get_bufnr ())
140+ require (" nvim-tree.keymap" ).on_attach (self :get_bufnr (" View:create_buffer3 " ))
138141
139- events ._dispatch_tree_attached_post (self :get_bufnr ())
142+ events ._dispatch_tree_attached_post (self :get_bufnr (" View:create_buffer4 " ))
140143end
141144
142145--- @private
@@ -171,7 +174,7 @@ local move_tbl = {
171174-- setup_tabpage sets up the initial state of a tab
172175--- @private
173176--- @param tabpage integer
174- --- @param callsite string ?
177+ --- @param callsite string
175178function View :setup_tabpage (tabpage , callsite )
176179 local winnr = vim .api .nvim_get_current_win ()
177180
188191
189192--- @private
190193function View :set_window_options_and_buffer ()
191- pcall (vim .api .nvim_command , " buffer " .. self :get_bufnr ())
194+ pcall (vim .api .nvim_command , " buffer " .. self :get_bufnr (" View:set_window_options_and_buffer " ))
192195
193196 if vim .fn .has (" nvim-0.10" ) == 1 then
194197 local eventignore = vim .api .nvim_get_option_value (" eventignore" , {})
348351--- @private
349352function View :grow ()
350353 local starts_at = self :is_root_folder_visible (require (" nvim-tree.core" ).get_cwd ()) and 1 or 0
351- local lines = vim .api .nvim_buf_get_lines (self :get_bufnr (), starts_at , - 1 , false )
354+ local lines = vim .api .nvim_buf_get_lines (self :get_bufnr (" View:grow1 " ), starts_at , - 1 , false )
352355 -- number of columns of right-padding to indicate end of path
353356 local padding = self :get_size (self .padding )
354357
@@ -372,7 +375,7 @@ function View:grow()
372375 for line_nr , l in pairs (lines ) do
373376 local count = vim .fn .strchars (l )
374377 -- also add space for right-aligned icons
375- local extmarks = vim .api .nvim_buf_get_extmarks (self :get_bufnr (), ns_id , { line_nr , 0 }, { line_nr , - 1 }, { details = true })
378+ local extmarks = vim .api .nvim_buf_get_extmarks (self :get_bufnr (" View:grow2 " ), ns_id , { line_nr , 0 }, { line_nr , - 1 }, { details = true })
376379 count = count + utils .extmarks_length (extmarks )
377380 if resizing_width < count then
378381 resizing_width = count
@@ -449,7 +452,7 @@ function View:set_current_win(callsite)
449452 local current_win = vim .api .nvim_get_current_win ()
450453
451454 if self .explorer .opts .experimental .multi_instance_debug then
452- log .line (" dev" , " View:set_current_win(%-20.20s) t%d w%3d ->w%3d %s" ,
455+ log .line (" dev" , " View:set_current_win(%-20.20s) t%d w%3s ->w%3s %s" ,
453456 callsite ,
454457 current_tab ,
455458 globals .TABPAGES [current_tab ].winnr ,
483486function View :abandon_current_window ()
484487 local tab = vim .api .nvim_get_current_tabpage ()
485488 globals .BUFNR_PER_TAB [tab ] = nil
489+ self .bufnr_by_tab [tab ] = nil
486490 if globals .TABPAGES [tab ] then
487491 globals .TABPAGES [tab ].winnr = nil
488492 end
491495function View :abandon_all_windows ()
492496 for tab , _ in pairs (vim .api .nvim_list_tabpages ()) do
493497 globals .BUFNR_PER_TAB [tab ] = nil
498+ self .bufnr_by_tab [tab ] = nil
494499 if globals .TABPAGES [tab ] then
495500 globals .TABPAGES [tab ].winnr = nil
496501 end
568573
569574--- Returns the window number for nvim-tree within the tabpage specified
570575--- @param tabpage number | nil (optional ) the number of the chosen tabpage. Defaults to current tabpage.
571- --- @param callsite string ? for logging purposes
576+ --- @param callsite string for logging purposes
572577--- @return number | nil
573578function View :get_winnr (tabpage , callsite )
574579 if self .explorer .opts .experimental .multi_instance_debug then
@@ -603,14 +608,24 @@ function View:get_winnr(tabpage, callsite)
603608end
604609
605610--- Returns the current nvim tree bufnr
611+ --- @param callsite string
606612--- @return number
607- function View :get_bufnr ()
608- return globals .BUFNR_PER_TAB [vim .api .nvim_get_current_tabpage ()]
613+ function View :get_bufnr (callsite )
614+ local tab = vim .api .nvim_get_current_tabpage ()
615+ if self .explorer .opts .experimental .multi_instance_debug then
616+ log .line (" dev" , " View:get_bufnr(%-20.20s) t%d global b%s member b%s %s" ,
617+ callsite ,
618+ tab ,
619+ globals .BUFNR_PER_TAB [tab ],
620+ self .bufnr_by_tab [tab ],
621+ (globals .BUFNR_PER_TAB [tab ] == self .bufnr_by_tab [tab ]) and " " or " MISMATCH" )
622+ end
623+ return globals .BUFNR_PER_TAB [tab ]
609624end
610625
611626function View :prevent_buffer_override ()
612627 local view_winnr = self :get_winnr (nil , " View:prevent_buffer_override" )
613- local view_bufnr = self :get_bufnr ()
628+ local view_bufnr = self :get_bufnr (" View:prevent_buffer_override " )
614629
615630 -- need to schedule to let the new buffer populate the window
616631 -- because this event needs to be run on bufWipeout.
0 commit comments