Skip to content

Commit 10960f3

Browse files
committed
Sort :OmniSharpStatus jobs by age; use ! like :ls!
1 parent d699f50 commit 10960f3

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

autoload/OmniSharp.vim

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,23 @@ function! s:FindRunningServerForBuffer(bufnr) abort
457457
endfunction
458458

459459

460-
function! OmniSharp#Status() abort
461-
let slns = OmniSharp#proc#ListJobs()
462-
if len(slns) == 0
463-
echohl WarningMsg
464-
echo 'No servers started'
465-
echohl None
460+
function! OmniSharp#Status(include_dead) abort
461+
let jobs = map(OmniSharp#proc#ListJobs(), {_,s -> OmniSharp#proc#GetJob(s)})
462+
call filter(jobs, {_,j -> type(j) == type({})})
463+
if len(jobs) == 0
464+
echohl WarningMsg | echo 'No servers started' | echohl None
466465
return
467466
endif
468-
for sln_or_dir in slns
469-
if OmniSharp#proc#IsJobRunning(sln_or_dir)
470-
let job = OmniSharp#proc#GetJob(sln_or_dir)
467+
468+
function! s:SortServers(j1, j2) abort
469+
let t1 = has_key(a:j1, 'start_time') ? reltimefloat(a:j1.start_time) : 0
470+
let t2 = has_key(a:j2, 'start_time') ? reltimefloat(a:j2.start_time) : 0
471+
return t1 == t2 ? 0 : t1 < t2 ? 1 : -1
472+
endfunction
473+
call sort(jobs, 's:SortServers')
474+
475+
for job in jobs
476+
if OmniSharp#proc#IsJobRunning(job.sln_or_dir)
471477
let total = get(job, 'projects_total', 0)
472478
let loaded = get(job, 'projects_loaded', 0)
473479
let pl = total == 1 ? '' : 's'
@@ -481,7 +487,7 @@ function! OmniSharp#Status() abort
481487
let status = printf('loading (%d of %d project%s)', loaded, total, pl)
482488
endif
483489
else
484-
if OmniSharp#py#CheckAlive(sln_or_dir)
490+
if OmniSharp#py#CheckAlive(job.sln_or_dir)
485491
echohl Title
486492
let status = 'running'
487493
else
@@ -512,12 +518,14 @@ function! OmniSharp#Status() abort
512518
endif
513519
endif
514520
endif
515-
else
516-
echohl WarningMsg
521+
elseif a:include_dead
522+
echohl Comment
517523
let status = 'not running'
518524
let pid = ''
525+
else
526+
continue
519527
endif
520-
echo sln_or_dir
528+
echo job.sln_or_dir
521529
echohl None
522530
if !empty(pid)
523531
echon "\n pid: "

autoload/OmniSharp/proc.vim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let s:save_cpo = &cpoptions
22
set cpoptions&vim
33

4-
let s:jobs = {}
5-
let s:channels = {}
4+
let s:jobs = get(s:, 'jobs', {})
5+
let s:channels = get(s:, 'channels', {})
66

77
" Neovim jobs {{{ "
88

@@ -115,9 +115,6 @@ function! OmniSharp#proc#vimJobStart(command) abort
115115
call OmniSharp#util#EchoErr('Not using Vim 8.0+')
116116
return -1
117117
endif
118-
119-
120-
121118
call s:debug('Using vim job_start to start the following command:')
122119
call s:debug(a:command)
123120
let opts = {'err_cb': 'OmniSharp#proc#vimErrHandler'}

doc/omnisharp-vim.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,9 @@ convenient user re-mapping. These can be used like so: >
544544
NOTE: Requires vim 8.0+, neovim or vim-dispatch
545545

546546
*:OmniSharpStatus*
547-
:OmniSharpStatus
548-
Displays the status of all running and stopped servers
547+
:OmniSharpStatus[!]
548+
Displays the status of all running servers.
549+
When the [!] is included the list will include stopped/dead servers.
549550

550551
*:OmniSharpStartServer*
551552
*<Plug>(omnisharp_start_server)*

plugin/OmniSharp.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let g:omnicomplete_fetch_full_documentation = get(g:, 'omnicomplete_fetch_full_d
4343

4444
command! -bar -nargs=? OmniSharpInstall call OmniSharp#Install(<f-args>)
4545
command! -bar -nargs=? OmniSharpOpenLog call OmniSharp#log#Open(<q-args>)
46-
command! -bar OmniSharpStatus call OmniSharp#Status()
46+
command! -bar -bang OmniSharpStatus call OmniSharp#Status(<bang>0)
4747

4848
" Initialise automatic type and interface highlighting
4949
" Preserve backwards compatibility with older version g:OmniSharp_highlight_types

0 commit comments

Comments
 (0)