mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-05-18 06:19:42 +08:00
impl vim-lsp progress
This commit is contained in:
@@ -61,7 +61,44 @@ function! airline#extensions#lsp#get_error() abort
|
||||
return airline#extensions#lsp#get('error')
|
||||
endfunction
|
||||
|
||||
let s:lsp_progress = []
|
||||
function! airline#extensions#lsp#progress() abort
|
||||
if get(w:, 'airline_active', 0)
|
||||
if exists('*lsp#get_progress')
|
||||
let s:lsp_progress = lsp#get_progress()
|
||||
|
||||
if len(s:lsp_progress) == 0 | return '' | endif
|
||||
|
||||
" show only most new progress
|
||||
let s:lsp_progress = s:lsp_progress[0]
|
||||
if s:lsp_progress['message'] != '' && s:lsp_progress['percentage'] != 100
|
||||
let percent = ''
|
||||
if s:lsp_progress['percentage'] >= 0
|
||||
let percent = ' ' . string(s:lsp_progress['percentage']) . '%'
|
||||
endif
|
||||
let s:title = s:lsp_progress['title']
|
||||
let message = airline#util#shorten(s:lsp_progress['message'] . percent, 91, 9)
|
||||
return s:lsp_progress['server'] . ':' . s:title . ' ' . message
|
||||
endif
|
||||
return ''
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:timer = 0
|
||||
let s:ignore_time = 0
|
||||
function! airline#extensions#lsp#update() abort
|
||||
if reltimefloat(reltime()) - s:ignore_time >=
|
||||
\ get(g:, 'airline#extensions#lsp#progress_skip_time', 0.3)
|
||||
\ || len(s:lsp_progress) == 0
|
||||
call airline#update_statusline()
|
||||
let s:ignore_time = reltimefloat(reltime())
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#lsp#init(ext) abort
|
||||
call airline#parts#define_function('lsp_error_count', 'airline#extensions#lsp#get_error')
|
||||
call airline#parts#define_function('lsp_warning_count', 'airline#extensions#lsp#get_warning')
|
||||
call airline#parts#define_function('lsp_progress', 'airline#extensions#lsp#progress')
|
||||
autocmd User lsp_progress_updated call airline#extensions#lsp#update()
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user