Skip to content

File tree disapears after session reload with persisted.nvim #2217

@marcelarie

Description

@marcelarie

Description

When I close a session with :q! with Nvimtree open, after reloading the session with SessionLoadLast from persisted, the file tree buffer appears empty.

Screenshot 2023-05-18 at 13 19 51

Neovim version

NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.0/share/nvim"

Run :checkhealth for more info

Operating system and version

macOS 12.4

nvim-tree version

736c7ff

Minimal config

local root = "/tmp/persisted"

-- Set stdpaths to use root dir
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- Bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

vim.opt.sessionoptions = "buffers,curdir,folds,globals,tabpages,winpos,winsize" -- Session options to store in the session

-- Install plugins
local plugins = {
  {
    "olimorris/persisted.nvim",
    opts = {
      -- Your custom config here
    }
  },
{ "kyazdani42/nvim-tree.lua" }
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

require("nvim-tree").setup {
	disable_netrw = false,
	hijack_netrw = false,
	hijack_cursor = false,
	update_cwd = false,
	-- update_to_buf_dir = {
	-- 	enable = true,
	-- 	auto_open = true,
	-- },
	diagnostics = {
		enable = false,
		icons = {
			hint = "",
			info = "",
			warning = "",
			error = "",
		},
	},
	update_focused_file = {
		enable = false,
		update_cwd = false,
		ignore_list = {},
	},
	system_open = {
		cmd = nil,
		args = {},
	},
	filters = {
		dotfiles = false,
		custom = {},
	},
	git = {
		enable = false,
		ignore = false,
		timeout = 500,
	},
	-- renderer = {
	-- 	icons = {
	-- 		show = {
	-- 			file = false,
	-- 			folder = false,
	-- 			folder_arrow = true,
	-- 			git = true
	-- 		},
	-- 	},
	-- },
	view = {
		adaptive_size = true,
		width = 40,
		-- height = 30,
		hide_root_folder = false,
		side = "left",
		mappings = {
			custom_only = false,
			list = {},
		},
		number = false,
		relativenumber = true,
	},
	trash = {
		cmd = "trash",
		require_confirm = true,
	},
}

vim.api.nvim_set_keymap(
	"n",
	"<Leader><Tab>",
	":NvimTreeToggle<cr>",
	{ noremap = true, silent = true }
)
-- vim.api.nvim_set_keymap("n", "<Leader>ma", ":set ma<cr>", { noremap = true, silent = true })

vim.cmd "let g:nvim_tree_highlight_opened_files = 1"

local function open_nvim_tree(data)
	-- buffer is a directory
	local directory = vim.fn.isdirectory(data.file) == 1
	if not directory then
		return
	end

	vim.cmd.cd(data.file)

	-- open the file tree
	-- require("nvim-tree.api").tree.open()
	vim.cmd("Ex")
end

vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })

Steps to reproduce

  1. Exit neovim with :q! and nvim tree open
  2. reload the session with SessionLoadLast

Expected behavior

No response

Actual behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions