luukvbaal / statuscol.nvim

Status column plugin that provides a configurable 'statuscolumn' and click handlers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hide signs with lower priorities when using `maxwidth`

przepompownia opened this issue · comments

Branch: 0.10.

I started from explaining myself why do I get displayed two signs with the same priority if I use the example from :h diagnostic-handlers-example and the new foldclosed option. After looking into

for j = 1, ss.maxwidth do
if not sss[lnum][j] or s.priority > sss[lnum][j].priority then
sss[lnum][ss.maxwidth] = nil
table.insert(sss[lnum], j, sign)
if wss.width < j then wss.width = j end
break
end
end
I decreased maxwidth value from 2 to 1 in my config. At the first glance it seemed for me that I can drop using :h diagnostic-handlers-example in this case. It's not because the loop doesn't get the n+1-th sign for the same line if maxwidth = n.

Example independent of foldclosed setting (and maybe 0.10 branch):

local ns = vim.api.nvim_create_namespace('example')
vim.diagnostic.reset(ns, 0)
vim.diagnostic.set(ns, 0, {
  {
    bufnr = 0,
    col = 1,
    lnum = 3,
    message = 'Warn',
    severity = vim.diagnostic.severity.WARN,
  },
  {
    bufnr = 0,
    col = 1,
    lnum = 3,
    message = 'Error',
    severity = vim.diagnostic.severity.ERROR,
  },
})

Simply source it. For me only warning sign is shown:
image

I don't fully understand your issue but we only sort by extmark priority, not diagnostic severity:

:=a.nvim_buf_get_extmarks(0, -1, 0, -1, {type='sign', details=true})
{ { 2, 3, 0, {
      ns_id = 10,
      priority = 10,
      right_gravity = true,
      sign_hl_group = "DiagnosticSignError",
      sign_text = "󰅙 "
    } }, { 1, 3, 0, {
      ns_id = 10,
      priority = 10,
      right_gravity = true,
      sign_hl_group = "DiagnosticSignWarn",
      sign_text = ""
    } } }

I wonder why all diagnostic signs have the same priority, which sign gets shown is random/arbitrary it seems.

Ah, there is a "severity_sort" key in vim.diagnostic.config(), if you set that to true, the highest severity diagnostic sign will show.

Indeed, I didn't pay attention to the difference between the diagnostic severity and sign priority (and (first of all) the existence of severity_sort). That's what I need to get expected sorting:

image

Thanks!