Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on session restore when first buffer is terminal #454

Closed
maximyurevich opened this issue Apr 10, 2023 · 9 comments
Closed

Error on session restore when first buffer is terminal #454

maximyurevich opened this issue Apr 10, 2023 · 9 comments
Labels
bug Something isn't working
Milestone

Comments

@maximyurevich
Copy link

Description

I get error on session restore when first buffer is terminal

To Reproduce

local status_ok, barbar = pcall(require, "barbar")
if not status_ok then
	return
end

vim.g.barbar_auto_setup = false

barbar.setup({
	animation = false,
	auto_hide = true,
	tabpages = true,
	clickable = true,
	sidebar_filetypes = {
		NvimTree = true,
	},
})

Steps to reproduce the behavior:

  1. nvim .
  2. :ter
  3. :q
  4. nvim

Screenshots
NFS0cwG
sHmGUyR

Informations
Neovim version: 0.9

@maximyurevich maximyurevich changed the title Error when session restore when first buffer is terminal Error on session restore when first buffer is terminal Apr 10, 2023
@Iron-E Iron-E added the bug Something isn't working label Apr 10, 2023
@Iron-E Iron-E added this to the 1.6 milestone Apr 10, 2023
@Iron-E
Copy link
Collaborator

Iron-E commented Apr 10, 2023

Can I get your nvim-tree config?

@maximyurevich
Copy link
Author

Can I get your nvim-tree config?

local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
	return
end

local opts = { noremap = true, silent = true }

nvim_tree.setup()

local function open_nvim_tree(data)
	local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
	local directory = vim.fn.isdirectory(data.file) == 1
	if not no_name and not directory then
		return
	end
	if directory then
		vim.cmd.cd(data.file)
	end
	require("nvim-tree.api").tree.open()
end

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

vim.keymap.set("n", "<C-f>", ":NvimTreeFindFileToggle<CR>", opts)

vim.keymap.set(
	"n",
	"<C-t>",
	":lua require('nvim-tree.api').tree.toggle(false, true)<cr>",
	opts
)

@Iron-E
Copy link
Collaborator

Iron-E commented Apr 11, 2023

I created a minimal lua file (I added our session integration feature to your config):

require'barbar'.setup {sidebar_filetypes = {NvimTree = true}}

require'nvim-tree'.setup {}

vim.api.nvim_create_autocmd({'VimEnter'}, {callback = function(event)
  local no_name = event.file == "" and vim.bo[event.buf].buftype == ""
  local directory = vim.fn.isdirectory(event.file) == 1

  if not no_name and not directory then
    return
  end

  if directory then
    vim.cmd.cd(event.file)
  end

  require("nvim-tree.api").tree.open()
end})

vim.opt.sessionoptions:append 'globals'
vim.api.nvim_create_user_command(
  'Mksession',
  function(attr)
    vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'})
    vim.cmd.mksession {bang = attr.bang, args = attr.fargs}
  end,
  {bang = true, complete = 'file', desc = 'Save barbar with :mksession', nargs = '?'}
)

Then ran:

nvim --clean  \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/barbar.nvim' \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/nvim-tree.lua' \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/nvim-web-devicons' \
     -u minimal.lua

Then did your steps from above (i.e. :term, :Mksession foo.vim, :q), then ran the same nvim --clean command form before but with -S foo.vim at the end, and got no error.

What session manager plugin are you using? Can you share your config for that?

@maximyurevich
Copy link
Author

I created a minimal lua file (I added our session integration feature to your config):

require'barbar'.setup {sidebar_filetypes = {NvimTree = true}}

require'nvim-tree'.setup {}

vim.api.nvim_create_autocmd({'VimEnter'}, {callback = function(event)
  local no_name = event.file == "" and vim.bo[event.buf].buftype == ""
  local directory = vim.fn.isdirectory(event.file) == 1

  if not no_name and not directory then
    return
  end

  if directory then
    vim.cmd.cd(event.file)
  end

  require("nvim-tree.api").tree.open()
end})

vim.opt.sessionoptions:append 'globals'
vim.api.nvim_create_user_command(
  'Mksession',
  function(attr)
    vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'})
    vim.cmd.mksession {bang = attr.bang, args = attr.fargs}
  end,
  {bang = true, complete = 'file', desc = 'Save barbar with :mksession', nargs = '?'}
)

Then ran:

nvim --clean  \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/barbar.nvim' \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/nvim-tree.lua' \
     --cmd 'set rtp+=~/.local/share/nvim/lazy/nvim-web-devicons' \
     -u minimal.lua

Then did your steps from above (i.e. :term, :Mksession foo.vim, :q), then ran the same nvim --clean command form before but with -S foo.vim at the end, and got no error.

What session manager plugin are you using? Can you share your config for that?

nvim-session-manager

@Iron-E
Copy link
Collaborator

Iron-E commented Apr 11, 2023

Do you use any particular config options for nvim-session-manager?

@maximyurevich
Copy link
Author

maximyurevich commented Apr 11, 2023

Do you use any particular config options for nvim-session-manager?

local Path = require("plenary.path")

local status_ok, session_manager = pcall(require, "session_manager")
if not status_ok then
	return
end

session_manager.setup({
	sessions_dir = Path:new(vim.fn.stdpath("data"), "sessions"), -- The directory where the session files will be saved.
	path_replacer = "__", -- The character to which the path separator will be replaced for session files.
	colon_replacer = "++", -- The character to which the colon symbol will be replaced for session files.
	autoload_mode = require("session_manager.config").AutoloadMode.LastSession, -- Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession
	autosave_last_session = true, -- Automatically save last session on exit and on session switch.
	autosave_ignore_not_normal = true, -- Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed.
	autosave_ignore_dirs = {}, -- A list of directories where the session will not be autosaved.
	autosave_ignore_filetypes = { -- All buffers of these file types will be closed before the session is saved.
		"gitcommit",
	},
	autosave_ignore_buftypes = {}, -- All buffers of these bufer types will be closed before the session is saved.
	autosave_only_in_session = false, -- Always autosaves session. If true, only autosaves after a session is active.
	max_path_length = 80, -- Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all.
})

@Iron-E
Copy link
Collaborator

Iron-E commented Apr 13, 2023

Does the latest commit fix the issue? I was never able to reproduce, but I just fixed something similar. If not, I have a few ideas.

@maximyurevich
Copy link
Author

Does the latest commit fix the issue? I was never able to reproduce, but I just fixed something similar. If not, I have a few ideas.

yes

@Iron-E
Copy link
Collaborator

Iron-E commented Apr 13, 2023

Thank you for confirming!

@Iron-E Iron-E closed this as completed Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants