Skip to content

refactor(#2826): remove view debug/cc, enable new codepaths for get_winid and get_bufnr #3169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e7ce87
refactor(#2826): fuller error messages
alex-courtis Jun 19, 2025
b7e9789
refactor(#2826): winnr->winid in view/globals, remove redundant get_w…
alex-courtis Jun 19, 2025
d6cd465
refactor(#2826): winnr->winid consistently
alex-courtis Jun 19, 2025
de2ae0b
refactor(#2826): consistent use of buffer registry, tidy, add todos
alex-courtis Jun 19, 2025
414e576
refactor(#2826): remove unnecessary view members float, hide_root_fol…
alex-courtis Jun 19, 2025
f1e9d51
refactor(#2826): remove unused view members centralize_selection and …
alex-courtis Jun 19, 2025
5fbd674
refactor(#2826): remove unused view member height
alex-courtis Jun 19, 2025
3615c7d
refactor(#2826): temporarily reuse BUFNR_PER_TAB in view constructor
alex-courtis Jun 19, 2025
09ec00c
refactor(#2826): get_winid returns new after consistency check
alex-courtis Jun 20, 2025
83fdff7
refactor(#2826): globals.TABPAGES -> WINID_PER_TAB
alex-courtis Jun 20, 2025
e875f15
refactor(#2826): consistent naming of tabid
alex-courtis Jun 20, 2025
d72f85f
refactor(#2826): more consistency checking
alex-courtis Jun 20, 2025
4d6c423
refactor(#2826): more consistency checking
alex-courtis Jun 20, 2025
d84dfad
refactor(#2826): move global CURSORS to view member
alex-courtis Jun 20, 2025
82cc80f
Revert "refactor(#2826): move global CURSORS to view member"
alex-courtis Jun 20, 2025
51b269d
refactor(#2826): move global CURSORS to view member
alex-courtis Jun 20, 2025
0830436
refactor(#2826): consistency check returns new
alex-courtis Jun 20, 2025
fee19f4
Merge branch 'master' into 2826-remove-view-globals
alex-courtis Jun 20, 2025
5737649
Merge branch 'master' into 2826-remove-view-globals
alex-courtis Jul 27, 2025
ec5d41f
Merge branch 'master' into 2826-remove-view-globals
alex-courtis Jul 28, 2025
e6a0385
refactor(#2826): remove consistency checks, enabling new path for vie…
alex-courtis Jul 28, 2025
940deef
refactor(#2826): restore CURSORS global
alex-courtis Jul 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,
Expand Down
4 changes: 1 addition & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,
Expand Down Expand Up @@ -669,7 +668,7 @@ function M.purge_all_state()
local explorer = core.get_explorer()
if explorer then
explorer.view:close_all_tabs()
explorer.view:abandon_all_windows("purge_all_state")
explorer.view:abandon_all_windows()
require("nvim-tree.git").purge_state()
explorer:destroy()
core.reset_explorer()
Expand Down Expand Up @@ -727,7 +726,6 @@ function M.setup(conf)
require("nvim-tree.buffers").setup(opts)
require("nvim-tree.help").setup(opts)
require("nvim-tree.watcher").setup(opts)
require("nvim-tree.multi-instance-debug").setup(opts)

setup_autocommands(opts)

Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local function close_windows(windows)
-- Prevent from closing when the win count equals 1 or 2,
-- where the win to remove could be the last opened.
-- For details see #2503.
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
return
end

Expand All @@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
for _, buf in pairs(bufs) do
if buf.name == absolute_path then
local tree_winnr = vim.api.nvim_get_current_win()
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
vim.api.nvim_set_current_win(buf.windows[1])
vim.cmd(":bn")
end
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
if explorer and not explorer.view.float.quit_on_focus_loss then
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
vim.api.nvim_set_current_win(tree_winnr)
end
if M.config.actions.remove_file.close_window then
Expand Down
12 changes: 6 additions & 6 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local function usable_win_ids()
local explorer = core.get_explorer()
local tabpage = vim.api.nvim_get_current_tabpage()
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
local tree_winid = explorer and explorer.view:get_winnr(tabpage, "open-file.usable_win_ids")
local tree_winid = explorer and explorer.view:get_winid(tabpage)

return vim.tbl_filter(function(id)
local bufid = vim.api.nvim_win_get_buf(id)
Expand Down Expand Up @@ -196,7 +196,7 @@ local function open_file_in_tab(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.open_file_in_tab")
explorer.view:close()
end
end
if M.relative_path then
Expand All @@ -209,7 +209,7 @@ local function drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.drop")
explorer.view:close()
end
end
if M.relative_path then
Expand All @@ -222,7 +222,7 @@ local function tab_drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.tab_drop")
explorer.view:close()
end
end
if M.relative_path then
Expand Down Expand Up @@ -352,7 +352,7 @@ local function open_in_new_window(filename, mode)
end
end

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

if M.quit_on_open and explorer then
explorer.view:close(nil, "open-file.fn")
explorer.view:close()
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/root/change-dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
if should_change_dir() then
cd(M.options.global, foldername)
end
core.init(foldername, "change-dir")
core.init(foldername)
end

if should_open_view then
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/tree/toggle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function M.fn(opts, no_focus, cwd, bang)

if explorer and explorer.view:is_visible() then
-- close
explorer.view:close(nil, "toggle.fn")
explorer.view:close()
else
-- open
lib.open({
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts)
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
if explorer then
explorer.view:close(cur_tabpage, "api.edit " .. mode)
explorer.view:close(cur_tabpage)
end
end

Expand Down
5 changes: 1 addition & 4 deletions lua/nvim-tree/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ local TreeExplorer = nil
local first_init_done = false

---@param foldername string
---@param callsite string
function M.init(foldername, callsite)
function M.init(foldername)
local profile = log.profile_start("core init %s", foldername)

log.line("dev", "core.init(%s, %s)", foldername, callsite)

if TreeExplorer then
TreeExplorer:destroy()
end
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function M.update_coc()

local bufnr
if explorer then
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
bufnr = explorer.view:get_bufnr()
end

local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)
Expand Down
14 changes: 4 additions & 10 deletions lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("WinLeave", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
end
callback = function()
if utils.is_nvim_tree_buf(0) then
self.view:close(nil, "WinLeave")
self.view:close()
end
end,
})
Expand Down Expand Up @@ -172,10 +169,7 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("BufWipeout", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
end
callback = function()
if not utils.is_nvim_tree_buf(0) then
return
end
Expand Down Expand Up @@ -554,7 +548,7 @@ end
---nil on no explorer or invalid view win
---@return integer[]|nil
function Explorer:get_cursor_position()
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
local winnr = self.view:get_winid()
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
return
end
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/explorer/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ local overlay_bufnr = 0
local overlay_winnr = 0

local function remove_overlay(self)
if self.explorer.view.float.enable and self.explorer.view.float.quit_on_focus_loss then
if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
-- return to normal nvim-tree float behaviour when filter window is closed
vim.api.nvim_create_autocmd("WinLeave", {
pattern = "NvimTree_*",
Expand Down Expand Up @@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
end

local function create_overlay(self)
if self.explorer.view.float.enable then
if self.explorer.opts.view.float.enable then
-- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds({
event = "WinLeave",
Expand Down
Loading
Loading