mirror of
https://github.com/neovim/neovim.git
synced 2026-08-15 11:59:31 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user