@@ -31,6 +31,7 @@ local DEFAULT_PADDING = 1
31
31
--- @field private width (fun (): integer )| integer | string
32
32
--- @field private max_width integer
33
33
--- @field private padding integer
34
+ --- @field private bufnr_by_tab table<integer , integer> for diagnostics during multi instance
34
35
local View = Class :extend ()
35
36
36
37
--- @class View
@@ -53,6 +54,7 @@ function View:new(args)
53
54
self .preserve_window_proportions = self .explorer .opts .view .preserve_window_proportions
54
55
self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
55
56
self .live_filter = { prev_focused_node = nil , }
57
+ self .bufnr_by_tab = {}
56
58
57
59
self .winopts = {
58
60
relativenumber = self .explorer .opts .view .relativenumber ,
@@ -127,16 +129,17 @@ function View:create_buffer(bufnr)
127
129
128
130
local tab = vim .api .nvim_get_current_tabpage ()
129
131
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 )
131
134
132
- bufnr = self :get_bufnr ()
135
+ bufnr = self :get_bufnr (" View:create_buffer2 " )
133
136
for _ , option in ipairs (BUFFER_OPTIONS ) do
134
137
vim .api .nvim_set_option_value (option .name , option .value , { buf = bufnr })
135
138
end
136
139
137
- require (" nvim-tree.keymap" ).on_attach (self :get_bufnr ())
140
+ require (" nvim-tree.keymap" ).on_attach (self :get_bufnr (" View:create_buffer3 " ))
138
141
139
- events ._dispatch_tree_attached_post (self :get_bufnr ())
142
+ events ._dispatch_tree_attached_post (self :get_bufnr (" View:create_buffer4 " ))
140
143
end
141
144
142
145
--- @private
@@ -171,7 +174,7 @@ local move_tbl = {
171
174
-- setup_tabpage sets up the initial state of a tab
172
175
--- @private
173
176
--- @param tabpage integer
174
- --- @param callsite string ?
177
+ --- @param callsite string
175
178
function View :setup_tabpage (tabpage , callsite )
176
179
local winnr = vim .api .nvim_get_current_win ()
177
180
188
191
189
192
--- @private
190
193
function 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 " ))
192
195
193
196
if vim .fn .has (" nvim-0.10" ) == 1 then
194
197
local eventignore = vim .api .nvim_get_option_value (" eventignore" , {})
348
351
--- @private
349
352
function View :grow ()
350
353
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 )
352
355
-- number of columns of right-padding to indicate end of path
353
356
local padding = self :get_size (self .padding )
354
357
@@ -372,7 +375,7 @@ function View:grow()
372
375
for line_nr , l in pairs (lines ) do
373
376
local count = vim .fn .strchars (l )
374
377
-- 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 })
376
379
count = count + utils .extmarks_length (extmarks )
377
380
if resizing_width < count then
378
381
resizing_width = count
@@ -449,7 +452,7 @@ function View:set_current_win(callsite)
449
452
local current_win = vim .api .nvim_get_current_win ()
450
453
451
454
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" ,
453
456
callsite ,
454
457
current_tab ,
455
458
globals .TABPAGES [current_tab ].winnr ,
483
486
function View :abandon_current_window ()
484
487
local tab = vim .api .nvim_get_current_tabpage ()
485
488
globals .BUFNR_PER_TAB [tab ] = nil
489
+ self .bufnr_by_tab [tab ] = nil
486
490
if globals .TABPAGES [tab ] then
487
491
globals .TABPAGES [tab ].winnr = nil
488
492
end
491
495
function View :abandon_all_windows ()
492
496
for tab , _ in pairs (vim .api .nvim_list_tabpages ()) do
493
497
globals .BUFNR_PER_TAB [tab ] = nil
498
+ self .bufnr_by_tab [tab ] = nil
494
499
if globals .TABPAGES [tab ] then
495
500
globals .TABPAGES [tab ].winnr = nil
496
501
end
568
573
569
574
--- Returns the window number for nvim-tree within the tabpage specified
570
575
--- @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
572
577
--- @return number | nil
573
578
function View :get_winnr (tabpage , callsite )
574
579
if self .explorer .opts .experimental .multi_instance_debug then
@@ -603,14 +608,24 @@ function View:get_winnr(tabpage, callsite)
603
608
end
604
609
605
610
--- Returns the current nvim tree bufnr
611
+ --- @param callsite string
606
612
--- @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 ]
609
624
end
610
625
611
626
function View :prevent_buffer_override ()
612
627
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 " )
614
629
615
630
-- need to schedule to let the new buffer populate the window
616
631
-- because this event needs to be run on bufWipeout.
0 commit comments