Skip to content

Commit a9156c0

Browse files
authored
refactor(#2826): remove view debug/cc, enable new codepaths for get_winid and get_bufnr (#3169)
* refactor(#2826): fuller error messages * refactor(#2826): winnr->winid in view/globals, remove redundant get_winid and get_bufnr calls * refactor(#2826): winnr->winid consistently * refactor(#2826): consistent use of buffer registry, tidy, add todos * refactor(#2826): remove unnecessary view members float, hide_root_folder; use explorer opts * refactor(#2826): remove unused view members centralize_selection and preserve_window_proportions * refactor(#2826): remove unused view member height * refactor(#2826): temporarily reuse BUFNR_PER_TAB in view constructor * refactor(#2826): get_winid returns new after consistency check * refactor(#2826): globals.TABPAGES -> WINID_PER_TAB * refactor(#2826): consistent naming of tabid * refactor(#2826): more consistency checking * refactor(#2826): more consistency checking * refactor(#2826): move global CURSORS to view member * Revert "refactor(#2826): move global CURSORS to view member" This reverts commit d84dfad. * refactor(#2826): move global CURSORS to view member * refactor(#2826): consistency check returns new * refactor(#2826): remove consistency checks, enabling new path for view get_winid and get_bufnr * refactor(#2826): restore CURSORS global
1 parent 10db694 commit a9156c0

File tree

16 files changed

+157
-422
lines changed

16 files changed

+157
-422
lines changed

doc/nvim-tree-lua.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
639639
},
640640
},
641641
experimental = {
642-
multi_instance = false,
643642
},
644643
log = {
645644
enable = false,

lua/nvim-tree.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
486486
},
487487
},
488488
experimental = {
489-
multi_instance = false,
490489
},
491490
log = {
492491
enable = false,
@@ -669,7 +668,7 @@ function M.purge_all_state()
669668
local explorer = core.get_explorer()
670669
if explorer then
671670
explorer.view:close_all_tabs()
672-
explorer.view:abandon_all_windows("purge_all_state")
671+
explorer.view:abandon_all_windows()
673672
require("nvim-tree.git").purge_state()
674673
explorer:destroy()
675674
core.reset_explorer()
@@ -727,7 +726,6 @@ function M.setup(conf)
727726
require("nvim-tree.buffers").setup(opts)
728727
require("nvim-tree.help").setup(opts)
729728
require("nvim-tree.watcher").setup(opts)
730-
require("nvim-tree.multi-instance-debug").setup(opts)
731729

732730
setup_autocommands(opts)
733731

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local function close_windows(windows)
1818
-- Prevent from closing when the win count equals 1 or 2,
1919
-- where the win to remove could be the last opened.
2020
-- For details see #2503.
21-
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
21+
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
2222
return
2323
end
2424

@@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
3636
for _, buf in pairs(bufs) do
3737
if buf.name == absolute_path then
3838
local tree_winnr = vim.api.nvim_get_current_win()
39-
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
39+
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
4040
vim.api.nvim_set_current_win(buf.windows[1])
4141
vim.cmd(":bn")
4242
end
4343
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
44-
if explorer and not explorer.view.float.quit_on_focus_loss then
44+
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
4545
vim.api.nvim_set_current_win(tree_winnr)
4646
end
4747
if M.config.actions.remove_file.close_window then

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local function usable_win_ids()
2323
local explorer = core.get_explorer()
2424
local tabpage = vim.api.nvim_get_current_tabpage()
2525
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
26-
local tree_winid = explorer and explorer.view:get_winnr(tabpage, "open-file.usable_win_ids")
26+
local tree_winid = explorer and explorer.view:get_winid(tabpage)
2727

2828
return vim.tbl_filter(function(id)
2929
local bufid = vim.api.nvim_win_get_buf(id)
@@ -196,7 +196,7 @@ local function open_file_in_tab(filename)
196196
if M.quit_on_open then
197197
local explorer = core.get_explorer()
198198
if explorer then
199-
explorer.view:close(nil, "open-file.open_file_in_tab")
199+
explorer.view:close()
200200
end
201201
end
202202
if M.relative_path then
@@ -209,7 +209,7 @@ local function drop(filename)
209209
if M.quit_on_open then
210210
local explorer = core.get_explorer()
211211
if explorer then
212-
explorer.view:close(nil, "open-file.drop")
212+
explorer.view:close()
213213
end
214214
end
215215
if M.relative_path then
@@ -222,7 +222,7 @@ local function tab_drop(filename)
222222
if M.quit_on_open then
223223
local explorer = core.get_explorer()
224224
if explorer then
225-
explorer.view:close(nil, "open-file.tab_drop")
225+
explorer.view:close()
226226
end
227227
end
228228
if M.relative_path then
@@ -352,7 +352,7 @@ local function open_in_new_window(filename, mode)
352352
end
353353
end
354354

355-
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.view.float.enable then
355+
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
356356
-- ignore "WinLeave" autocmd on preview
357357
-- because the registered "WinLeave"
358358
-- will kill the floating window immediately
@@ -453,7 +453,7 @@ function M.fn(mode, filename)
453453
end
454454

455455
if M.quit_on_open and explorer then
456-
explorer.view:close(nil, "open-file.fn")
456+
explorer.view:close()
457457
end
458458
end
459459

lua/nvim-tree/actions/root/change-dir.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
8585
if should_change_dir() then
8686
cd(M.options.global, foldername)
8787
end
88-
core.init(foldername, "change-dir")
88+
core.init(foldername)
8989
end
9090

9191
if should_open_view then

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(nil, "toggle.fn")
47+
explorer.view:close()
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, "api.edit " .. mode)
250+
explorer.view:close(cur_tabpage)
251251
end
252252
end
253253

lua/nvim-tree/core.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ local TreeExplorer = nil
99
local first_init_done = false
1010

1111
---@param foldername string
12-
---@param callsite string
13-
function M.init(foldername, callsite)
12+
function M.init(foldername)
1413
local profile = log.profile_start("core init %s", foldername)
1514

16-
log.line("dev", "core.init(%s, %s)", foldername, callsite)
17-
1815
if TreeExplorer then
1916
TreeExplorer:destroy()
2017
end

lua/nvim-tree/diagnostics.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function M.update_coc()
185185

186186
local bufnr
187187
if explorer then
188-
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
188+
bufnr = explorer.view:get_bufnr()
189189
end
190190

191191
local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)

lua/nvim-tree/explorer/init.lua

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ function Explorer:create_autocmds()
105105
vim.api.nvim_create_autocmd("WinLeave", {
106106
group = self.augroup_id,
107107
pattern = "NvimTree_*",
108-
callback = function(data)
109-
if self.opts.experimental.multi_instance then
110-
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
111-
end
108+
callback = function()
112109
if utils.is_nvim_tree_buf(0) then
113-
self.view:close(nil, "WinLeave")
110+
self.view:close()
114111
end
115112
end,
116113
})
@@ -172,10 +169,7 @@ function Explorer:create_autocmds()
172169
vim.api.nvim_create_autocmd("BufWipeout", {
173170
group = self.augroup_id,
174171
pattern = "NvimTree_*",
175-
callback = function(data)
176-
if self.opts.experimental.multi_instance then
177-
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
178-
end
172+
callback = function()
179173
if not utils.is_nvim_tree_buf(0) then
180174
return
181175
end
@@ -554,7 +548,7 @@ end
554548
---nil on no explorer or invalid view win
555549
---@return integer[]|nil
556550
function Explorer:get_cursor_position()
557-
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
551+
local winnr = self.view:get_winid()
558552
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
559553
return
560554
end

0 commit comments

Comments
 (0)