2016-10-07 05:49:30 +00:00
|
|
|
" Author: KabbAmine <amine.kabb@gmail.com>
|
2019-01-27 12:44:49 +00:00
|
|
|
" Additions by: petpetpetpet <chris@freelanceninjas.com>
|
2016-10-07 05:49:30 +00:00
|
|
|
" Description: Statusline related function(s)
|
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
function! s:CreateCountDict() abort
|
|
|
|
" Keys 0 and 1 are for backwards compatibility.
|
|
|
|
" The count object used to be a List of [error_count, warning_count].
|
|
|
|
return {
|
|
|
|
\ '0': 0,
|
|
|
|
\ '1': 0,
|
|
|
|
\ 'error': 0,
|
|
|
|
\ 'warning': 0,
|
|
|
|
\ 'info': 0,
|
|
|
|
\ 'style_error': 0,
|
|
|
|
\ 'style_warning': 0,
|
|
|
|
\ 'total': 0,
|
|
|
|
\}
|
|
|
|
endfunction
|
|
|
|
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 21:51:01 +00:00
|
|
|
" Update the buffer error/warning count with data from loclist.
|
|
|
|
function! ale#statusline#Update(buffer, loclist) abort
|
2017-05-21 14:37:45 +00:00
|
|
|
if !exists('g:ale_buffer_info') || !has_key(g:ale_buffer_info, a:buffer)
|
2017-02-09 18:47:14 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-08-13 12:24:10 +00:00
|
|
|
let l:loclist = filter(copy(a:loclist), 'v:val.bufnr == a:buffer')
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count = s:CreateCountDict()
|
2017-08-13 12:24:10 +00:00
|
|
|
let l:count.total = len(l:loclist)
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 21:51:01 +00:00
|
|
|
|
2019-01-27 12:44:49 +00:00
|
|
|
" Allows easy access to the first instance of each problem type.
|
|
|
|
let l:first_problems = {}
|
|
|
|
|
2017-08-13 12:24:10 +00:00
|
|
|
for l:entry in l:loclist
|
2017-08-08 07:39:13 +00:00
|
|
|
if l:entry.type is# 'W'
|
|
|
|
if get(l:entry, 'sub_type', '') is# 'style'
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count.style_warning += 1
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
if l:count.style_warning == 1
|
|
|
|
let l:first_problems.style_warning = l:entry
|
|
|
|
endif
|
2017-05-21 17:58:26 +00:00
|
|
|
else
|
|
|
|
let l:count.warning += 1
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
if l:count.warning == 1
|
|
|
|
let l:first_problems.warning = l:entry
|
|
|
|
endif
|
2017-05-21 14:37:45 +00:00
|
|
|
endif
|
2017-08-08 07:39:13 +00:00
|
|
|
elseif l:entry.type is# 'I'
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count.info += 1
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
if l:count.info == 1
|
|
|
|
let l:first_problems.info = l:entry
|
|
|
|
endif
|
2017-08-08 07:39:13 +00:00
|
|
|
elseif get(l:entry, 'sub_type', '') is# 'style'
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count.style_error += 1
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
if l:count.style_error == 1
|
|
|
|
let l:first_problems.style_error = l:entry
|
|
|
|
endif
|
2016-10-07 05:49:30 +00:00
|
|
|
else
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count.error += 1
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
if l:count.error == 1
|
|
|
|
let l:first_problems.error = l:entry
|
|
|
|
endif
|
2016-10-07 05:49:30 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
" Set keys for backwards compatibility.
|
|
|
|
let l:count[0] = l:count.error + l:count.style_error
|
|
|
|
let l:count[1] = l:count.total - l:count[0]
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 21:51:01 +00:00
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
let g:ale_buffer_info[a:buffer].count = l:count
|
2019-01-27 12:44:49 +00:00
|
|
|
let g:ale_buffer_info[a:buffer].first_problems = l:first_problems
|
2016-10-23 21:41:00 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
" Get the counts for the buffer, and update the counts if needed.
|
2019-01-27 12:44:49 +00:00
|
|
|
function! s:UpdateCacheIfNecessary(buffer) abort
|
|
|
|
" Cache is cold, so manually ask for an update.
|
|
|
|
if !has_key(g:ale_buffer_info[a:buffer], 'count')
|
2019-02-06 18:05:13 +00:00
|
|
|
call ale#statusline#Update(
|
|
|
|
\ a:buffer,
|
|
|
|
\ g:ale_buffer_info[a:buffer].loclist
|
|
|
|
\)
|
2019-01-27 12:44:49 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:BufferCacheExists(buffer) abort
|
2017-07-06 09:51:05 +00:00
|
|
|
if !exists('g:ale_buffer_info') || !has_key(g:ale_buffer_info, a:buffer)
|
2019-01-27 12:44:49 +00:00
|
|
|
return 0
|
2017-07-06 09:51:05 +00:00
|
|
|
endif
|
2017-02-13 23:31:29 +00:00
|
|
|
|
2019-01-27 12:44:49 +00:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Get the counts for the buffer, and update the counts if needed.
|
|
|
|
function! s:GetCounts(buffer) abort
|
|
|
|
if !s:BufferCacheExists(a:buffer)
|
|
|
|
return s:CreateCountDict()
|
2017-07-06 09:51:05 +00:00
|
|
|
endif
|
2016-10-23 21:41:00 +00:00
|
|
|
|
2019-01-27 12:44:49 +00:00
|
|
|
call s:UpdateCacheIfNecessary(a:buffer)
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
return g:ale_buffer_info[a:buffer].count
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 21:51:01 +00:00
|
|
|
endfunction
|
|
|
|
|
2019-01-27 12:44:49 +00:00
|
|
|
" Get the dict of first_problems, update the buffer info cache if necessary.
|
|
|
|
function! s:GetFirstProblems(buffer) abort
|
|
|
|
if !s:BufferCacheExists(a:buffer)
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:UpdateCacheIfNecessary(a:buffer)
|
|
|
|
|
|
|
|
return g:ale_buffer_info[a:buffer].first_problems
|
|
|
|
endfunction
|
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
" Returns a Dictionary with counts for use in third party integrations.
|
|
|
|
function! ale#statusline#Count(buffer) abort
|
|
|
|
" The Dictionary is copied here before exposing it to other plugins.
|
|
|
|
return copy(s:GetCounts(a:buffer))
|
|
|
|
endfunction
|
2019-01-27 12:44:49 +00:00
|
|
|
|
|
|
|
" Returns a copy of the *first* locline instance of the specified problem
|
|
|
|
" type. (so this would allow an external integration to know all the info
|
|
|
|
" about the first style warning in the file, for example.)
|
|
|
|
function! ale#statusline#FirstProblem(buffer, type) abort
|
|
|
|
let l:first_problems = s:GetFirstProblems(a:buffer)
|
|
|
|
|
|
|
|
if !empty(l:first_problems) && has_key(l:first_problems, a:type)
|
|
|
|
return copy(l:first_problems[a:type])
|
|
|
|
endif
|
|
|
|
|
|
|
|
return {}
|
|
|
|
endfunction
|