Closed pianocomposer321 closed 3 years ago
There is no diagnostics section as of right now. I will work on this when #60 is merged.
OK. For now then, how do I get colors set up (red for errors and orange/yellow for warnings)? Currently, this is how it looks:
Also, if it's not implemented yet, should it be taken out of the README.md?
Św
Also, if it's not implemented yet, should it be taken out of the README.md?
Yea it should, thanks for pointing that out
OK. For now then, how do I get colors set up (red for errors and orange/yellow for warnings)? Currently, this is how it looks:
try
:set stastusline=%#LineNr#
Etc
OK. For now then, how do I get colors set up (red for errors and orange/yellow for warnings)? Currently, this is how it looks:
try
:set stastusline = %#LineNr#
Etc
I'm sorry, I don't follow...that command results in an error.
Could you give a more complete example?
In case it's relevant, the way I have it set up is that the format is "E [errors in current buffer]:[total errors] W [warnings in current buffer]:[total warnings]"
set stastusline = %#LineNr#
you are getting error because set command cann't have spaces . Can you provide the function you are using to provide the diagnostics . Then I'll be able to further help you . for now it will be abit complecated . once #61 are merged life will be alot easier to create this kind of components .Also lualine will provide a diagnostic api itself . Not rewuireing to hack it yourself :)
@shadmansaleh how is #54 relevant here? I think it's already merged.
Regarding the diagnostic api, I will work on it when we manage to perfect #60 and #61 . This will happen sooner than later
how is #54 relevant here? I think it's already merged.
My bad I've tagged a wrong pr.
Can you provide the function you are using to provide the diagnostics . Then I'll be able to further help you .
Sure, the reason I didn't before is b/c I was getting some unexpected results (I'm kinda new to lua, so some rules about scope and references vs copies are a bit confusing still). But I think I've got it working now, so here it is:
local function diagnostics()
local errors = 0
local warnings = 0
local cur_buf_errors = 0
local cur_buf_warnings = 0
for _, buffer in ipairs(vim.fn['getbufinfo']()) do -- Loop through buffers
if buffer.listed == 1 and buffer.name ~= '' then -- If the buffer is listed and it is not a no-name buffer
local bufnr = buffer.bufnr
local buf_errors = vim.lsp.diagnostic.get_count(bufnr, [[Error]])
local buf_warnings = vim.lsp.diagnostic.get_count(bufnr, [[Warning]])
errors = errors + buf_errors -- Add this buffer's errors to the total errors
warnings = warnings + buf_warnings -- Same with warnings
if bufnr == vim.fn.bufnr() then -- If this buffer is the currently open buffer
cur_buf_errors = buf_errors
cur_buf_warnings = buf_warnings
end
end
end
if errors ~= 0 or warnings ~= 0 then -- If there is at least one error or warning
return "E "..tostring(cur_buf_errors)..":"..tostring(errors).." W "..tostring(cur_buf_warnings)..":"..tostring(warnings)
else
return '' -- Otherwise return empty string
end
end
function _G.set_lualine_diagnostic_highlights()
vim.cmd('highlight my_hl_warn guifg=Orange guibg=#504945')
vim.cmd('highlight my_hl_error guifg=Red guibg=#504945')
end
vim.cmd('autocmd ColorScheme * :call v:lua.set_lualine_diagnostic_highlights()')
local function diagnostics()
local errors = 0
local warnings = 0
local cur_buf_errors = 0
local cur_buf_warnings = 0
for _, buffer in ipairs(vim.fn['getbufinfo']()) do -- Loop through buffers
if buffer.listed == 1 and buffer.name ~= '' then -- If the buffer is listed and it is not a no-name buffer
local bufnr = buffer.bufnr
local buf_errors = vim.lsp.diagnostic.get_count(bufnr, [[Error]])
local buf_warnings = vim.lsp.diagnostic.get_count(bufnr, [[Warning]])
errors = errors + buf_errors -- Add this buffer's errors to the total errors
warnings = warnings + buf_warnings -- Same with warnings
if bufnr == vim.fn.bufnr() then -- If this buffer is the currently open buffer
cur_buf_errors = buf_errors
cur_buf_warnings = buf_warnings
end
end
end
if errors ~= 0 or warnings ~= 0 then -- If there is at least one error or warning
return "%#my_hl_error# E "..tostring(cur_buf_errors)..":"..tostring(errors).."%#my_hl_warn# W "..tostring(cur_buf_warnings)..":"..tostring(warnings).."%#lualine_b_normal#"
else
return '' -- Otherwise return empty string
end
end
Also you can set the background with guibg and ctermbg. Since you're using gruvbox guibg=#504945 seems like a good choice. If you aren't useing termguicolors you will have to set ctermfg too
For postarity, this is what I ended up with:
I'm likely gonna end up modularizing this a bit more, but for now, here's the gist of it 😉.
@hoob3rt some things I'd like to see change in lualine to make this type of thing easier (I'll open a separate issue for this if you want). I know that this project doesn't have to go the way I want it to, but these are just some suggestions, and I thought I should probably say them before the diagnostic section gets added and it's too late to make suggestions about how it should work.
there should be a section set aside for diagnostics. If it is pre-configured to show diagnostics already, it should be easy to substitute your own function to display them in the format you want.
I think we've decided to make it a genaral component that can be placed in any section.
There should be the ability to add your own sections/components to lualine.
It's posible to add new components now it will be expanded with #53 .
The problem with just adding a new function to existing sections is that it adds the separator between things, which messes up coloring (I'll attach a screenshot if you don't understand what I mean).
It shouldn't put a separator if it's returnes from same function . I'd love to see the screenshot please share it.
You can add suggetions to #38 that's where diagnostics is being discussed.
It shouldn't put a separator if it's returnes from same function . I'd love to see the screenshot please share it.
It doesn't return from the same function...here's the part of my config where it's added to the statusline (note that this has been modified since I posted the gist):
lualine.sections.lualine_z = vim.list_extend(lualine.sections.lualine_z, {
function()
local count = get_count()
return diagnostics(count, {"", ""})
end
})
Here's a gist of the full config: https://gist.github.com/pianocomposer321/1383f082ee1a41ab2cbd90d17d6534f3
It doesn't return from the same function...here's the part of my config where it's added to the statusline
I get it now it's the separators between components. I thought you ment seperators inside a component. I think it looks bad because of the padding that is automaticaly added to components.
It doesn't return from the same function...here's the part of my config where it's added to the statusline
I get it now it's the separators between components. I thought you ment seperators inside a component. I think it looks bad because of the padding that is automaticaly added to components.
Yep, I'm pretty sure that's the problem.
For now since you want to have it in the end . You can just append it to statusline. Make your diagnostics function global and add this inplace of lualine.status() call
lualine.status()
vim.cmd("autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.set_active_statusline(1)..v:lua.diagnostics()")
Also remove diagnostics from z section. See if you like that better :)
Works great, thanks. Will do until this functionality gets added to lualine natively.
@hoob3rt @shadmansaleh Should this issue be close, or left open b/c lualine_diagnostics isn't implemented yet?
Yeah, no point of having it open. I'm glad @shadmansaleh helped you implement the functionality you wanted. I will try to remember to tag you here when diagnostics is implemented natively
snippet from my lualine config file:
but nothing changes in my status line. If I set a different sections to my diagnostics function, it works as expected. But nothing shows when I set the
lualine_diagnostics
section.