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

Fix to not try to save a deleted buffer #42

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

dkotvan
Copy link

@dkotvan dkotvan commented Aug 7, 2022

Sometimes the buffer can be deleted before being saved, like the input
dialog the NvimTree creates when renaming or creating a file

Add a check in debounce to verify if the buffer is still valid before
trying to save

Minimal configuration to reproduce the error

local execute = vim.api.nvim_command
local fn = vim.fn

local install_path = fn.stdpath('data') .. '/site/minimal_pack/minimal_packer/start/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
  fn.system({ 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path })
  execute 'packadd packer.nvim'
end

return require("packer").startup {
  function(use)
    use { 'wbthomason/packer.nvim' }

    use {
      'kyazdani42/nvim-tree.lua',
      requires = { 'kyazdani42/nvim-web-devicons'},
      config = function()
        require 'nvim-tree'.setup {
          disable_netrw = false,
          hijack_netrw  = true,
        }
      end
    }

    use { "Pocco81/auto-save.nvim" }
  end
}

Steps:

1 - Open NvimTree ( e.g. using :NvimTreeToggle )
2 - Press ato open the dialog to create a new file
3 -After saving the error:

Error executing vim.schedule lua callback: ...nimal-packer/start/auto-save.nvim/lua/auto-save/init.lua:27: Invalid buffer id: 4
stack traceback:
        [C]: in function 'nvim_buf_set_var'
        ...nimal-packer/start/auto-save.nvim/lua/auto-save/init.lua:27: in function 'set_buf_var'
        ...nimal-packer/start/auto-save.nvim/lua/auto-save/init.lua:44: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Sometimes the buffer can be deleted before being saved, like the input
dialog the NvimTree creates when renaming or creating a file

Add a check in debounce to verify if the buffer is still valid before
trying to save
@pocco81 pocco81 changed the base branch from main to dev August 9, 2022 03:37
@pocco81 pocco81 merged commit 9aceacf into pocco81:dev Aug 9, 2022
@pocco81
Copy link
Owner

pocco81 commented Aug 9, 2022

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants