dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.55k stars 1.43k forks source link

Wishlist: single counter for errors and warnings in the statusline #323

Closed mgedmin closed 7 years ago

mgedmin commented 7 years ago

My statusline is cluttered, so I'd prefer to see one counter showing the number of errors plus warnings, rather than two separate numbers.

I'm currently using

let g:ale_statusline_format = ['{%d}', '{%d}', '']

to save space, which means I get to look at {1}{1} when there's one error and one warning. I'd like there to be an option that would let me see just {2}.

w0rp commented 7 years ago

I tried to come up with some kind of formatting option which would support the following, all at once:

  1. Outputting numbers with arbitrary placement.
  2. Removing numbers when they are 0... OR
  3. Allowing numbers to appear as 0 when they are at 0.
  4. Setting a message for when there are no problems.
  5. A format type for a total of all problems.

I tried a few different ideas, but so far I've just written things and started over again.

mgedmin commented 7 years ago

Full flexibility probably requires the user to write their own statusline formatting function. All ALE has to do then is provide the raw values via some sort of API.

ale#statusline#Count(buffer) seems like it could be used for this, which means I can do

fun! LinterStatus()
    let total = ale#statusline#Count(bufnr('%')).total
    return total == 0 ? '' : printf('{%d}', total)
endf

and then use %{LinterStatus()} instead of %{ALEGetStatusLine()}.

And, hey, it works perfectly! I think this bug can be closed.

(Edited to adapt to the latest API.)

w0rp commented 7 years ago

@mgedmin I was thinking that. I think I'll document the Count function. The API has changed slightly, to take the newer problem types into account. The sample code above won't work anymore, but accessing 0 and 1 from the result will, as the result is now a Dictionary instead of a List.

w0rp commented 7 years ago

I just pushed a commit which adds documentation for ale#statusline#Count() instead. The keys documented there should be available now and forever. The tests will ensure that the Status() function continues to work until version 2.0, and the documentation encourages using Count() instead.