2016-10-07 05:49:30 +00:00
|
|
|
" Author: KabbAmine <amine.kabb@gmail.com>
|
|
|
|
" 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-05-21 14:37:45 +00:00
|
|
|
let l:count = s:CreateCountDict()
|
|
|
|
let l:count.total = len(a: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
|
|
|
|
|
|
|
for l:entry in a: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
|
2017-05-21 17:58:26 +00:00
|
|
|
else
|
|
|
|
let l:count.warning += 1
|
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
|
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
|
2016-10-07 05:49:30 +00:00
|
|
|
else
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:count.error += 1
|
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
|
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.
|
|
|
|
function! s:GetCounts(buffer) abort
|
2017-07-06 09:51:05 +00:00
|
|
|
if !exists('g:ale_buffer_info') || !has_key(g:ale_buffer_info, a:buffer)
|
|
|
|
return s:CreateCountDict()
|
|
|
|
endif
|
2017-02-13 23:31:29 +00:00
|
|
|
|
2017-07-06 09:51:05 +00:00
|
|
|
" Cache is cold, so manually ask for an update.
|
|
|
|
if !has_key(g:ale_buffer_info[a:buffer], 'count')
|
|
|
|
call ale#statusline#Update(a:buffer, g:ale_buffer_info[a:buffer].loclist)
|
|
|
|
endif
|
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
|
|
|
|
|
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
|
2017-02-13 23:31:29 +00:00
|
|
|
|
2017-05-21 14:37:45 +00:00
|
|
|
" This is the historical format setting which could be configured before.
|
|
|
|
function! s:StatusForListFormat() abort
|
2016-10-23 21:41:00 +00:00
|
|
|
let [l:error_format, l:warning_format, l:no_errors] = g:ale_statusline_format
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:counts = s:GetCounts(bufnr(''))
|
2016-10-23 21:41:00 +00:00
|
|
|
|
2016-10-13 13:10:50 +00:00
|
|
|
" Build strings based on user formatting preferences.
|
2017-05-21 14:37:45 +00:00
|
|
|
let l:errors = l:counts[0] ? printf(l:error_format, l:counts[0]) : ''
|
|
|
|
let l:warnings = l:counts[1] ? printf(l:warning_format, l:counts[1]) : ''
|
2016-10-07 05:49:30 +00:00
|
|
|
|
2016-10-13 13:10:50 +00:00
|
|
|
" Different formats based on the combination of errors and warnings.
|
2016-10-10 23:00:09 +00:00
|
|
|
if empty(l:errors) && empty(l:warnings)
|
|
|
|
let l:res = l:no_errors
|
|
|
|
elseif !empty(l:errors) && !empty(l:warnings)
|
|
|
|
let l:res = printf('%s %s', l:errors, l:warnings)
|
2016-10-07 05:49:30 +00:00
|
|
|
else
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:res = empty(l:errors) ? l:warnings : l:errors
|
2016-10-07 05:49:30 +00:00
|
|
|
endif
|
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
return l:res
|
2016-10-07 05:49:30 +00:00
|
|
|
endfunction
|
2017-05-21 14:37:45 +00:00
|
|
|
|
|
|
|
" Returns a formatted string that can be integrated in the statusline.
|
2017-05-24 09:23:13 +00:00
|
|
|
"
|
|
|
|
" This function is deprecated, and should not be used. Use the airline plugin
|
|
|
|
" instead, or write your own status function with ale#statusline#Count()
|
2017-05-21 14:37:45 +00:00
|
|
|
function! ale#statusline#Status() abort
|
|
|
|
if !exists('g:ale_statusline_format')
|
|
|
|
return 'OK'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if type(g:ale_statusline_format) == type([])
|
|
|
|
return s:StatusForListFormat()
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunction
|