lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
5.09k stars 192 forks source link

Error executing vim.schedule lua callback ... In valid buffer id: 2 #80

Closed olimorris closed 3 years ago

olimorris commented 3 years ago

Describe the bug Pull request #73 (58544f1bc7dc53f36cabd16d6c842a2a0fb7e591) is causing this error for me:

Error executing vim.schedule lua callback: ...e/pack/packer/start/gitsigns.nvim/lua/gitsigns/async.lua:53: ...im/site/pack/packer/start/gitsigns.nvim/lua/gitsigns.lua:126: In
valid buffer id: 2

To Reproduce

To Stop the Bug

init.lua:

utils = require('utils')
---------------------------------- Paths ----------------------------------- {{{
cmd 'set runtimepath+=~/.config/nvim'
cmd 'set runtimepath+=~/.config/nvim/lua'
cmd 'set runtimepath+=~/.config/nvim/after'
cmd 'set runtimepath+=~/.local/share/nvim/site'
cmd 'set runtimepath+=~/.local/share/nvim/site/after'

cmd 'set packpath+=~/.config/nvim'
cmd 'set packpath+=~/.config/nvim/after'
cmd 'set packpath+=~/.local/share/nvim/site'
cmd 'set packpath+=~/.local/share/nvim/site/after'
---------------------------------------------------------------------------- }}}
-- Require Lua files
require('plugins')
require('settings')
require('functions')

-- Set the appearance
colorschemes = {
    light = 'onehalflight',
    dark = 'onedark'
}
SetTheme('dark')

plugins/init.lua:

---------------------------------- INSTALL --------------------------------- {{{
local install_path = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
    cmd ('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
end

cmd 'packadd packer.nvim'
cmd 'autocmd BufWritePost plugins.lua PackerCompile'

local packer = require("packer")
local util = require("packer.util")

local compile_path = util.join_paths(
  fn.stdpath("config"), "plugin", "packer_compiled.vim"
)

---------------------------------------------------------------------------- }}}
---------------------------------- PLUGINS --------------------------------- {{{
function packer_spec()
    use {'wbthomason/packer.nvim', opt = true}

    -- Appearance plugins
    use {'joshdick/onedark.vim' }           -- Theme
    use {'sonph/onehalf', rtp = 'vim' }     -- Theme

    use {
        'romgrk/barbar.nvim',               -- Tabline
        event = {'VimEnter *'},
        config = require('plugins.bufferline').config(),
        requires = {'kyazdani42/nvim-web-devicons', opt = true}
    }
    use {
        'dstein64/nvim-scrollview',         -- Scrollbars in Neovim
        event = {'VimEnter *'}
    }
    use {
        'lewis6991/gitsigns.nvim',          -- Git signs in the signcolumn
        config = function() require('gitsigns').setup() end,
        requires = {'nvim-lua/plenary.nvim'},
    }       
    use {
        'glepnir/galaxyline.nvim',          -- Status line written in Lua
        branch = 'main',
        -- event = {'VimEnter *'},
        requires = {'kyazdani42/nvim-web-devicons', opt = true},
        config = function() require('plugins.statusline') end,
    }
    use {
        'lukas-reineke/indent-blankline.nvim',  -- Show indentation lines
        branch = 'lua',
        event = {'BufReadPre *', 'BufNewFile *'},
        config = require('plugins.indentline').config()
    }

    -- Coding plugins
    use {
        'neovim/nvim-lspconfig',            -- Use native LSP
        setup = require('plugins.lsp').setup(),
        config = require('plugins.lsp').config()
    }
    use {
        'hrsh7th/nvim-compe',               -- Code completion
        event = {'InsertEnter *'},
        config = require('plugins.compe').config(),
        requires = {'norcalli/snippets.nvim'} -- Snippets
    }
    use {'glepnir/lspsaga.nvim'}            -- Async finder, code action, hover docs
    use {'onsails/lspkind-nvim'}            -- VSCode like icons in menu
    use {
        'kosayoda/nvim-lightbulb',          -- Use VSCode lightbulb hint
        config = require('plugins.lightbulb').config()
    }
    use {
        'nvim-treesitter/nvim-treesitter',
        requires = {
            {
                'nvim-treesitter/nvim-treesitter-refactor',
                after = 'nvim-treesitter'
            },
            {
                'nvim-treesitter/nvim-treesitter-textobjects',
                after = 'nvim-treesitter'
            }
        },
        run = ':TSUpdate',
        config = require('plugins.treesitter').config()
    }
    use {'nvim-treesitter/playground'}      -- See the structure for the given file
    use {
        'vim-test/vim-test',                -- Run tests on any type of code base 
        requires = {
            {
                'rcarriga/vim-ultest',      -- Seemless running of tests within neovim
                after = 'vim-test'
            },
            {
                'voldikss/vim-floaterm',    -- Use the terminal in a floating window
                after = 'vim-test'
            }
        },
        config = require('plugins.testing').config()
    }

    -- Misc plugins
    use {'sheerun/vim-polyglot'}            -- Language packs
    use {'tpope/vim-surround'}              -- Use Vim commands within parenthesis and brackets
    use {'alvan/vim-closetag'}              -- Auto close HTML tags
    use {'kassio/neoterm'}                  -- Wrapper for neovim terminal commands and can reuse terminal
    use {'tweekmonster/django-plus.vim'}    -- Django support
    use {'b3nj5m1n/kommentary', config = require('plugins.kommentary').config()}        -- Comment out code
    use {
        'kyazdani42/nvim-tree.lua',         -- File explorer
        setup = require('plugins.nvim_tree').setup(),
        requires = {'kyazdani42/nvim-web-devicons', opt = true}
    }
    use {
        'nvim-telescope/telescope.nvim',    -- Awesome fuzzy finder for everything
        setup = require('plugins.telescope').setup(),
        config = require('plugins.telescope').config(),
        requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}
    }
    use {
        'christoomey/vim-tmux-navigator',   -- Navigate Tmux panes inside of neovim
        cond = function() return os.getenv('TMUX') end,
        setup = function() cmd 'packadd vim-tmux-navigator' end
    }
    use {
        'dhruvasagar/vim-prosession',       -- Easy session switching and also auto-starts sessions
        config = require('plugins.misc').prosession(),
        requires = {'tpope/vim-obsession'}  -- Continuously update session files
    }                                       
    use {'mhinz/vim-startify'}              -- Startup screen for Vim
    use {'dbakker/vim-projectroot'}         -- Detect the project root of a folder
end
---------------------------------------------------------------------------- }}}
packer.startup {
    packer_spec,
}

