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

BUG: Buffer with this name already exists #1365

Open
3 tasks done
SparrowMike opened this issue Feb 27, 2024 · 13 comments
Open
3 tasks done

BUG: Buffer with this name already exists #1365

SparrowMike opened this issue Feb 27, 2024 · 13 comments
Assignees
Labels
bug Something isn't working working-on-it
Milestone

Comments

@SparrowMike
Copy link

SparrowMike commented Feb 27, 2024

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

Neovim Version (nvim -v)

NVIM v0.9.5

Operating System / Version

macOS - 14.2.1

Describe the Bug

When loading into a previous session that had neo-tree enabled I simply get the a blank window, whenever I toggle the neo-tree I get another blank window followed by a error:

[Neo-tree ERROR] debounce filesystem_navigate error: ...are/nvim/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:1045: Vim:E95: Buffer with this name already exists

I believe the issue has something to do with auto-sessions as disabling it makes the problem go away.

Screenshots, Traceback

The first image is loading into a session and the blank window on the right is what I think should be the neo-tree
Screenshot 2024-02-27 at 9 52 11 PM

At the bottom of the screen the error can be seen - it was triggered by the hotkey that I used to enable the neo-tree window, there is also an additional window, I believe this is where neo-tree tries to load into but its buffer already exists?
Screenshot 2024-02-27 at 9 52 37 PM

Steps to Reproduce

  1. neo-tree and auto-session plugin installed
  2. open any project, have some files open as well as neo-tree enabled
  3. close session with some file and neo-tree enabled
  4. open up the session

Expected Behavior

No errors?

Your Configuration

My neo-tree
{
    "nvim-neo-tree/neo-tree.nvim",
    branch = "v3.x",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
        "MunifTanjim/nui.nvim",
        -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information
        -- {
        "s1n7ax/nvim-window-picker",
        version = "2.*",
        config = function()
            require("window-picker").setup({
                filter_rules = {
                    include_current_win = false,
                    autoselect_one = true,
                    -- filter using buffer options
                    bo = {
                        -- if the file type is one of following, the window will be ignored
                        filetype = { "neo-tree", "neo-tree-popup", "notify" },
                        -- if the buffer type is one of following, the window will be ignored
                        buftype = { "terminal", "quickfix" },
                    },
                },
            })
        end,
    },
    config = function()
        local config = require("neo-tree")
        config.setup({
            event_handlers = {
                {
                    event = "neo_tree_buffer_enter",
                    handler = function(arg)
                        vim.cmd([[setlocal relativenumber]])
                    end,
                },
            },
            window = {
                position = "right",
            },
            filesystem = {
                follow_current_file = {
                    enabled = false, -- This will find and focus the file in the active buffer every time
                },
                filtered_items = {
                    hide_dotfiles = false,
                },
            },
        })

        vim.keymap.set("n", "<C-B>", ":Neotree source=filesystem toggle position=right<CR>")
        vim.keymap.set("n", "<C-G>", ":Neotree float git_status<CR>")
    end,
}


auto-session
{
        'rmagatti/auto-session',
        config = function()
            require("auto-session").setup {
                log_level = "error",
                auto_session_suppress_dirs = { "~/", "~/Projects", "~/Downloads", "/"},
            }
        end
    }
@SparrowMike SparrowMike added the bug Something isn't working label Feb 27, 2024
@pysan3
Copy link
Collaborator

pysan3 commented Feb 27, 2024

Please revise your config. I think you pasted neo-tree config twice.

Also please update the issue title like other issues.

@SparrowMike SparrowMike changed the title BUG: BUG: Buffer with this name already exists Feb 27, 2024
@SparrowMike
Copy link
Author

Thanks @pysan3, that was fast! Hopefully all is clear now.

@josephcrawfordSRH
Copy link

josephcrawfordSRH commented Feb 27, 2024

I am also seeing this issue. I am simply using LazyVim without any modifications to the neo-tree configuration and the auto-session plugin with the following configuration.

return {
  "rmagatti/auto-session",
  config = function()
    require("auto-session").setup({
      auto_session_last_session_dir = vim.fn.stdpath("data") .. "/sessions/",
      auto_session_root_dir = vim.fn.stdpath("data") .. "/sessions/",
      auto_session_enabled = true,
      log_level = vim.log.levels.ERROR,
      auto_session_suppress_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
      auto_save_enabled = true,
      auto_session_create_enabled = true,
      session_lens = {
        buftypes_to_ignore = {},
        load_on_setup = true,
        theme_conf = { border = true },
        previewer = false,
      },
    })

    vim.keymap.set("n", "<leader>ls", require("auto-session.session-lens").search_session, {
      noremap = true,
    })
  end,
}

I have also seen other issues where if I use the pre_restore_cmds = { "Neotree close", "Neotree focus" } when i switch projects it opens Neotree full screen. I have been trying to get the auto-session plugin to work with neo-tree for a few days now without any success. What I would like to see is that when I jump sessions the tree is open at the current session directory.

