mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-12-07 20:54:26 +08:00
Implement extension to report errors and warnings from LanguageClient plugin
This commit is contained in:
@@ -254,6 +254,11 @@ function! airline#extensions#load()
|
||||
call add(loaded_ext, 'ale')
|
||||
endif
|
||||
|
||||
if (get(g:, 'airline#extensions#languageclient#enabled', 1) && exists(':LanguageClientStart'))
|
||||
call airline#extensions#languageclient#init(s:ext)
|
||||
call add(loaded_ext, 'languageclient')
|
||||
endif
|
||||
|
||||
if get(g:, 'airline#extensions#whitespace#enabled', 1)
|
||||
call airline#extensions#whitespace#init(s:ext)
|
||||
call add(loaded_ext, 'whitespace')
|
||||
|
||||
101
autoload/airline/extensions/languageclient.vim
Normal file
101
autoload/airline/extensions/languageclient.vim
Normal file
@@ -0,0 +1,101 @@
|
||||
" MIT License. Copyright (c) 2013-2018 Bjorn Neergaard, w0rp, hallettj et al.
|
||||
" 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)
|
||||
let result = json_decode(a:state.result)
|
||||
let s:diagnostics = result.diagnostics
|
||||
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()
|
||||
if d.severity == a:type
|
||||
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
|
||||
|
||||
let count = 0
|
||||
for d in s:diagnostics_for_buffer()
|
||||
if d.severity == a:type
|
||||
let count += 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
if count == 0
|
||||
return ''
|
||||
endif
|
||||
|
||||
if s:show_line_numbers == 1
|
||||
return s:airline_languageclient_count(count, symbol) . <sid>airline_languageclient_get_line_number(a:type)
|
||||
else
|
||||
return s:airline_languageclient_count(count, symbol)
|
||||
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
|
||||
@@ -148,7 +148,8 @@ function! airline#init#bootstrap()
|
||||
call airline#parts#define_empty(['hunks', 'branch', 'obsession', 'tagbar',
|
||||
\ 'syntastic-warn', 'syntastic-err', 'eclim', 'whitespace','windowswap',
|
||||
\ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count',
|
||||
\ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count'])
|
||||
\ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count',
|
||||
\ 'languageclient_error_count', 'languageclient_warning_count'])
|
||||
call airline#parts#define_text('capslock', '')
|
||||
call airline#parts#define_text('gutentags', '')
|
||||
call airline#parts#define_text('grepper', '')
|
||||
@@ -194,9 +195,9 @@ function! airline#init#sections()
|
||||
endif
|
||||
endif
|
||||
if !exists('g:airline_section_error')
|
||||
let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count'])
|
||||
let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count', 'languageclient_error_count'])
|
||||
endif
|
||||
if !exists('g:airline_section_warning')
|
||||
let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'whitespace'])
|
||||
let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'languageclient_warning_count', 'whitespace'])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user