Supplementary files:

Additional context System: Mac Neovim version: Nightly

lewis6991 commented 3 years ago

Could you minimise the required config and provide some details on how to use procession? The idea of a minimal config is that it shouldn't take much time for the developer to reproduce the issue. Thanks.

olimorris commented 3 years ago

Okay so I isolated the issue further this morning. It seems the event = {'VimEnter *'} next to plugins, alongside procession is what's causing the issue.

Simplified configs:

init.lua

vim.cmd 'set runtimepath+=~/.config/nvim'
vim.cmd 'set runtimepath+=~/.config/nvim/lua'
vim.cmd 'set runtimepath+=~/.config/nvim/after'
vim.cmd 'set runtimepath+=~/.local/share/nvim/site'
vim.cmd 'set runtimepath+=~/.local/share/nvim/site/after'

vim.cmd 'set packpath+=~/.config/nvim'
vim.cmd 'set packpath+=~/.config/nvim/after'
vim.cmd 'set packpath+=~/.local/share/nvim/site'
vim.cmd 'set packpath+=~/.local/share/nvim/site/after'

require('plugins')

plugins.init.lua

vim.cmd('packadd packer.nvim')

local packer = require("packer")

function packer_spec()
    use {'wbthomason/packer.nvim', opt = true}
    use {
        'dstein64/nvim-scrollview',         -- Scrollbars in Neovim
        event = { 'VimEnter *'}
    }
    use {
        'lewis6991/gitsigns.nvim',          -- Git signs in the signcolumn
        config = function() require('gitsigns').setup() end,
        requires = {'nvim-lua/plenary.nvim'},
    }
  use {
        'dhruvasagar/vim-prosession',       -- Easy session switching and also auto-starts sessions
        requires = {'tpope/vim-obsession'}  -- Continuously update session files
    }   
end

packer.startup {
    packer_spec,
}

Removing the event on any plugin, in this case nvim-scrollview, results in the error not occuring. Similarly when vim-prosession is removed, the error doesn't occur. And as stated above, when I roll back to the previous commit, no error.

I should note that in this scenario I have a session already saved that vim-prosession that it autoloads by default

akinsho commented 3 years ago

I was just coming here to report this exact issue as well, I tried looking to see if there was anything in the session file that referenced a buffer id 2, and also checked my buffer list :ls! and there is no buffer with an id of 2. I think the fact that I also consistently get a buffer id 2 error might mean it's coming from something in gitsigns?

The description matches exactly what I'm also experiencing. I've pinned gitsigns to 63ba88f as well as the last point before the error began showing up

lewis6991 commented 3 years ago

I've just recreated the issue and it appears to be because of vim-prosession unloading buffers during gitsigns attach sequence. Should have a fix soon.

lewis6991 commented 3 years ago

I think this is fixed with 133f1aa39f88cb403e4f474473d20db8ff000f58. Not too sure I understand the specifics fully, but it appears to fix things.

akinsho commented 3 years ago

Yep this seems to have resolved the issue for me 👍🏿 thanks

lewis6991 commented 3 years ago

Should be fixed now, please reopen if not.