AutoSessions does have an example of how to make it work with nvim-tree in their README but I am unsure how I can make this work with neo-tree

local function restore_nvim_tree()
    local nvim_tree = require('nvim-tree')
    nvim_tree.change_dir(vim.fn.getcwd())
    nvim_tree.refresh()
end

require('auto-session').setup {
    pre_restore_cmds = {restore_nvim_tree}
}

@pysan3
Copy link
Collaborator

pysan3 commented Feb 27, 2024

Could you test this option and see if it works?

#779

@SparrowMike
Copy link
Author

SparrowMike commented Feb 28, 2024

Could you test this option and see if it works?

#779

Thanks @pysan3, adding auto_clean_after_session_restore = true kinda solved the problem, but at the same time introduce another.

Basically what happens now is - if neo-tree was open in previous sessions, after reopening nvim its pane gets simply closed (this can be seen in action for a split second).

Feb-28-2024 10-24-43

It would be nice to still keep the neo-tree open if that was the case in the previous session, however I'm ok with this solution for now, I guess next step would be to explore auto-session readme as mentioned by @josephcrawfordSRH, unless some additional configuration could be added on neo-tree side?

@pysan3
Copy link
Collaborator

pysan3 commented Feb 28, 2024

@SparrowMike Thanks for testing!

Unfortunately no, there is no way to auto-restore neo-tree state since we can adjust the position (left, right etc) and source (filesystem, buffers etc) dynamically, we cannot tell which and where neo-tree was with only the buffer name (and this is the only clue autosession will restore for us).

Spoiler alert, I will make it possible with the new re-write.

@pysan3
Copy link
Collaborator

pysan3 commented Feb 28, 2024

EDIT: please see #1366 (comment) instead. Below is old info so plz ignore.


Nah just do it now lol.

#1366

Could you test it out? @SparrowMike

return {
  "pysan3/neo-tree.nvim",
  branch = "restore-session-experimental",
  version = false,
  opts = {
    auto_restore_session_experimental = true,
    -- ...

Caution:

You need to have blank set to sessionoptions like it is said here.
https://github.com/rmagatti/auto-session?tab=readme-ov-file#recommended-sessionoptions-config

For the case of vimscript, set sessionoptions+=blank. Idk much about lua.

Caution2:

It will be wonky (or not work at all) when you set the default neo-tree position to float or current.

Caution3:

If you had more than one neo-tree sources opened, only one of them will be respected, with filesystem being most prioritized.

@pysan3 pysan3 added this to the v4.0 milestone Feb 28, 2024
@SparrowMike
Copy link
Author

Thanks @pysan3 for going extra mile, I followed all the steps as described however the results are the same.

I will give it another go on my other machine at home, will let you know if results are different.

cheers!

@josephcrawfordSRH
Copy link

I am still seeing quite a few issues here, I am attaching a screen recording. Notice that sometimes neo-tree opens full screen, other times it opens but the cwd is from the previous project. Also notice there are tabs open for the session directory and sometimes [No Name].

This is my config for neo-tree, outside of using the default implementation from LazyVim

return {
  "nvim-neo-tree/neo-tree.nvim",
  opts = {
    auto_clean_after_session_restore = false,
  },
}

This is my auto-session configuration

return {
  "rmagatti/auto-session",
  config = function()
    require("auto-session").setup({
      auto_session_last_session_dir = vim.fn.stdpath("data") .. "/sessions/",
      auto_session_root_dir = vim.fn.stdpath("data") .. "/sessions/",
      auto_session_enabled = true,
      log_level = vim.log.levels.ERROR,
      auto_session_suppress_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
      auto_save_enabled = true,
      auto_session_create_enabled = true,
      session_lens = {
        buftypes_to_ignore = {},
        load_on_setup = true,
        theme_conf = { border = true },
        previewer = false,
      },
    })

    vim.keymap.set("n", "<leader>ls", require("auto-session.session-lens").search_session, {
      noremap = true,
    })
  end,
}

@josephcrawfordSRH
Copy link

Screen.Recording.2024-02-28.at.9.16.04.AM.mp4

@pysan3
Copy link
Collaborator

pysan3 commented Feb 28, 2024

@josephcrawfordSRH

Thanks for testing but you should switch the repo to my fork and change the branch name.

You are testing nothing as this has not yet landed to neo-tree's main branch...

return {
  "pysan3/neo-tree.nvim",
  branch = "restore-session-experimental",
  version = false,
  opts = {
    auto_restore_session_experimental = true,
    -- ...

And could you move a bit more slowly, or please describe what you are doing.

Your screen capture is just flashing and constantly moving that I cannot tell what and what not you are testing...

@pysan3
Copy link
Collaborator

pysan3 commented Feb 28, 2024

@josephcrawfordSRH

May I ask you to give me your feedbacks in this thread next time?

#1366

@josephcrawfordSRH
Copy link

@pysan3 apologies, I will use that thread from now on. I will also make a new screen recording slowing things down so that you can see what i am doing. I will also test using your fork and branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working working-on-it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants