Skip to content

Commit 00ec883

Browse files
committed
Display Console output and fold syntax regions
1 parent 4a4fac3 commit 00ec883

File tree

4 files changed

+135
-91
lines changed

4 files changed

+135
-91
lines changed

autoload/OmniSharp/actions/test.vim

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

4-
5-
" Function dict for debug-test functions
64
let s:debug = {}
75
let s:debug.process = {}
86
let s:run = {}
@@ -142,7 +140,7 @@ function! s:run.single.complete(summary) abort
142140
" call OmniSharp#testrunner#StateSkipped(bufnr)
143141
endif
144142
let location = a:summary.locations[0]
145-
call s:run.updatestate(location)
143+
call OmniSharp#testrunner#StateComplete(location)
146144
if a:summary.pass
147145
if get(location, 'type', '') ==# 'W'
148146
call s:utils.log.warn(location.name . ': skipped')
@@ -245,7 +243,7 @@ function! s:run.multiple.complete(summary) abort
245243
endif
246244
endfor
247245
for location in locations
248-
call s:run.updatestate(location)
246+
call OmniSharp#testrunner#StateComplete(location)
249247
endfor
250248
if pass
251249
let title = len(locations) . ' tests passed'
@@ -295,9 +293,11 @@ function! s:run.process(Callback, bufnr, tests, response) abort
295293
let locations = [location]
296294
" Write any standard output to message-history
297295
if len(get(result, 'StandardOutput', []))
296+
let location.output = []
298297
echomsg 'Standard output from test ' . location.name . ':'
299298
for output in result.StandardOutput
300299
for line in split(trim(output), '\r\?\n', 1)
300+
call add(location.output, line)
301301
echomsg ' ' . line
302302
endfor
303303
endfor
@@ -354,16 +354,6 @@ function! s:run.process(Callback, bufnr, tests, response) abort
354354
call a:Callback(summary)
355355
endfunction
356356

357-
function! s:run.updatestate(location) abort
358-
if get(a:location, 'type', '') ==# 'E'
359-
call OmniSharp#testrunner#StateFailed(a:location.bufnr, a:location.fullname)
360-
elseif get(a:location, 'type', '') ==# 'W'
361-
call OmniSharp#testrunner#StateSkipped(a:location.bufnr, a:location.fullname)
362-
else
363-
call OmniSharp#testrunner#StatePassed(a:location.bufnr, a:location.fullname)
364-
endif
365-
endfunction
366-
367357

368358
function! OmniSharp#actions#test#Validate() abort
369359
return s:utils.capabilities()

autoload/OmniSharp/testrunner.vim

Lines changed: 108 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
let s:save_cpo = &cpoptions
22
set cpoptions&vim
33

4-
let s:state2char = {
5-
\ 'Not run': '|',
6-
\ 'Running': '-',
7-
\ 'Passed': '*',
8-
\ 'Failed': '!'
9-
\}
10-
114
function! OmniSharp#testrunner#Open() abort
125
if !OmniSharp#actions#test#Validate() | return | endif
136
call s:Open()
@@ -37,9 +30,6 @@ function s:Open() abort
3730
botright new
3831
endif
3932
let s:testrunner_bufnr = bufnr()
40-
silent setlocal noswapfile signcolumn=no conceallevel=3 concealcursor=nv
41-
setlocal comments=:# commentstring=#\ %s
42-
set bufhidden=hide
4333
let &filetype = ft
4434
execute 'file' title
4535
call s:Paint()
@@ -70,18 +60,28 @@ function! s:Paint() abort
7060
call add(lines, '')
7161

