All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: KabbAmine <amine.kabb@gmail.com>
2 " Additions by: petpetpetpet <chris@freelanceninjas.com>
3 " Description: Statusline related function(s)
5 function! s:CreateCountDict() abort
6 " Keys 0 and 1 are for backwards compatibility.
7 " The count object used to be a List of [error_count, warning_count].
20 " Update the buffer error/warning count with data from loclist.
21 function! ale#statusline#Update(buffer, loclist) abort
22 if !exists('g:ale_buffer_info') || !has_key(g:ale_buffer_info, a:buffer)
26 let l:loclist = filter(copy(a:loclist), 'v:val.bufnr == a:buffer')
27 let l:count = s:CreateCountDict()
28 let l:count.total = len(l:loclist)
30 " Allows easy access to the first instance of each problem type.
31 let l:first_problems = {}
33 for l:entry in l:loclist
34 if l:entry.type is# 'W'
35 if get(l:entry, 'sub_type', '') is# 'style'
36 let l:count.style_warning += 1
38 if l:count.style_warning == 1
39 let l:first_problems.style_warning = l:entry
42 let l:count.warning += 1
44 if l:count.warning == 1
45 let l:first_problems.warning = l:entry
48 elseif l:entry.type is# 'I'
52 let l:first_problems.info = l:entry
54 elseif get(l:entry, 'sub_type', '') is# 'style'
55 let l:count.style_error += 1
57 if l:count.style_error == 1
58 let l:first_problems.style_error = l:entry
61 let l:count.error += 1
64 let l:first_problems.error = l:entry
69 " Set keys for backwards compatibility.
70 let l:count[0] = l:count.error + l:count.style_error
71 let l:count[1] = l:count.total - l:count[0]
73 let g:ale_buffer_info[a:buffer].count = l:count
74 let g:ale_buffer_info[a:buffer].first_problems = l:first_problems
77 " Get the counts for the buffer, and update the counts if needed.
78 function! s:UpdateCacheIfNecessary(buffer) abort
79 " Cache is cold, so manually ask for an update.
80 if !has_key(g:ale_buffer_info[a:buffer], 'count')
81 call ale#statusline#Update(
83 \ g:ale_buffer_info[a:buffer].loclist
88 function! s:BufferCacheExists(buffer) abort
89 if !exists('g:ale_buffer_info') || !has_key(g:ale_buffer_info, a:buffer)
96 " Get the counts for the buffer, and update the counts if needed.
97 function! s:GetCounts(buffer) abort
98 if !s:BufferCacheExists(a:buffer)
99 return s:CreateCountDict()
102 call s:UpdateCacheIfNecessary(a:buffer)
104 return g:ale_buffer_info[a:buffer].count
107 " Get the dict of first_problems, update the buffer info cache if necessary.
108 function! s:GetFirstProblems(buffer) abort
109 if !s:BufferCacheExists(a:buffer)
113 call s:UpdateCacheIfNecessary(a:buffer)
115 return g:ale_buffer_info[a:buffer].first_problems
118 " Returns a Dictionary with counts for use in third party integrations.
119 function! ale#statusline#Count(buffer) abort
120 " The Dictionary is copied here before exposing it to other plugins.
121 return copy(s:GetCounts(a:buffer))
124 " Returns a copy of the *first* locline instance of the specified problem
125 " type. (so this would allow an external integration to know all the info
126 " about the first style warning in the file, for example.)
127 function! ale#statusline#FirstProblem(buffer, type) abort
128 let l:first_problems = s:GetFirstProblems(a:buffer)
130 if !empty(l:first_problems) && has_key(l:first_problems, a:type)
131 return copy(l:first_problems[a:type])