nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.89k stars 459 forks source link

Bug: `searchcount` error on `refresh` after #958 #1004

Closed yavorski closed 1 year ago

yavorski commented 1 year ago

Self Checks

How to reproduce the problem

nvim starts with error after this PR #958. It was working fine without errors before that. It appears that refresh() method is now throwing an error. The reason refresh() is called it is to avoid unwanted flashing in the tabline.

Expected behaviour

Start neovim without error

Actual behaviour

Receiving the following error when starting neovim

packer.nvim: Error running config for lualine.nvim: ...e/nvim/site/pack/packer/opt/lualine.nvim/lua/lualine.lua:432: Error executing lua: .../opt/lualine.nvim/lua/lualine/components/searchcount.lua:23: bad argumen
t #1 to 'min' (number expected, got nil)
stack traceback:
^I[C]: in function 'min'
^I.../opt/lualine.nvim/lua/lualine/components/searchcount.lua:23: in function 'update_status'
^I...e/pack/packer/opt/lualine.nvim/lua/lualine/component.lua:273: in function 'draw'
^I...ck/packer/opt/lualine.nvim/lua/lualine/utils/section.lua:26: in function 'draw_section'
^I...e/nvim/site/pack/packer/opt/lualine.nvim/lua/lualine.lua:173: in function 'statusline'
^I...e/nvim/site/pack/packer/opt/lualine.nvim/lua/lualine.lua:301: in function <...e/nvim/site/pack/packer/opt/lualine.nvim/lua/lualine.lua:282>
^I[C]: in function 'nvim_win_call'
^I...e/nvim/site/pack/packer/opt/lualine.nvim/lua/lualine.lua:432: in function 'refresh'
^I[string "..."]: in function <[string "..."]:0>
^I[C]: in function 'pcall'
^I/home/my-user/.config/nvim/plugin/packer_compiled.lua:65: in function 'try_loadstring'
^I/home/my-user/.config/nvim/plugin/packer_compiled.lua:323: in function </home/my-user/.config/nvim/plugin/packer_compiled.lua:10>
^I[C]: in function 'pcall'

Minimal config to reproduce the issue

-- statusline
use {
  "nvim-lualine/lualine.nvim", -- statusline plugin
  after = "zephyr-nvim", -- init after color scheme in order to prevent any overrides
  requires = {
    { "tiagovla/scope.nvim" }, -- scope buffers to tabs
    { "kyazdani42/nvim-web-devicons", opt = true }, -- use dev icons
    { "whoissethdaniel/lualine-lsp-progress.nvim" }, -- display lsp progress
  },
  config = function()
    require("scope").setup()

    require("lualine").setup({
      options = {
        theme = "onedark",
        icons_enabled = true,
        section_separators = "", -- disable separators
        component_separators = "", -- disable separators
      },
      sections = {
        lualine_a = { "mode" },
        lualine_b = { "branch", "diff", "diagnostics" },
        lualine_c = { "filename", "filesize", "lsp_progress" },
        lualine_x = { "searchcount", "encoding", "fileformat", "filetype" },
        lualine_y = { "progress" },
        lualine_z = { "location" }
      },
      tabline = {
        lualine_a = {{
          "buffers",
          mode = 0, -- shows only buffer name
          icons_enabled = false, -- disable icons for tabline
          show_filename_only = true,
          show_modified_status = true,
          hide_filename_extension = false,
          max_length = vim.o.columns, -- maximum width of buffers component
          symbols = {
            modified = " ^", -- buffer is modified
            directory = "", -- buffer is a directory
            alternate_file = "#", -- text for alternate file
          },
          filetype_names = {
            fzf = "FZF",
            alpha = "Alpha",
            packer = "Packer",
            NvimTree = "NvimTree",
            dashboard = "Dashboard",
            TelescopePrompt = "Telescope",
          },
        }},
        lualine_b = {},
        lualine_c = {},
        lualine_x = {},
        lualine_y = {},
        lualine_z = { "tabs" }
      }
    })

    require("lualine").refresh()
  end
}
Chris1320 commented 1 year ago

This issue also happened to me, and I had to search any string using / to fix it.

Example: /test

After searching, I restarted Neovim and now the error is not thrown. When running on a new Neovim installation, vim.fn.searchcount() returns a vim.empty_dict().


My lualine config

yavorski commented 1 year ago

Nice, Thanks! I confirm it works now as expected after the update.