romgrk / barbar.nvim

The neovim tabline plugin.
2.26k stars 85 forks source link

Error on session restore when first buffer is terminal #454

Closed maximyurevich closed 1 year ago

maximyurevich commented 1 year ago

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

Iron-E commented 1 year ago

Can I get your nvim-tree config?

maximyurevich commented 1 year ago

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", "", ":NvimTreeFindFileToggle", opts)

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

Iron-E commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

maximyurevich commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thank you for confirming!