0

I am using ALE as LSP client, and I would like to write a function to get the number of errors and warnings from the current location list.

I think that a possible solution would be to write a function that count all the lines containing the keyword error and to count all the lines containing the keyword warning in the location list, and to call this function with some autocommand that is triggers every time the location list is updated.

Is it correct?

But then, how to implement it? Especially the part of reading from the location list doesn’t sound straightforward.

2
  • 1
    The last portion is straightforward: see :h :llist or :h getloclist(). The part about grepping for ERROR and WARNING should work. Try writing a function.
    – 3N4N
    Oct 4, 2022 at 7:32
  • This is good to know, but given that I am using ALE, I could easily fix it by using adding` ale` to the airline extension, e.g. let g:airline_extensions = ['ale','tabline']
    – Barzi2001
    Oct 5, 2022 at 8:41

1 Answer 1

2

ALE provides a function ale#statusline#Count(buffer) for this purpose:

  Given the number of a buffer which may have problems, return a |Dictionary|
  containing information about the number of problems detected by ALE. The
  following keys are supported:

  `error`         -> The number of problems with type `E` and `sub_type != 'style'`
  `warning`       -> The number of problems with type `W` and `sub_type != 'style'`
  `info`          -> The number of problems with type `I`
  `style_error`   -> The number of problems with type `E` and `sub_type == 'style'`
  `style_warning` -> The number of problems with type `W` and `sub_type == 'style'`
  `total`         -> The total number of problems.
7
  • This is indeed very cool! Many thanks for the hint!
    – Barzi2001
    Oct 4, 2022 at 18:10
  • 1
    This is absolutely good to know - I was not aware of it - but I discovered that there is a vim-airline builtin option and I could easily get what I wanted by adding ale to the airline extensions, e.g. let g:airline_extensions = ['ale','tabline']
    – Barzi2001
    Oct 5, 2022 at 8:44
  • How to get the "buffer"' argument in order to execute that function from in the command mod, like exe ale#statusline#Count(?) ?
    – dtrckd
    Jan 11 at 17:31
  • @dtrckd see :help buffer-functions
    – D. Ben Knoble
    Jan 13 at 15:52
  • 1
    @dtrckd Why are you using execute? Try echo ale#statusline#Count(bufnr('%')), and see github.com/benknoble/Dotfiles/blob/…; github.com/benknoble/Dotfiles/blob/…
    – D. Ben Knoble
    Jan 17 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.