MunifTanjim / nougat.nvim

🍫 Hyperextensible Statusline / Tabline / Winbar for Neovim 🚀
MIT License
197 stars 3 forks source link

Stack trace for type mismatch #45

Closed dsully closed 10 months ago

dsully commented 10 months ago
E5108: Error executing lua Error executing lua: ...cal/share/nvim/lazy/nougat.nvim/lua/nougat/item/init.lua:117: attempt to index local 'cache' (a function value)
stack traceback:
    ...cal/share/nvim/lazy/nougat.nvim/lua/nougat/item/init.lua:117: in function 'item'
    /Users/dsully/.config/nvim/lua/plugins/nougat.lua:156: in function 'content'
    ...y/.local/share/nvim/lazy/nougat.nvim/lua/nougat/util.lua:388: in function 'prepare_parts'
    ...ocal/share/nvim/lazy/nougat.nvim/lua/nougat/bar/init.lua:118: in function 'generate'
    ...ocal/share/nvim/lazy/nougat.nvim/lua/nougat/bar/util.lua:19: in function <...ocal/share/nvim/lazy/nougat.nvim/lua/nougat/bar/util.lua:17>
    [C]: at 0x0100ec0e38
stack traceback:
    [C]: at 0x0100ec0e38

This started happening with change https://github.com/MunifTanjim/nougat.nvim/commit/dba049fe50b2b3b07f446e66e6159b663650ee63 or more likely https://github.com/MunifTanjim/nougat.nvim/commit/45cc6e6ac8fb562ce3304c68041d655d9a4930c3 which started using the cache.

MunifTanjim commented 10 months ago

How are you configuring the Git Branch for your statusbar? 🤔

MunifTanjim commented 10 months ago

You shouldn't create new item inside the content function.

https://github.com/dsully/nvim/blob/a8c02cfc2201b6489dc0d839a3a930320bca6611/lua/plugins/nougat.lua#L152-L164

If content is a function it will be called each time statusbar is evaluated.

Try doing something like this instead.

        local git_status = require("nougat.nut.git.branch").create({
          config = { provider = "gitsigns" },
          hl = { bg = colors.bg0, fg = colors.white.base },
          prefix = "  ",
          sep_left = sep.left_lower_triangle_solid(true),
          suffix = " ",
        })
        statusline:add_item({
            content = {
              white_left_lower_triangle,
              git_status,
            },
            hidden = function()
                return not vim.g.gitsigns_head
            end,
        })
dsully commented 10 months ago

Thanks - that fixed the issue. Can you see if there is any more that should be changed?

https://github.com/dsully/nvim/blob/main/lua/plugins/nougat.lua

It seems that dynamic items like navic should continue to be in content = function() wrapper, correct?

MunifTanjim commented 10 months ago

You can check the usage patterns in here: https://github.com/MunifTanjim/nougat.nvim/tree/main/examples

It seems that dynamic items like navic should continue to be in content = function() wrapper, correct?

Yes, you can set content to a function when you need it. But do not create a new item inside content function. From the content function you can return:

From the above example (https://github.com/MunifTanjim/nougat.nvim/issues/45#issuecomment-1810054847), both of these will do the same thing:

statusline:add_item({
  content = {
    white_left_lower_triangle,
    git_status,
  },
)}
statusline:add_item({
  content = function()
    return {
      white_left_lower_triangle,
      git_status,
    }
  end,
)}

But with the first one is faster than the second one.