Update the ALE extension so it loads better and uses the new count format

This commit is contained in:
w0rp 2017-06-25 19:49:18 +01:00
parent e7d18fe427
commit c8a5efc11e
2 changed files with 23 additions and 24 deletions

View File

@ -240,7 +240,7 @@ function! airline#extensions#load()
call add(loaded_ext, 'syntastic')
endif
if (get(g:, 'airline#extensions#ale#enabled', 1) && exists('g:loaded_ale'))
if (get(g:, 'airline#extensions#ale#enabled', 1) && exists(':ALELint'))
call airline#extensions#ale#init(s:ext)
call add(loaded_ext, 'ale')
endif

View File

@ -1,23 +1,32 @@
" MIT License. Copyright (c) 2013-2016 Bjorn Neergaard.
" MIT License. Copyright (c) 2013-2017 Bjorn Neergaard, w0rp
" vim: et ts=2 sts=2 sw=2
if !exists('g:loaded_ale')
finish
endif
let s:error_symbol = get(g:, 'airline#extensions#ale#error_symbol', 'E:')
let s:warning_symbol = get(g:, 'airline#extensions#ale#warning_symbol', 'W:')
function! s:count(index)
let l:buf = bufnr('%')
let l:count = ale#statusline#Count(l:buf)
if type(l:count) ==# type(0)
let l:count = 0
else
let l:count = l:count[a:index]
function! airline#extensions#ale#get(type)
if !exists(':ALELint')
return ''
endif
return l:count
let l:is_err = a:type ==# 'error'
let l:counts = ale#statusline#Count(bufnr(''))
let l:symbol = l:is_err ? s:error_symbol : s:warning_symbol
if type(l:counts) == type({}) && has_key(l:counts, 'error')
" Use the current Dictionary format.
let l:errors = l:counts.error + l:counts.style_error
let l:num = l:is_err ? l:errors : l:counts.total - l:errors
else
" Use the old List format.
let l:num = l:is_err ? l:counts[0] : l:counts[1]
endif
if l:num == 0
return ''
else
return l:symbol . l:num
endif
endfunction
function! airline#extensions#ale#get_warning()
@ -28,16 +37,6 @@ function! airline#extensions#ale#get_error()
return airline#extensions#ale#get('error')
endfunction
function! airline#extensions#ale#get(type)
let is_err = a:type is# 'error'
let cnt = s:count(is_err)
if cnt == 0
return ''
else
return (is_err ? s:error_symbol : s:warning_symbol) . cnt
endif
endfunction
function! airline#extensions#ale#init(ext)
call airline#parts#define_function('ale_error_count', 'airline#extensions#ale#get_error')
call airline#parts#define_function('ale_warning_count', 'airline#extensions#ale#get_warning')