NTBBloodbath / galaxyline.nvim

neovim statusline plugin written in lua
MIT License
163 stars 16 forks source link

Error on each redraw when an LSP is active. #29

Closed WhyNotHugo closed 2 years ago

WhyNotHugo commented 2 years ago

When opening any file with diagnostics, I'm seeing this error:

^I...ite/pack/packer/start/galaxyline.nvim/lua/galaxyline.lua:2...<...ite/pack/packer/start/galaxyline.nvim/lua/galaxyline.lua:24>
E15: Invalid expression: luaeval('require("galaxyline").component_decorator')("DiagnosticHint")
Press ENTER or type command to continue

Bisection indicates that 3b9d3f0b4592168baefa5838d943963336bc6a40 introduced this regression.

I'm not sure how to get the full error output though; the above is probably not helpful enough.

WhyNotHugo commented 2 years ago

Relevant config: https://git.sr.ht/~whynothugo/dotfiles/tree/main/item/home/.config/nvim/lua/_galaxyline.lua

fenetikm commented 2 years ago

I had a similar thing happening for me and it was because get_diagnostic was returning a nil and I wasn't handling that correctly - in my case I was trying to concat it.

WhyNotHugo commented 2 years ago

I had a similar thing happening for me and it was because get_diagnostic was returning a nil and I wasn't handling that correctly - in my case I was trying to concat it.

This PR explicitly changed the API to always return a number (in my case, I display info + hint). This was merged into this fork at some point, though history was squashed.

Upon looking closer at the above commit, it seems it broke this expectation; these methods now return a string, and integer or nil, which is really hard to work with since it requires handling and casting all scenarios any place these are called.

Given that it has [AFAIK] no functional changes, maybe it's best to just revert it?

Actually, it seems this was partially broken before, but it's only this particular commit that affects my own setup.

WhyNotHugo commented 2 years ago

Oh, there were two issues, one in my local config, and another in the above commit. My local code had to be updated with:

 -- Return the formatted sum of INFO and HINT diagnostics.
 ---@return string
 local function get_diagnostic_info()
   local count = 0
-  for _, type in ipairs({ "Hint", "Information" }) do
+  for _, type in ipairs({ vim.diagnostic.severity.HINT, vim.diagnostic.severity.INFO }) do
     count = count + diagnostic.get_diagnostic(type)
   end