From 0c8164b1b3c8017770296320a67a164b3c2aad39 Mon Sep 17 00:00:00 2001 From: micchy326 Date: Sat, 2 Jan 2021 16:51:16 +0900 Subject: [PATCH] impl vim-lsp progress --- autoload/airline/extensions/lsp.vim | 37 +++++++++++++++++++++++++++++ autoload/airline/init.vim | 8 +++++-- doc/airline.txt | 6 +++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/lsp.vim b/autoload/airline/extensions/lsp.vim index 4324a7d5..55b806fc 100644 --- a/autoload/airline/extensions/lsp.vim +++ b/autoload/airline/extensions/lsp.vim @@ -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 diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 5909c64a..0e0c070a 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -164,6 +164,10 @@ function! airline#init#bootstrap() \ 'raw': '', \ 'accent': 'bold' \ }) + call airline#parts#define('lsp_progress', { + \ 'raw': '', + \ 'accent': 'bold' + \ }) call airline#parts#define_empty(['obsession', 'tagbar', 'syntastic-warn', \ 'syntastic-err', 'eclim', 'whitespace','windowswap', \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count', @@ -198,9 +202,9 @@ function! airline#init#sections() endif if !exists('g:airline_section_c') if exists("+autochdir") && &autochdir == 1 - let g:airline_section_c = airline#section#create(['%<', 'path', spc, 'readonly', 'coc_status']) + let g:airline_section_c = airline#section#create(['%<', 'path', spc, 'readonly', 'coc_status', 'lsp_progress']) else - let g:airline_section_c = airline#section#create(['%<', 'file', spc, 'readonly', 'coc_status']) + let g:airline_section_c = airline#section#create(['%<', 'file', spc, 'readonly', 'coc_status', 'lsp_progress']) endif endif if !exists('g:airline_section_gutter') diff --git a/doc/airline.txt b/doc/airline.txt index bd0089f2..eba98c29 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -888,6 +888,12 @@ lsp < * lsp close_lnum_symbol > let airline#extensions#lsp#close_lnum_symbol = ')' +< +* lsp progress skip time + Suppresses the frequency of status line updates. + Prevents heavy operation when using a language server that sends frequent progress notifications. > + g:airline#extensions#lsp#progress_skip_time = 0.3 (default) +< ------------------------------------- *airline-neomake* neomake