diff options
| author | erdivartanovich <erdivartanovich@gmail.com> | 2026-08-03 18:31:15 +0800 |
|---|---|---|
| committer | erdivartanovich <erdivartanovich@gmail.com> | 2026-08-04 01:57:21 +0800 |
| commit | d80121327fe15663d7f5367f03bb150c748243db (patch) | |
| tree | 05a89261c357a0907423e97e2ccf692e9a97bc10 /runtime/lua/nvim/dir.lua | |
| parent | a3eff66e313b89cf721ad70ea34c41b7425200c1 (diff) | |
| download | rneovim-d80121327fe15663d7f5367f03bb150c748243db.tar.gz rneovim-d80121327fe15663d7f5367f03bb150c748243db.tar.bz2 rneovim-d80121327fe15663d7f5367f03bb150c748243db.zip | |
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.
Diffstat (limited to 'runtime/lua/nvim/dir.lua')
| -rw-r--r-- | runtime/lua/nvim/dir.lua | 14 |
1 files changed, 9 insertions, 5 deletions
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 |