From d80121327fe15663d7f5367f03bb150c748243db Mon Sep 17 00:00:00 2001 From: erdivartanovich Date: Mon, 3 Aug 2026 18:31:15 +0800 Subject: fix(dir): keep a listing buffer when the initial listing fails Problem: A failed initial directory listing discards the listing state: the user is left in an empty modifiable non-listing buffer, and the BufEnter autocmd retries the failing open, repeating the error on every re-entry. Solution: Render the failure as an empty listing with state and handlers intact: the error is reported once and "R" or :edit retries the listing. Keep the error on the listing state so a failed listing is distinguishable from an empty one; the next list clears it. --- runtime/lua/nvim/dir.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'runtime/lua/nvim/dir.lua') diff --git a/runtime/lua/nvim/dir.lua b/runtime/lua/nvim/dir.lua index f8b0b6b2d3..0b60fe4d00 100644 --- a/runtime/lua/nvim/dir.lua +++ b/runtime/lua/nvim/dir.lua @@ -26,6 +26,7 @@ local M = {} ---@class (private) nvim.dir.State ---@field gen integer +---@field err? string ---@field provider? nvim.dir.Provider local listing_group = api.nvim_create_augroup('nvim.dir.listing', { clear = false }) @@ -212,7 +213,8 @@ function load(buf, name, provider, restore_view, setup, select) local list_gen = state.gen + 1 state.gen = list_gen vim.b[buf].nvim_dir = state - -- Discard the listing state if the initial load fails, but preserve an existing listing on reload failure. + -- Render an empty listing (retried by "R" or :edit) if the initial load fails, + -- but preserve an existing listing on reload failure. local first_render = state.provider == nil local done = false @@ -229,10 +231,12 @@ function load(buf, name, provider, restore_view, setup, select) end if err ~= nil then notify_error(err) - if first_render then - close_listing(buf) + if not first_render then + current_state.err = err + vim.b[buf].nvim_dir = current_state + return end - return + entries = {} end ---@cast entries nvim.dir.Entry[] @@ -248,7 +252,7 @@ function load(buf, name, provider, restore_view, setup, select) if select and api.nvim_get_current_buf() == buf then select_entry(select) end - current_state.provider = provider + current_state.err, current_state.provider = err, provider vim.b[buf].nvim_dir = current_state if not setup then -- cgit