Skip to content

Commit 989a4ad

Browse files
committed
Add new test runner buffer
1 parent d6d682d commit 989a4ad

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

autoload/OmniSharp/actions/test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ function! s:utils.init.extract(Callback, codeStructures) abort
410410
\ 'bufnr': cs[0],
411411
\ 'tests': s:utils.extractTests(cs[1])
412412
\}})
413+
call OmniSharp#testrunner#SetTests(bufferTests)
413414
call a:Callback(bufferTests)
414415
endfunction
415416

autoload/OmniSharp/preview.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ function! OmniSharp#preview#Display(content, title) abort
66
silent wincmd P
77
setlocal modifiable noreadonly
88
setlocal nobuflisted buftype=nofile bufhidden=wipe
9-
0,$d
9+
0,$delete
1010
silent put =a:content
11-
0d_
12-
setfiletype omnisharpdoc
11+
0delete _
12+
set filetype=omnisharpdoc
1313
setlocal conceallevel=3
1414
setlocal nomodifiable readonly
1515
let winid = winnr()

autoload/OmniSharp/testrunner.vim

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
let s:save_cpo = &cpoptions
2+
set cpoptions&vim
3+
4+
function! OmniSharp#testrunner#Open() abort
5+
if !OmniSharp#actions#test#Validate() | return | endif
6+
call s:Open()
7+
endfunction
8+
9+
function s:Open() abort
10+
let ft = 'omnisharptest'
11+
let title = 'OmniSharp Test Runner'
12+
" If the buffer is listed in a window in the current tab, then focus it
13+
for winnr in range(1, winnr('$'))
14+
if getbufvar(winbufnr(winnr), '&filetype') ==# ft
15+
call win_gotoid(win_getid(winnr))
16+
break
17+
endif
18+
endfor
19+
if &filetype !=# ft
20+
" If a buffer with filetype omnisharptest exists, open it in a new split
21+
for buffer in getbufinfo()
22+
if getbufvar(buffer.bufnr, '&filetype') ==# ft
23+
botright split
24+
execute 'buffer' buffer.bufnr
25+
break
26+
endif
27+
endfor
28+
endif
29+
if &filetype !=# ft
30+
botright new
31+
endif
32+
33+
silent setlocal noswapfile signcolumn=no
34+
set bufhidden=hide
35+
let &filetype = ft
36+
execute 'file' title
37+
call s:Paint()
38+
endfunction
39+
40+
function! s:Paint() abort
41+
setlocal modifiable
42+
let winview = winsaveview()
43+
0,$delete _
44+
put ='OmniSharp Test Runner'
45+
0delete _
46+
put =''
47+
48+
for sln_or_dir in OmniSharp#proc#ListRunningJobs()
49+
put =fnamemodify(sln_or_dir, ':t')
50+
let job = OmniSharp#proc#GetJob(sln_or_dir)
51+
if !has_key(job, 'tests') | continue | endif
52+
for testfile in keys(job.tests)
53+
put =' ' . fnamemodify(testfile, ':.')
54+
for test in job.tests[testfile]
55+
put =' ' . test.name
56+
endfor
57+
endfor
58+
put =''
59+
endfor
60+
61+
call winrestview(winview)
62+
setlocal nomodifiable nomodified
63+
endfunction
64+
65+
function! OmniSharp#testrunner#SetTests(bufferTests) abort
66+
let winid = win_getid()
67+
for buffer in a:bufferTests
68+
let job = OmniSharp#GetHost(buffer.bufnr).job
69+
let job.tests = get(job, 'tests', {})
70+
let filename = fnamemodify(bufname(buffer.bufnr), ':p')
71+
let job.tests[filename] = buffer.tests
72+
endfor
73+
call s:Open()
74+
call win_gotoid(winid)
75+
endfunction
76+
77+
let &cpoptions = s:save_cpo
78+
unlet s:save_cpo
79+
80+
" vim:et:sw=2:sts=2

plugin/OmniSharp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ let g:omnicomplete_fetch_full_documentation = get(g:, 'omnicomplete_fetch_full_d
5151

5252
command! -bar -nargs=? OmniSharpInstall call OmniSharp#Install(<f-args>)
5353
command! -bar -nargs=? OmniSharpOpenLog call OmniSharp#log#Open(<q-args>)
54+
command! -bar -nargs=? OmniSharpOpenTestRunner call OmniSharp#testrunner#Open()
5455
command! -bar -bang OmniSharpStatus call OmniSharp#Status(<bang>0)
5556

5657
" Preserve backwards compatibility with older version g:OmniSharp_highlight_types

0 commit comments

Comments
 (0)