7262
for sln_or_dir in OmniSharp#proc#ListRunningJobs()
73-
call add(lines, fnamemodify(sln_or_dir, ':t'))
7463
let job = OmniSharp#proc#GetJob(sln_or_dir)
7564
if !has_key(job, 'tests') | continue | endif
76-
for testfile in keys(job.tests)
77-
call add(lines, ' ' . fnamemodify(testfile, ':.'))
78-
for name in keys(job.tests[testfile])
79-
let test = job.tests[testfile][name]
80-
let state = s:state2char[test.state]
81-
call add(lines, printf('%s %s', state, name))
82-
if state ==# '-' && !has_key(test, 'spintimer')
83-
call s:SpinnerStart(test, len(lines))
84-
endif
65+
for testproject in sort(keys(job.tests))
66+
call add(lines, testproject)
67+
for testfile in sort(keys(job.tests[testproject]))
68+
call add(lines, ' ' . fnamemodify(testfile, ':.'))
69+
let tests = job.tests[testproject][testfile]
70+
for name in sort(keys(tests), {a,b -> tests[a].lnum > tests[b].lnum})
71+
let test = tests[name]
72+
let state = s:utils.state2char[test.state]
73+
call add(lines, printf('%s %s', state, name))
74+
if state ==# '-' && !has_key(test, 'spintimer')
75+
call s:spinner.start(test, len(lines))
76+
endif
77+
let output = get(test, 'output', [])
78+
if len(output)
79+
for outputline in output
80+
call add(lines, '// ' . outputline)
81+
endfor
82+
endif
83+
endfor
84+
call add(lines, '__')
8585
endfor
8686
endfor
8787
call add(lines, '')
@@ -93,54 +93,24 @@ function! s:Paint() abort
9393
call setbufline(s:testrunner_bufnr, 1, lines)
9494
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
9595
call setbufvar(s:testrunner_bufnr, '&modified', 0)
96-
if bufnr() == s:testrunner_bufnr |call winrestview(winview) | endif
97-
endfunction
98-
99-
function! s:SpinnerSpin(test, lnum, timer) abort
100-
if s:state2char[a:test.state] !=# '-'
101-
call timer_stop(a:timer)
102-
return
103-
endif
104-
let lines = getbufline(s:testrunner_bufnr, a:lnum)
105-
if len(lines) == 0
106-
call timer_stop(a:timer)
107-
return
108-
endif
109-
let line = lines[0]
110-
let steps = get(g:, 'OmniSharp_testrunner_spinnersteps', [
111-
\ '<*---->', '<-*--->', '<--*-->', '<---*->',
112-
\ '<----*>', '<---*->', '<--*-->', '<-*--->'])
113-
if !has_key(a:test.spinner, 'index')
114-
let line .= ' -- ' . steps[0]
115-
let a:test.spinner.index = 0
116-
else
117-
let a:test.spinner.index += 1
118-
if a:test.spinner.index >= len(steps)
119-
let a:test.spinner.index = 0
120-
endif
121-
let line = substitute(line, ' -- \zs.*$', steps[a:test.spinner.index], '')
96+
if bufnr() == s:testrunner_bufnr
97+
call winrestview(winview)
98+
syn sync fromstart
12299
endif
123-
call setbufvar(s:testrunner_bufnr, '&modifiable', 1)
124-
call setbufline(s:testrunner_bufnr, a:lnum, line)
125-
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
126-
call setbufvar(s:testrunner_bufnr, '&modified', 0)
127100
endfunction
128101

129-
function! s:SpinnerStart(test, lnum) abort
130-
let a:test.spinner = {}
131-
let a:test.spinner.timer = timer_start(300,
132-
\ funcref('s:SpinnerSpin', [a:test, a:lnum]),
133-
\ {'repeat': -1})
134-
endfunction
135102

136103
function! OmniSharp#testrunner#SetTests(bufferTests) abort
137104
let winid = win_getid()
138105
for buffer in a:bufferTests
139106
let job = OmniSharp#GetHost(buffer.bufnr).job
140107
let job.tests = get(job, 'tests', {})
108+
let projectname = s:utils.getProjectName(buffer.bufnr)
109+
let testproject = get(job.tests, projectname, {})
110+
let job.tests[projectname] = testproject
141111
let filename = fnamemodify(bufname(buffer.bufnr), ':p')
142-
let existing = get(job.tests, filename, {})
143-
let job.tests[filename] = existing
112+
let existing = get(testproject, filename, {})
113+
let testproject[filename] = existing
144114
for test in buffer.tests
145115
let extest = get(existing, test.name, { 'state': 'Not run' })
146116
let existing[test.name] = extest
@@ -152,13 +122,14 @@ function! OmniSharp#testrunner#SetTests(bufferTests) abort
152122
call win_gotoid(winid)
153123
endfunction
154124

