-
Notifications
You must be signed in to change notification settings - Fork 42
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
functions for statusline components #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I left a few comments (mostly regarding style) in the changes - please let me know what you think.
lua/lsp-status/statusline.lua
Outdated
@@ -97,9 +97,39 @@ local function statusline_lsp(bufnr) | |||
return symbol .. config.indicator_ok .. ' ' | |||
end | |||
|
|||
local function statusline_errors(icon, bufh) | |||
icon = (icon or '✗') .. ' ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer that the fallback icon here come from config
, e.g. config.indicator_errors
. Same comment for the other functions.
lua/lsp-status/statusline.lua
Outdated
return icon .. errors | ||
end | ||
|
||
local function statusline_warnings(icon, bufh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could reduce some code duplication by making a factory function make_statusline_component
, parameterized on a fallback icon and diagnostics key, that returns a function of the form of these new functions. This would also make it easier to add future statusline components (e.g. for info).
These all make sense. I'll work on implementing them. |
@wbthomason this is what I've done so far: local function make_statusline_component(diagnostics_key)
return function(icon, bufh)
bufh = vim.api.nvim_get_current_buf()
local buf_diagnostics = diagnostics(bufh)
local val = buf_diagnostics[diagnostics_key]
return icon .. val
end
end
local M = {
...
errors = make_statusline_component('errors')
}
... Is this along the lines of what you were thinking, or do you think the user should call |
Yep, that's what I was suggesting. Regarding the default icon, I was actually suggesting that the signature of the factory function be more like However, it's also worth noting that, in Lua (without metatable customization), "attributes" and keys are (mostly) identical. That is, |
Of course! I can't believe I didn't think to do that :) I'm having a different issue now: no matter what I do, the |
Ah, that one's on me - since the factory is called at |
It works! |
I don't think we need |
Yep! Sorry, I was unclear - I meant the |
@wbthomason I believe it's in a good spot now, and ready for you to check when you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
I wanted to be able to easily access just the warnings, errors, etc. for a given buffer so I wrote these functions. I think others might find them useful.