romgrk / barbar.nvim

The neovim tabline plugin.
2.32k stars 84 forks source link

Random error messages when quickly moving tabs #590

Open nonetrix opened 5 months ago

nonetrix commented 5 months ago

Description

When quickly moving tabs you will get a lot of errors randomly, I assume I could just turn these off and ignore them automatically somehow. However, this seems like plugin itself has a bug that causes this in the first place and it should be fixed at the root. Here is a example of one I got quickly dragging tabs with mouse on Kitty

Error executing vim.schedule lua callback: ...yNeovimPackages/start/barbar.nvim/lua/barbar/animate.lua:43: attempt to perform arithmetic on local 'final' (a nil value)                                           
stack traceback:                                                                                                                                                                                                  
        ...yNeovimPackages/start/barbar.nvim/lua/barbar/animate.lua:43: in function 'lerp'                                                                                                                        
        ...ck/myNeovimPackages/start/barbar.nvim/lua/barbar/api.lua:232: in function 'move_buffer_animated_tick'                                                                                                  
        ...ck/myNeovimPackages/start/barbar.nvim/lua/barbar/api.lua:308: in function 'fn'                                                                                                                         
        ...yNeovimPackages/start/barbar.nvim/lua/barbar/animate.lua:59: in function 'animate_tick'                                                                                                                
        ...yNeovimPackages/start/barbar.nvim/lua/barbar/animate.lua:88: in function ''                                                                                                                            
        vim/_editor.lua: in function <vim/_editor.lua:0>

To Reproduce

  1. Quickly drag tabs back and forth quickly for a bit
  2. Observe

init.vim:

It's in Nix sorry :(

{...}: let
  global = import ../global-var.nix;
in {
  home-manager.users.${global.username} = {pkgs, ...}: {
    programs.neovim = {
      enable = true;
      defaultEditor = true;
      extraConfig = ''
        syntax on
        set number relativenumber
        set autoindent
        set tabstop=4
        set ignorecase
        set ttyfast
        set termguicolors
        set expandtab
        set cmdheight=0
      '';

      extraLuaConfig = ''
        vim.cmd.colorscheme "catppuccin"

        require('nvim-tree').setup {
          tab = { sync = { open = true, close = true, ignore = {} } },
        }

        require('lualine').setup {
          options = {
            theme = "catppuccin",
            disabled_filetypes = {
              statusline = {"NvimTree"},
            },
          },
        }

        require'colorizer'.setup {
          filetypes = {
            '*',
          },
        }

        vim.api.nvim_create_autocmd("FileType", {
          pattern = "nix",
          callback = function()
          vim.bo.expandtab = true
          vim.bo.shiftwidth = 2
          vim.bo.tabstop = 2
          vim.bo.softtabstop = 2
        end,
      })

      vim.api.nvim_create_autocmd('TextYankPost', {
        desc = 'Highlight when yanking (copying) text',
        group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
        callback = function()
          vim.highlight.on_yank()
        end,
      })

        require("nvim-autopairs").setup {}
        require("ibl").setup {}

        local function open_nvim_tree()
          -- open the tree
          require("nvim-tree.api").tree.open()
        end

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

        vim.api.nvim_set_keymap('n', '<F2>', ':NvimTreeToggle<CR>', { noremap = true, silent = true })

        if vim.g.neovide then
          vim.o.guifont = "iosevka Nerd Font:h12"
          vim.g.neovide_transparency = 0.9
        end
      '';

      plugins = with pkgs.vimPlugins; [
        catppuccin-nvim
        nvim-tree-lua
        nvim-web-devicons
        barbar-nvim
        lualine-nvim
        nvim-colorizer-lua
        nvim-autopairs
        indent-blankline-nvim
        nvim-treesitter.withAllGrammars
      ];
    };
  };
}

Steps to reproduce the behavior:

  1. Why are you asking me twice?

Screenshots image

Informations (note information is misspelled here in the template, small mistake but I noticed. Best of luck no harm meant:-) ) Neovim version: v0.10.0

nonetrix commented 5 months ago

Note: I am on 165Hz monitor, perhaps it sends mouse events quicker or something? Just a guess

Iron-E commented 5 months ago

Potentially related: #550

nonetrix commented 5 months ago

Luckily doesn't seem to cause many issues, is there way to suppress these errors until a fix?

Iron-E commented 5 months ago

Not a clean one 😅

I'll try to take a look at this soon.

Iron-E commented 4 months ago

Took a quick look at this, just reporting my findings so far (side note: I actually use nix myself, so I was able to drop your config right into mine without hassle!)

I was able to reproduce the issue right away with the config

Edit: I created a minimal repro that works with my config too

--[[ minimal.lua ]]
local lazy = vim.fn.stdpath('data') .. '/lazy/'
vim.opt.rtp:prepend {
  lazy .. 'barbar.nvim',
  lazy .. 'nvim-web-devicons',
}

vim.g.barbar_auto_setup = false
require('barbar').setup {
  -- additional options
}

-- additional code

vim.api.nvim_create_autocmd('VimEnter', {
  callback = vim.schedule_wrap(function()
    -- additional post-startup code
    vim.cmd [[
      for file in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"]
        execute "edit " .. file
      endfor
    ]]
  end),
})

@nonetrix for now setting animate = false in your barbar config should fix it. I'll let you know when we have a real fix

Iron-E commented 4 months ago

I set up some debug logging to inspect this further, and captured the following state here:

{
  current_animation = {
    current = 0,
    duration = 150,
    final = 1,
    fn = <function 1>,
    initial = 0,
    running = true,
    start = 6703368.801163,
    timer = <userdata 1>,
    type = 5
  },
  current_data = {
    closing = false,
    computed_position = 0,
    computed_width = 12,
    diagnostics = { 0, 0, 0, 0 },
    gitsigns = {
      added = 0,
      changed = 0,
      deleted = 0
    },
    moving = false,
    name = "a",
    pinned = false,
    will_close = false
  },
  current_number = 1,
  move_animation_data = {},
  ratio = 0.93393590000148
}

This leads me to believe that the problem is manifesting here, as the move_animation_data is empty (which causes the arithmetic error we see in lerp).

It seems move_animation_data is set just before move_buffer_animated_tick is called right here, which means previous_positions and next_positions must also be nil by this point