Skip to content

Commit e8ff9b9

Browse files
committed
Add testrunner Repaint function for updating state
1 parent 4fc43da commit e8ff9b9

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

autoload/OmniSharp/testrunner.vim

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let s:state2char = {
55
\ 'Not run': '|',
66
\ 'Running': '-',
77
\ 'Passed': '*',
8-
\ 'Failed': '#'
8+
\ 'Failed': '!'
99
\}
1010

1111
function! OmniSharp#testrunner#Open() abort
@@ -36,38 +36,61 @@ function s:Open() abort
3636
if &filetype !=# ft
3737
botright new
3838
endif
39-
39+
let s:testrunner_bufnr = bufnr()
4040
silent setlocal noswapfile signcolumn=no conceallevel=3 concealcursor=nv
41+
setlocal comments=:# commentstring=#\ %s
4142
set bufhidden=hide
4243
let &filetype = ft
4344
execute 'file' title
4445
call s:Paint()
4546
endfunction
4647

48+
function! OmniSharp#testrunner#Repaint() abort
49+
" Check that the test runner has been initialised and is still a loaded buffer
50+
if !exists('s:testrunner_bufnr') | return | endif
51+
if getbufvar(s:testrunner_bufnr, '&ft') !=# 'omnisharptest' | return | endif
52+
" If the buffer is listed in a window in the current tab, then focus it
53+
for winnr in range(1, winnr('$'))
54+
if winbufnr(winnr) == s:testrunner_bufnr
55+
let l:winid = win_getid()
56+
call win_gotoid(win_getid(winnr))
57+
break
58+
endif
59+
endfor
60+
call s:Paint()
61+
if exists('l:winid')
62+
call win_gotoid(l:winid)
63+
endif
64+
endfunction
65+
4766
function! s:Paint() abort
48-
setlocal modifiable
49-
let winview = winsaveview()
50-
0,$delete _
51-
put ='OmniSharp Test Runner'
52-
0delete _
53-
put =''
67+
let lines = []
68+
call add(lines, repeat('=', 80))
69+
call add(lines, ' OmniSharp Test Runner')
70+
call add(lines, repeat('=', 80))
71+
call add(lines, '')
5472

5573
for sln_or_dir in OmniSharp#proc#ListRunningJobs()
56-
put =fnamemodify(sln_or_dir, ':t')
74+
call add(lines, fnamemodify(sln_or_dir, ':t'))
5775
let job = OmniSharp#proc#GetJob(sln_or_dir)
5876
if !has_key(job, 'tests') | continue | endif
5977
for testfile in keys(job.tests)
60-
put =' ' . fnamemodify(testfile, ':.')
78+
call add(lines, ' ' . fnamemodify(testfile, ':.'))
6179
for name in keys(job.tests[testfile])
6280
let test = job.tests[testfile][name]
63-
put =printf('%s %s', s:state2char[test.state], name)
81+
call add(lines, printf('%s %s', s:state2char[test.state], name))
6482
endfor
6583
endfor
66-
put =''
84+
call add(lines, '')
6785
endfor
6886

69-
call winrestview(winview)
70-
setlocal nomodifiable nomodified
87+
if bufnr() == s:testrunner_bufnr | let winview = winsaveview() | endif
88+
call setbufvar(s:testrunner_bufnr, '&modifiable', 1)
89+
call deletebufline(s:testrunner_bufnr, 1, '$')
90+
call setbufline(s:testrunner_bufnr, 1, lines)
91+
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
92+
call setbufvar(s:testrunner_bufnr, '&modified', 0)
93+
if bufnr() == s:testrunner_bufnr |call winrestview(winview) | endif
7194
endfunction
7295

7396
function! OmniSharp#testrunner#SetTests(bufferTests) abort

syntax/omnisharptest.vim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ endif
55
let s:save_cpo = &cpoptions
66
set cpoptions&vim
77

8+
syn region ostIntro start="\%1l" end="^$" contains=ostIntroDelim transparent
9+
syn match ostIntroDelim "^=\+$" contained
10+
811
syn match ostStateNotRun "^|.*" contains=ostStateChar
912
syn match ostStateRunning "^-.*" contains=ostStateChar
1013
syn match ostStatePassed "^\*.*" contains=ostStateChar
11-
syn match ostStateFailed "^#.*" contains=ostStateChar
12-
syn match ostStateChar "^[|\*#-]" conceal contained
14+
syn match ostStateFailed "^!.*" contains=ostStateChar
15+
syn match ostStateChar "^[|\*!-]" conceal contained
16+
17+
hi def link ostIntroDelim PreProc
1318

1419
hi def link ostStateNotRun Comment
1520
hi def link ostStateRunning Identifier

0 commit comments

Comments
 (0)