155-
function! s:UpdateState(bufnr, testnames, state) abort
156-
let job = OmniSharp#GetHost(a:bufnr).job
125+
function! s:UpdateState(bufnr, testnames, state, output) abort
126+
let projectname = s:utils.getProjectName(a:bufnr)
157127
let filename = fnamemodify(bufname(a:bufnr), ':p')
158-
let tests = get(job.tests, filename, {})
128+
let tests = OmniSharp#GetHost(a:bufnr).job.tests[projectname][filename]
159129
for testname in a:testnames
160130
if has_key(tests, testname)
161131
let tests[testname].state = a:state
132+
let tests[testname].output = a:output
162133
endif
163134
endfor
164135
call s:Repaint()
@@ -167,24 +138,90 @@ endfunction
167138
function! OmniSharp#testrunner#StateRunning(bufnr, testnames) abort
168139
let testnames = type(a:testnames) == type([]) ? a:testnames : [a:testnames]
169140
let s:lasttestnames = testnames
170-
call s:UpdateState(a:bufnr, testnames, 'Running')
141+
call s:UpdateState(a:bufnr, testnames, 'Running', [])
171142
endfunction
172143

173-
function! OmniSharp#testrunner#StateSkipped(bufnr, ...) abort
174-
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
175-
call s:UpdateState(a:bufnr, testnames, 'Not run')
144+
function! OmniSharp#testrunner#StateComplete(location) abort
145+
if get(a:location, 'type', '') ==# 'E'
146+
let state = 'Failed'
147+
elseif get(a:location, 'type', '') ==# 'W'
148+
let state = 'Not run'
149+
else
150+
let state = 'Passed'
151+
endif
152+
let output = get(a:location, 'output', [])
153+
call s:UpdateState(a:.location.bufnr, [a:location.fullname], state, output)
176154
endfunction
177155

178-
function! OmniSharp#testrunner#StatePassed(bufnr, ...) abort
179-
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
180-
call s:UpdateState(a:bufnr, testnames, 'Passed')
156+
function! OmniSharp#testrunner#StateSkipped(bufnr) abort
157+
call s:UpdateState(a:bufnr, s:lasttestnames, 'Not run', [])
181158
endfunction
182159

183-
function! OmniSharp#testrunner#StateFailed(bufnr, ...) abort
184-
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
185-
call s:UpdateState(a:bufnr, testnames, 'Failed')
160+
161+
let s:spinner = {}
162+
let s:spinner.steps = get(g:, 'OmniSharp_testrunner_spinnersteps', [
163+
\ '<*---->',
164+
\ '<-*--->',
165+
\ '<--*-->',
166+
\ '<---*->',
167+
\ '<----*>',
168+
\ '<---*->',
169+
\ '<--*-->',
170+
\ '<-*--->'])
171+
172+
function! s:spinner.spin(test, lnum, timer) abort
173+
if s:utils.state2char[a:test.state] !=# '-'
174+
call timer_stop(a:timer)
175+
return
176+
endif
177+
let lines = getbufline(s:testrunner_bufnr, a:lnum)
178+
if len(lines) == 0
179+
call timer_stop(a:timer)
180+
return
181+
endif
182+
let line = lines[0]
183+
if !has_key(a:test.spinner, 'index')
184+
let line .= ' -- ' . s:spinner.steps[0]
185+
let a:test.spinner.index = 0
186+
else
187+
let a:test.spinner.index += 1
188+
if a:test.spinner.index >= len(s:spinner.steps)
189+
let a:test.spinner.index = 0
190+
endif
191+
let step = s:spinner.steps[a:test.spinner.index]
192+
let line = substitute(line, ' -- \zs.*$', step, '')
193+
endif
194+
call setbufvar(s:testrunner_bufnr, '&modifiable', 1)
195+
call setbufline(s:testrunner_bufnr, a:lnum, line)
196+
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
197+
call setbufvar(s:testrunner_bufnr, '&modified', 0)
186198
endfunction
187199

