2016-10-07 05:49:30 +00:00
|
|
|
" Author: KabbAmine <amine.kabb@gmail.com>
|
|
|
|
" Description: Statusline related function(s)
|
|
|
|
|
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-02-13 23:31:29 +00:00
|
|
|
if !exists('g:ale_buffer_info')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-02-09 18:47:14 +00:00
|
|
|
if !has_key(g:ale_buffer_info, a:buffer)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:errors = 0
|
|
|
|
let l:warnings = 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
|
|
|
|
|
|
|
for l:entry in a:loclist
|
2016-10-10 23:00:09 +00:00
|
|
|
if l:entry.type ==# 'E'
|
|
|
|
let l:errors += 1
|
2016-10-07 05:49:30 +00:00
|
|
|
else
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:warnings += 1
|
2016-10-07 05:49:30 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
let g:ale_buffer_info[a:buffer].count = [l:errors, l:warnings]
|
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
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
" Set the error and warning counts, calling for an update only if needed.
|
|
|
|
" If counts cannot be set, return 0.
|
|
|
|
function! s:SetupCount(buffer) abort
|
|
|
|
if !has_key(g:ale_buffer_info, a:buffer)
|
|
|
|
" Linters have not been run for the buffer yet, so stop here.
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2016-10-13 13:10:50 +00:00
|
|
|
" Cache is cold, so manually ask for an update.
|
2016-10-23 21:41:00 +00:00
|
|
|
if !has_key(g:ale_buffer_info[a:buffer], 'count')
|
2016-10-24 19:21:32 +00:00
|
|
|
call ale#statusline#Update(a:buffer, g:ale_buffer_info[a:buffer].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
|
|
|
endif
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Returns a tuple of errors and warnings for use in third-party integrations.
|
|
|
|
function! ale#statusline#Count(buffer) abort
|
2017-02-13 23:31:29 +00:00
|
|
|
if !exists('g:ale_buffer_info')
|
|
|
|
return [0, 0]
|
|
|
|
endif
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
if !s:SetupCount(a:buffer)
|
|
|
|
return [0, 0]
|
|
|
|
endif
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
" Returns a formatted string that can be integrated in the statusline.
|
|
|
|
function! ale#statusline#Status() abort
|
2017-02-13 23:31:29 +00:00
|
|
|
if !exists('g:ale_buffer_info')
|
|
|
|
return 'OK'
|
|
|
|
endif
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
let [l:error_format, l:warning_format, l:no_errors] = g:ale_statusline_format
|
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
|
|
|
let l:buffer = bufnr('%')
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
if !s:SetupCount(l:buffer)
|
|
|
|
return l:no_errors
|
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
|
|
|
endif
|
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
let [l:error_count, l:warning_count] = g:ale_buffer_info[l:buffer].count
|
|
|
|
|
2016-10-13 13:10:50 +00:00
|
|
|
" Build strings based on user formatting preferences.
|
2016-10-23 21:41:00 +00:00
|
|
|
let l:errors = l:error_count ? printf(l:error_format, l:error_count) : ''
|
|
|
|
let l:warnings = l:warning_count ? printf(l:warning_format, l:warning_count) : ''
|
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
|