akinsho / akinsho/bufferline.nvim

[Bug]: the example Custom Area from the documentation can be improved

Open
#901 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Lua
Stars
4.4k
Forks
240
PR merge metrics
No merged PRs in 30d

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### What happened?

I think [this](https://github.com/akinsho/bufferline.nvim/blob/main/doc/bufferline.txt#L1111) part of documentation which presents an example `custom_areas` definition could be improved.
Currently, this won't create a highlight group for every type of message (error, warning ...), but instead it will create the groups only for the existing entries. Meaning that if there is no error and few warnings, the first hl group will be for warnings. As a result, if the error appears later, it will try to overwrite the hl group of the warning as error and create new group for warning. I think the better approach would be to always return the same length of the section's table:
```lua
custom_areas = {
right = function()
local result = {}
local seve = vim.diagnostic.severity
local error = #vim.diagnostic.get(0, { severity = seve.ERROR })
local warn = #vim.diagnostic.get(0, { severity = seve.WARN })
local info = #vim.diagnostic.get(0, { severity = seve.INFO })
local hint = #vim.diagnostic.get(0, { severity = seve.HINT })

local error_text = ""
if error ~= 0 then
error_text = "  " .. error .. " "
end
table.insert(result, { text = error_text, fg = "#EC5241" })

local warn_text = ""
if warn ~= 0 then
warn_text = "  " .. warn .. " "
end
table.insert(result, { text = warn_text, fg = "#EFB839" })

local hint_text = ""
if hint ~= 0 then
hint_text = " 󱜸 " .. hint .. " "
end
table.insert(result, { text = hint_text , fg = "#A3BA5E" })


local info_text = ""
if info ~= 0 then
info_text = "  " .. info .. " "
end
table.insert(result, { text = info_text, fg = "#7EA9A7" })

return result
end,
}
```

### What did you expect to happen?

proper colors

### Config

.

### Additional Information

...

### commit

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.