2019-03-25 07:27:10 -04:00
|
|
|
" MIT License. Copyright (c) 2013-2019 Bjorn Neergaard, w0rp et al.
|
2016-10-09 21:27:51 -04:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2018-01-05 04:18:22 -05:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2017-06-27 07:52:48 -04:00
|
|
|
function! s:airline_ale_count(cnt, symbol)
|
|
|
|
return a:cnt ? a:symbol. a:cnt : ''
|
|
|
|
endfunction
|
|
|
|
|
2019-01-27 08:57:18 -05:00
|
|
|
function! s:legacy_airline_ale_get_line_number(cnt, type) abort
|
|
|
|
" Before ALE introduced the FirstProblem API function, this is how
|
|
|
|
" airline would get the line numbers:
|
|
|
|
" 1. Get the whole loclist; 2. Filter it for the desired problem type.
|
|
|
|
" 3. Return the line number of the first element in the filtered list.
|
2017-11-16 13:08:41 -05:00
|
|
|
if a:cnt == 0
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let buffer = bufnr('')
|
|
|
|
let problem_type = (a:type ==# 'error') ? 'E' : 'W'
|
|
|
|
let problems = copy(ale#engine#GetLoclist(buffer))
|
|
|
|
|
|
|
|
call filter(problems, 'v:val.bufnr is buffer && v:val.type is# problem_type')
|
|
|
|
|
|
|
|
if empty(problems)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let open_lnum_symbol = get(g:, 'airline#extensions#ale#open_lnum_symbol', '(L')
|
|
|
|
let close_lnum_symbol = get(g:, 'airline#extensions#ale#close_lnum_symbol', ')')
|
|
|
|
|
|
|
|
return open_lnum_symbol . problems[0].lnum . close_lnum_symbol
|
|
|
|
endfunction
|
|
|
|
|
2019-01-27 08:57:18 -05:00
|
|
|
function! s:new_airline_ale_get_line_number(cnt, type) abort
|
|
|
|
" The FirstProblem call in ALE is a far more efficient way
|
|
|
|
" of obtaining line number data. If the installed ALE supports
|
|
|
|
" it, we should use this method of getting line data.
|
|
|
|
if a:cnt == 0
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let l:buffer = bufnr('')
|
|
|
|
|
|
|
|
" Try to get the first error from ALE.
|
|
|
|
let l:result = ale#statusline#FirstProblem(l:buffer, a:type)
|
|
|
|
if empty(l:result)
|
|
|
|
" If there are no errors then try and check for style errors.
|
|
|
|
let l:result = ale#statusline#FirstProblem(l:buffer, 'style_' . a:type)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if empty(l:result)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:open_lnum_symbol =
|
|
|
|
\ get(g:, 'airline#extensions#ale#open_lnum_symbol', '(L')
|
|
|
|
let l:close_lnum_symbol =
|
|
|
|
\ get(g:, 'airline#extensions#ale#close_lnum_symbol', ')')
|
|
|
|
|
|
|
|
return open_lnum_symbol . l:result.lnum . close_lnum_symbol
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:airline_ale_get_line_number(cnt, type) abort
|
|
|
|
" Use the new ALE statusline API function if it is available.
|
|
|
|
if exists("*ale#statusline#FirstProblem")
|
|
|
|
return s:new_airline_ale_get_line_number(a:cnt, a:type)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return s:legacy_airline_ale_get_line_number(a:cnt, a:type)
|
|
|
|
endfunction
|
|
|
|
|
2017-06-25 14:49:18 -04:00
|
|
|
function! airline#extensions#ale#get(type)
|
|
|
|
if !exists(':ALELint')
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2018-10-14 14:14:56 -04:00
|
|
|
let error_symbol = get(g:, 'airline#extensions#ale#error_symbol', 'E:')
|
|
|
|
let warning_symbol = get(g:, 'airline#extensions#ale#warning_symbol', 'W:')
|
|
|
|
let checking_symbol = get(g:, 'airline#extensions#ale#checking_symbol', '...')
|
|
|
|
let show_line_numbers = get(g:, 'airline#extensions#ale#show_line_numbers', 1)
|
2017-06-27 07:52:48 -04:00
|
|
|
|
|
|
|
let is_err = a:type ==# 'error'
|
|
|
|
|
2018-10-14 14:14:56 -04:00
|
|
|
if ale#engine#IsCheckingBuffer(bufnr('')) == 1
|
|
|
|
return is_err ? '' : checking_symbol
|
|
|
|
endif
|
|
|
|
|
|
|
|
let symbol = is_err ? error_symbol : warning_symbol
|
|
|
|
|
|
|
|
let counts = ale#statusline#Count(bufnr(''))
|
2017-06-27 07:52:48 -04:00
|
|
|
if type(counts) == type({}) && has_key(counts, 'error')
|
2017-06-25 14:49:18 -04:00
|
|
|
" Use the current Dictionary format.
|
2017-06-27 07:52:48 -04:00
|
|
|
let errors = counts.error + counts.style_error
|
|
|
|
let num = is_err ? errors : counts.total - errors
|
2016-10-09 21:27:51 -04:00
|
|
|
else
|
2017-06-25 14:49:18 -04:00
|
|
|
" Use the old List format.
|
2017-06-27 07:52:48 -04:00
|
|
|
let num = is_err ? counts[0] : counts[1]
|
2016-10-09 21:27:51 -04:00
|
|
|
endif
|
|
|
|
|
2018-10-14 14:14:56 -04:00
|
|
|
if show_line_numbers == 1
|
2018-03-19 06:28:45 -04:00
|
|
|
return s:airline_ale_count(num, symbol) . <sid>airline_ale_get_line_number(num, a:type)
|
|
|
|
else
|
|
|
|
return s:airline_ale_count(num, symbol)
|
|
|
|
endif
|
2016-10-09 21:27:51 -04:00
|
|
|
endfunction
|
|
|
|
|
2017-06-20 16:23:46 -04:00
|
|
|
function! airline#extensions#ale#get_warning()
|
|
|
|
return airline#extensions#ale#get('warning')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#ale#get_error()
|
|
|
|
return airline#extensions#ale#get('error')
|
|
|
|
endfunction
|
|
|
|
|
2016-10-09 21:27:51 -04:00
|
|
|
function! airline#extensions#ale#init(ext)
|
2017-06-20 16:23:46 -04:00
|
|
|
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')
|
2017-08-26 07:00:40 -04:00
|
|
|
augroup airline_ale
|
|
|
|
autocmd!
|
|
|
|
autocmd CursorHold,BufWritePost * call <sid>ale_refresh()
|
2018-10-14 14:15:03 -04:00
|
|
|
autocmd User ALEJobStarted,ALELintPost call <sid>ale_refresh()
|
2017-08-26 07:00:40 -04:00
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:ale_refresh()
|
|
|
|
if get(g:, 'airline_skip_empty_sections', 0)
|
|
|
|
exe ':AirlineRefresh'
|
|
|
|
endif
|
2016-10-09 21:27:51 -04:00
|
|
|
endfunction
|