mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-12-06 12:14:24 +08:00
Add OmniSharp extension to display server status
This commit is contained in:
@@ -461,6 +461,11 @@ function! airline#extensions#load()
|
||||
call add(s:loaded_ext, 'dirvish')
|
||||
endif
|
||||
|
||||
if (get(g:, 'airline#extensions#omnisharp#enabled', 1) && get(g:, 'OmniSharp_loaded', 0))
|
||||
call airline#extensions#omnisharp#init(s:ext)
|
||||
call add(s:loaded_ext, 'omnisharp')
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#get_loaded_extensions()
|
||||
|
||||
45
autoload/airline/extensions/omnisharp.vim
Normal file
45
autoload/airline/extensions/omnisharp.vim
Normal file
@@ -0,0 +1,45 @@
|
||||
" MIT License
|
||||
" Plugin: https://github.com/OmniSharp/omnisharp-vim
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
if !get(g:, 'OmniSharp_loaded', 0)
|
||||
finish
|
||||
endif
|
||||
|
||||
function! airline#extensions#omnisharp#server_status(...) abort
|
||||
if !exists(':OmniSharpGotoDefinition') || !get(g:, 'OmniSharp_server_stdio', 0)
|
||||
return ''
|
||||
endif
|
||||
|
||||
let host = OmniSharp#GetHost(bufnr('%'))
|
||||
if type(host.job) != v:t_dict || get(host.job, 'stopped')
|
||||
return ''
|
||||
endif
|
||||
|
||||
let sln = fnamemodify(host.sln_or_dir, ':t')
|
||||
|
||||
if get(host.job, 'loaded', 0)
|
||||
return sln
|
||||
endif
|
||||
|
||||
try
|
||||
let projectsloaded = OmniSharp#project#CountLoaded()
|
||||
let projectstotal = OmniSharp#project#CountTotal()
|
||||
catch
|
||||
" The CountLoaded and CountTotal functions are very new - catch the error
|
||||
" when they don't exist
|
||||
let projectsloaded = 0
|
||||
let projectstotal = 0
|
||||
endtry
|
||||
return printf('%s(%d/%d)', sln, projectsloaded, projectstotal)
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#omnisharp#init(ext) abort
|
||||
call airline#parts#define_function('omnisharp', 'airline#extensions#omnisharp#server_status')
|
||||
augroup airline_omnisharp
|
||||
autocmd!
|
||||
autocmd User OmniSharpStarted,OmniSharpReady,OmniSharpStopped AirlineRefresh!
|
||||
augroup END
|
||||
endfunction
|
||||
@@ -178,6 +178,7 @@ function! airline#init#bootstrap()
|
||||
call airline#parts#define_text('grepper', '')
|
||||
call airline#parts#define_text('xkblayout', '')
|
||||
call airline#parts#define_text('keymap', '')
|
||||
call airline#parts#define_text('omnisharp', '')
|
||||
|
||||
unlet g:airline#init#bootstrapping
|
||||
endfunction
|
||||
@@ -205,7 +206,7 @@ function! airline#init#sections()
|
||||
let g:airline_section_gutter = airline#section#create(['%='])
|
||||
endif
|
||||
if !exists('g:airline_section_x')
|
||||
let g:airline_section_x = airline#section#create_right(['bookmark', 'tagbar', 'vista', 'gutentags', 'grepper', 'filetype'])
|
||||
let g:airline_section_x = airline#section#create_right(['bookmark', 'tagbar', 'vista', 'gutentags', 'omnisharp', 'grepper', 'filetype'])
|
||||
endif
|
||||
if !exists('g:airline_section_y')
|
||||
let g:airline_section_y = airline#section#create_right(['ffenc'])
|
||||
|
||||
Reference in New Issue
Block a user