From c8a5efc11e10065bf7d101fc1afb997167f75115 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 25 Jun 2017 19:49:18 +0100 Subject: [PATCH] Update the ALE extension so it loads better and uses the new count format --- autoload/airline/extensions.vim | 2 +- autoload/airline/extensions/ale.vim | 45 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index a3c05be1..b76169ee 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -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 diff --git a/autoload/airline/extensions/ale.vim b/autoload/airline/extensions/ale.vim index 5bd8bf21..062ef1de 100644 --- a/autoload/airline/extensions/ale.vim +++ b/autoload/airline/extensions/ale.vim @@ -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')