Skip to content

Commit d699f50

Browse files
committed
Add :OmniSharpStatus command
1 parent 78d45f5 commit d699f50

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

autoload/OmniSharp.vim

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,79 @@ 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
466+
return
467+
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)
471+
let total = get(job, 'projects_total', 0)
472+
let loaded = get(job, 'projects_loaded', 0)
473+
let pl = total == 1 ? '' : 's'
474+
let pid = get(job, 'pid', '')
475+
if g:OmniSharp_server_stdio
476+
if get(job, 'loaded') || !g:OmniSharp_server_stdio
477+
echohl Title
478+
let status = printf('running (%d project%s)', total, pl)
479+
else
480+
echohl ModeMsg
481+
let status = printf('loading (%d of %d project%s)', loaded, total, pl)
482+
endif
483+
else
484+
if OmniSharp#py#CheckAlive(sln_or_dir)
485+
echohl Title
486+
let status = 'running'
487+
else
488+
echohl ModeMsg
489+
let status = 'not running'
490+
endif
491+
endif
492+
if has_key(job, 'start_time')
493+
let seconds = float2nr(reltimefloat(reltime(job.start_time)))
494+
if seconds < 60
495+
let status .= printf(' for %d seconds', seconds)
496+
else
497+
let minutes = seconds / 60
498+
if minutes == 1
499+
let status .= ' for 1 minute'
500+
elseif minutes < 60
501+
let status .= printf(' for %d minutes', minutes)
502+
else
503+
let hours = minutes / 60
504+
let minutes %= 60
505+
if hours == 1
506+
let status .= printf(' for an hour and %d minutes', minutes)
507+
elseif hours < 48
508+
let status .= printf(' for %d hours', hours)
509+
else
510+
let status .= printf(' for %d days', hours / 24)
511+
endif
512+
endif
513+
endif
514+
endif
515+
else
516+
echohl WarningMsg
517+
let status = 'not running'
518+
let pid = ''
519+
endif
520+
echo sln_or_dir
521+
echohl None
522+
if !empty(pid)
523+
echon "\n pid: "
524+
echohl Identifier
525+
echon pid . "\n"
526+
echohl None
527+
endif
528+
echo ' ' . status
529+
endfor
530+
endfunction
531+
532+
460533
let s:plugin_root_dir = expand('<sfile>:p:h:h')
461534

462535
function! OmniSharp#Install(...) abort

autoload/OmniSharp/proc.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ function! OmniSharp#proc#StopJob(jobkey) abort
238238
silent doautocmd <nomodeline> User OmniSharpStopped
239239
endfunction
240240

241+
function! OmniSharp#proc#ListJobs() abort
242+
return keys(s:jobs)
243+
endfunction
244+
241245
function! OmniSharp#proc#ListRunningJobs() abort
242246
return filter(keys(s:jobs), 'OmniSharp#proc#IsJobRunning(v:val)')
243247
endfunction

doc/omnisharp-vim.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ convenient user re-mapping. These can be used like so: >
543543
Restarts the OmniSharp server
544544
NOTE: Requires vim 8.0+, neovim or vim-dispatch
545545

546+
*:OmniSharpStatus*
547+
:OmniSharpStatus
548+
Displays the status of all running and stopped servers
549+
546550
*:OmniSharpStartServer*
547551
*<Plug>(omnisharp_start_server)*
548552
:OmniSharpStartServer {sln-or-dir}

ftplugin/cs/OmniSharp.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ let b:undo_ftplugin .= '
118118
\| delcommand OmniSharpPreviewImplementation
119119
\| delcommand OmniSharpRename
120120
\| delcommand OmniSharpRenameTo
121+
\| delcommand OmniSharpRepeatCodeAction
121122
\| delcommand OmniSharpRestartAllServers
122123
\| delcommand OmniSharpRestartServer
123-
\| delcommand OmniSharpRepeatCodeAction
124124
\| delcommand OmniSharpRunTest
125125
\| delcommand OmniSharpRunTestsInFile
126126
\| delcommand OmniSharpSignatureHelp

plugin/OmniSharp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +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()
4647

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

0 commit comments

Comments
 (0)