200+
function! s:spinner.start(test, lnum) abort
201+
if !get(g:, 'OmniSharp_testrunner_spinner', 1) | return | endif
202+
let a:test.spinner = {}
203+
let a:test.spinner.timer = timer_start(300,
204+
\ funcref('s:spinner.spin', [a:test, a:lnum], self),
205+
\ {'repeat': -1})
206+
endfunction
207+
208+
209+
let s:utils = {}
210+
211+
let s:utils.state2char = {
212+
\ 'Not run': '|',
213+
\ 'Running': '-',
214+
\ 'Passed': '*',
215+
\ 'Failed': '!'
216+
\}
217+
218+
function! s:utils.getProjectName(bufnr) abort
219+
let project = OmniSharp#GetHost(a:bufnr).project
220+
let msbuildproject = get(project, 'MsBuildProject', {})
221+
return get(msbuildproject, 'AssemblyName', '_Default')
222+
endfunction
223+
224+
188225
let &cpoptions = s:save_cpo
189226
unlet s:save_cpo
190227

ftplugin/omnisharptest/OmniSharp.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set bufhidden=hide
2+
set noswapfile
3+
set conceallevel=3
4+
set concealcursor=nv
5+
set foldlevel=2
6+
set foldmethod=syntax
7+
set signcolumn=no

syntax/omnisharptest.vim

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@ set cpoptions&vim
88
syn region ostIntro start="\%1l" end="^$" contains=ostIntroDelim transparent
99
syn match ostIntroDelim "^=\+$" contained
1010

11-
syn match ostStateNotRun "^|.*" contains=ostStateChar
12-
syn match ostStateRunning "^-.*" contains=ostStateChar,ostRunningSuffix
13-
syn match ostStatePassed "^\*.*" contains=ostStateChar
14-
syn match ostStateFailed "^!.*" contains=ostStateChar
15-
syn match ostStateChar "^[|\*!-]" conceal contained
11+
syn region ostProject matchgroup=ostProjectName start="^\a.*" end="^$"me=s-1 contains=TOP transparent fold
12+
syn region ostFile matchgroup=ostFileName start="^ \S.*" end="^__$"me=s-1 contains=TOP transparent fold
13+
syn match ostFileDivider "^__$" conceal
14+
15+
syn match ostStateNotRun "^|.*" contains=ostStatePrefix
16+
syn match ostStateRunning "^-.*" contains=ostStatePrefix,ostRunningSuffix
17+
syn match ostStatePassed "^\*.*" contains=ostStatePrefix
18+
syn match ostStateFailed "^!.*" contains=ostStatePrefix
19+
syn match ostStatePrefix "^[|\*!-]" conceal contained
20+
1621
syn match ostRunningSuffix " -- .*" contained contains=ostRunningSpinner,ostRunningSuffixDivider
1722
syn match ostRunningSuffixDivider " \zs--" conceal contained
1823
syn match ostRunningSpinner " -- \zs.*" contained
1924

20-
hi def link ostIntroDelim PreProc
25+
syn region ostOutput start="^//" end="^[^/]"me=s-1 contains=ostOutputPrefix fold
26+
syn match ostOutputPrefix "^//" conceal contained
2127

28+
hi def link ostIntroDelim PreProc
29+
hi def link ostProjectName Identifier
30+
hi def link ostFileName TypeDef
2231
hi def link ostStateNotRun Comment
2332
hi def link ostStateRunning Identifier
2433
hi def link ostRunningSpinner Normal
2534
hi def link ostStatePassed Title
2635
hi def link ostStateFailed WarningMsg
36+
hi def link ostOutput Comment
2737

2838
let b:current_syntax = 'omnisharptest'
2939

0 commit comments

Comments
 (0)