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

Bug: Refresh Settings Ignored #1293

Open
kuro337 opened this issue Aug 10, 2024 · 4 comments
Open

Bug: Refresh Settings Ignored #1293

kuro337 opened this issue Aug 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@kuro337
Copy link

kuro337 commented Aug 10, 2024

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 kuro337 added the bug Something isn't working label Aug 10, 2024
@kuro337
Copy link
Author

kuro337 commented Aug 10, 2024

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?

local function refresh(opts)

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

@kuro337
Copy link
Author

kuro337 commented Aug 10, 2024

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
Copy link
Member

shadmansaleh commented Aug 12, 2024

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.

@sebszyller
Copy link

sebszyller commented Sep 24, 2024

I think I've observed a concrete bug that falls under this.
Everyone's favourite cmdheight=0 /s

I use a very minimal lualine setup where I only display the filename, branch, macro status and attached lsps. So there're only a few events where it refreshes. Crucially, I don't display the mode.
In my case, lualine disappears when I enter insert mode, when cmdheight=0. It reappears when I type the first character.
When I say disappears I suspect that neovim is actually drawing an empty line on top of lualine.

Currently, I can fix it either by 1) adding "mode" to lualine which I suspect forces it to refresh the string it displays or 2) just not using cmdheight=0. Neither of which is ideal because there's clearly a bug either in lualine or, again, in how cmdheight is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants