nvim-lualine / lualine.nvim

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

Bug: Refresh Settings Ignored #1293

Open kuro337 opened 1 month ago

kuro337 commented 1 month ago

I see the refresh settings are documented here -

It mentions it is not guaranteed but does it not work at all in terms of not applying refreshes?

I want to control the refresh behavior myself so ideally I can disable it - would appreciate any feedback


return {
  {
    'nvim-lualine/lualine.nvim',
    dependencies = { 'nvim-tree/nvim-web-devicons' },
    config = function(_, opts)
      local colors = require('core.ui.colors')

      --- @type LSPClient
      local lsp = {}
      lsp.lsp_name = ''
      lsp.filetype = ''
      lsp.icon = ''
      lsp.color = ''

      local conditions = {
        buffer_not_empty = function() return vim.fn.empty(vim.fn.expand('%:t')) ~= 1 end,
        hide_in_width = function() return vim.fn.winwidth(0) > 80 end,
        check_git_workspace = function()
          local filepath = vim.fn.expand('%:p:h')
          local gitdir = vim.fn.finddir('.git', filepath .. ';')
          return gitdir and #gitdir > 0 and #gitdir < #filepath
        end,
      }

      -- Config
      local config = {
        options = {

          component_separators = '',
          section_separators = '',

          globalstatus = true,
          refresh = { -- sets how often lualine should refresh it's contents (in ms)
            statusline = 20000, -- The refresh option sets minimum time that lualine tries
            tabline = 20000, -- to maintain between refresh. It's not guarantied if situation
            winbar = 20000, -- arises that lualine needs to refresh itself before this time
            -- it'll do it.
          },

          theme = {

            normal = { c = { fg = colors.fg, bg = colors.bg } },
            inactive = { c = { fg = colors.fg, bg = colors.bg } },
          },
          disabled_filetypes = {
            statusline = { 'packer', 'toggleterm', 'term' },
            winbar = { 'packer', 'toggleterm', 'term' },
          },
        },
        ignore_focus = { 'NvimTree' }, -- Add NvimTree here

        sections = {

          lualine_a = {},
          lualine_b = {},
          lualine_y = {},
          lualine_z = {},

          lualine_c = {},
          lualine_x = {},
        },
        inactive_sections = {

          lualine_a = {},
          lualine_b = {},
          lualine_y = {},
          lualine_z = {},
          lualine_c = {},
          lualine_x = {},
        },
      }

      local function ins_left(component) table.insert(config.sections.lualine_c, component) end

      local function ins_right(component) table.insert(config.sections.lualine_x, component) end

      ins_left({
        require('custom.git.diff').git_differ,
        color = { fg = colors.fg, gui = 'bold' }, -- This will be the default color
      })

      ins_left({
        function() return '' end,
        color = { fg = colors.blue }, -- Sets highlighting of component
        padding = { left = 0, right = 0 }, -- We don't need space before this
      })

      ins_left({
        function()
          -- return ' '
          return '  ' .. string.upper(vim.fn.mode())
        end,
        color = function()
          -- auto change color according to neovims mode
          local mode_color = {
            n = colors.red,
            i = colors.green,
            v = colors.blue,
            ['␖'] = colors.blue,
            V = colors.blue,
            c = colors.magenta,
            no = colors.red,
            s = colors.orange,
            S = colors.orange,
            ['␓'] = colors.orange,
            ic = colors.yellow,
            R = colors.violet,
            Rv = colors.violet,
            cv = colors.red,
            ce = colors.red,
            r = colors.cyan,
            rm = colors.cyan,
            ['r?'] = colors.cyan,
            ['!'] = colors.red,
            t = colors.red,
          }
          return { fg = mode_color[vim.fn.mode()] }
        end,
        padding = { right = 1 },
      })

      ins_left({ 'location' })

      ins_left({ 'progress', color = { fg = colors.fg, gui = 'bold' } })

      ins_left({
        require('plugins.lsp.core.diagnostics').get_buf_diag_count,
        color = { fg = colors.fg, gui = 'bold' }, -- This will be the default color
      })

      ins_left({
        function() return '%=' end,
      })

      ins_right({
        function() return require('stream-config').curr_gpt() end,
        color = { fg = colors.teal, gui = 'bold' },
      })

      ins_right({
        function() return require('plugins.lsp.lsp-config').get_lsp_icon(vim.bo.filetype) end,
      })

      ins_right({
        'o:encoding', -- option component same as &encoding in viml
        fmt = string.upper, -- I'm not sure why it's upper case either ;)
        cond = conditions.hide_in_width,
        color = { fg = colors.blue, gui = 'bold' },
      })

      ins_right({
        function() return '▊' end,
        color = { fg = colors.blue },
        padding = { left = 1 },
      })

      require('lualine').setup(config)
    end,
  },
}

But the setting seems to have no effect

kuro337 commented 1 month ago

Trying something along these lines

function M.disable_lualine_autocommands()
  -- Clear autocommands for Lualine's groups
  vim.cmd([[
    augroup lualine_stl_refresh
      autocmd! BufWritePost,BufEnter
    augroup END

    augroup lualine_tal_refresh
      autocmd! BufWritePost,BufEnter
    augroup END

    augroup lualine_wb_refresh
      autocmd! BufWritePost,BufEnter
    augroup END
  ]])
end

But doesn't have to have the desired effect as well - I see these are hardcoded that might be causing the issues?

https://github.com/nvim-lualine/lualine.nvim/blob/544dd1583f9bb27b393f598475c89809c4d5e86b/lua/lualine.lua#L318

-- The events on which lualine redraws itself
local default_refresh_events =
  'WinEnter,BufEnter,BufWritePost,SessionLoadPost,FileChangedShellPost,VimResized,Filetype,CursorMoved,CursorMovedI,ModeChanged'
kuro337 commented 1 month ago

Also is this expected?

I am seeing this -

M.get_hl_diff call rate: 460.00 calls/minute (Total calls: 92, Elapsed time: 0.20 minutes)
M.get_hl_diff call rate: 1191.43 calls/minute (Total calls: 556, Elapsed time: 0.47 minutes)
M.get_hl_diff call rate: 1632.00 calls/minute (Total calls: 1904, Elapsed time: 1.17 minutes)

Every single function in the config is called this frequently?

For people with the diff component for e.g won't that be the plugin makes a git syscall on the filesystem with such high frequency?

Not sure if I am missing any settings or if this is expected - for me currently there seem to be a lot of redundant calls in excess

shadmansaleh commented 1 month ago

It mentions it is not guaranteed but does it not work at all in terms of not applying refreshes?

By it's not guaranteed it means that it can refresh more often based on other factors other than the refresh rate. Basically it'll refresh atleast as often as user-specified refresh rate.

But doesn't have to have the desired effect as well

are you sure you can remove an event from a autocommand like that? I don't think that's a thing. if you want to clear you'd have to clear all of them.

augroup lualine_stl_refresh
     autocmd!
augroup END

Also BufEnter and BufWritePost doesn't get triggered very often. And are quite handy for statusline. I feel like getting triggered by events is better than a refreshrate.

Every single function in the config is called this frequently?

That rate does look suspiciously high. Can you tell me how did you record it?

Also, where is this get_hl_diff ? I'm getting 0 hits with grep.

For people with the diff component for e.g won't that be the plugin makes a git syscall on the filesystem with such high frequency?

The internal diff caches it's result and doesn't actually hit filesystem as too often even if refresh rate is high.