Skip to content

Commit 742aba4

Browse files
committed
fix: work around bufloaded issue when neovim is killed (#49)
1 parent 4ce2266 commit 742aba4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lua/resession/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,15 @@ local function save(name, opts, target_tabpage)
239239
tabpage_bufs[bufnr] = true
240240
end
241241
end
242+
local is_unexpected_exit = vim.v.exiting ~= vim.NIL and vim.v.exiting > 0
242243
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
243244
if util.include_buf(target_tabpage, bufnr, tabpage_bufs) then
244245
local buf = {
245246
name = vim.api.nvim_buf_get_name(bufnr),
246-
loaded = vim.api.nvim_buf_is_loaded(bufnr),
247+
-- if neovim quit unexpectedly, all buffers will appear as unloaded.
248+
-- As a hack, we just assume that all of them were loaded, to avoid all of them being
249+
-- *unloaded* when the session is restored.
250+
loaded = is_unexpected_exit or vim.api.nvim_buf_is_loaded(bufnr),
247251
options = util.save_buf_options(bufnr),
248252
last_pos = vim.api.nvim_buf_get_mark(bufnr, '"'),
249253
}

0 commit comments

Comments
 (0)