2019-01-28 18:11:43 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2018 Bjorn Neergaard, hallettj et al.
|
2019-01-28 18:21:32 +08:00
|
|
|
" This comes from the Languageclient plugin:
|
|
|
|
" https://github.com/autozimu/LanguageClient-neovim
|
2018-09-03 05:08:04 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
let s:error_symbol = get(g:, 'airline#extensions#languageclient#error_symbol', 'E:')
|
|
|
|
let s:warning_symbol = get(g:, 'airline#extensions#languageclient#warning_symbol', 'W:')
|
|
|
|
let s:show_line_numbers = get(g:, 'airline#extensions#languageclient#show_line_numbers', 1)
|
|
|
|
|
|
|
|
" Severity codes from the LSP spec
|
|
|
|
let s:severity_error = 1
|
|
|
|
let s:severity_warning = 2
|
|
|
|
let s:severity_info = 3
|
|
|
|
let s:severity_hint = 4
|
|
|
|
|
|
|
|
" After each LanguageClient state change `s:diagnostics` will be populated with
|
|
|
|
" a map from file names to lists of errors, warnings, informational messages,
|
|
|
|
" and hints.
|
|
|
|
let s:diagnostics = {}
|
|
|
|
|
|
|
|
function! s:languageclient_refresh()
|
|
|
|
if get(g:, 'airline_skip_empty_sections', 0)
|
|
|
|
exe ':AirlineRefresh'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:record_diagnostics(state)
|
2019-01-28 18:21:32 +08:00
|
|
|
" The returned message might not have the 'result' key
|
|
|
|
if has_key(a:state, 'result')
|
|
|
|
let result = json_decode(a:state.result)
|
|
|
|
let s:diagnostics = result.diagnostics
|
|
|
|
endif
|
2018-09-03 05:08:04 +08:00
|
|
|
call s:languageclient_refresh()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:get_diagnostics()
|
|
|
|
call LanguageClient#getState(function("s:record_diagnostics"))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diagnostics_for_buffer()
|
|
|
|
return get(s:diagnostics, expand('%:p'), [])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:airline_languageclient_count(cnt, symbol)
|
|
|
|
return a:cnt ? a:symbol. a:cnt : ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:airline_languageclient_get_line_number(type) abort
|
|
|
|
let linenumber_of_first_problem = 0
|
|
|
|
for d in s:diagnostics_for_buffer()
|
2018-09-17 00:17:04 +08:00
|
|
|
if has_key(d, 'severity') && d.severity == a:type
|
2018-09-03 05:08:04 +08:00
|
|
|
let linenumber_of_first_problem = d.range.start.line
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if linenumber_of_first_problem == 0
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let open_lnum_symbol = get(g:, 'airline#extensions#languageclient#open_lnum_symbol', '(L')
|
|
|
|
let close_lnum_symbol = get(g:, 'airline#extensions#languageclient#close_lnum_symbol', ')')
|
|
|
|
|
|
|
|
return open_lnum_symbol . linenumber_of_first_problem . close_lnum_symbol
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#languageclient#get(type)
|
|
|
|
let is_err = a:type == s:severity_error
|
|
|
|
let symbol = is_err ? s:error_symbol : s:warning_symbol
|
|
|
|
|
2018-09-10 14:51:11 +08:00
|
|
|
let cnt = 0
|
2018-09-03 05:08:04 +08:00
|
|
|
for d in s:diagnostics_for_buffer()
|
2018-09-23 22:50:15 +08:00
|
|
|
if has_key(d, 'severity') && d.severity == a:type
|
2018-09-10 14:51:11 +08:00
|
|
|
let cnt += 1
|
2018-09-03 05:08:04 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2018-09-10 14:51:11 +08:00
|
|
|
if cnt == 0
|
2018-09-03 05:08:04 +08:00
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
if s:show_line_numbers == 1
|
2018-09-10 14:51:11 +08:00
|
|
|
return s:airline_languageclient_count(cnt, symbol) . <sid>airline_languageclient_get_line_number(a:type)
|
2018-09-03 05:08:04 +08:00
|
|
|
else
|
2018-09-10 14:51:11 +08:00
|
|
|
return s:airline_languageclient_count(cnt, symbol)
|
2018-09-03 05:08:04 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#languageclient#get_warning()
|
|
|
|
return airline#extensions#languageclient#get(s:severity_warning)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#languageclient#get_error()
|
|
|
|
return airline#extensions#languageclient#get(s:severity_error)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#languageclient#init(ext)
|
|
|
|
call airline#parts#define_function('languageclient_error_count', 'airline#extensions#languageclient#get_error')
|
|
|
|
call airline#parts#define_function('languageclient_warning_count', 'airline#extensions#languageclient#get_warning')
|
|
|
|
augroup airline_languageclient
|
|
|
|
autocmd!
|
|
|
|
autocmd User LanguageClientDiagnosticsChanged call <sid>get_diagnostics()
|
|
|
|
augroup END
|
|
|
|
endfunction
|