Skip to content

Commit d846e83

Browse files
committed
Display diagnostic test output (build status)
1 parent 387b9b0 commit d846e83

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

autoload/OmniSharp/actions/test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ endfunction
424424
" code structures. All operations are performed asynchronously, and the
425425
" a:Callback is called when all buffer code structures have been fetched.
426426
function! s:utils.initialize(buffers, Callback) abort
427+
call OmniSharp#testrunner#Init(a:buffers)
427428
call s:utils.init.await(a:buffers, 'OmniSharp#actions#project#Get',
428429
\ funcref('s:utils.init.await', [a:buffers, 'OmniSharp#actions#codestructure#Get',
429430
\ funcref('s:utils.init.extract', [a:Callback])]))

autoload/OmniSharp/stdio.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ function! s:HandleServerEvent(job, res) abort
106106

107107
" Diagnostics received while running tests
108108
if get(a:res, 'Event', '') ==# 'TestMessage'
109-
let lines = split(body.Message, '\n')
109+
let lines = split(body.Message, '\r\?\n')
110+
call OmniSharp#testrunner#Log(lines)
110111
for line in lines
111112
if get(body, 'MessageLevel', '') ==# 'error'
112113
echohl WarningMsg | echomsg line | echohl None

autoload/OmniSharp/testrunner.vim

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ scriptencoding utf-8
22
let s:save_cpo = &cpoptions
33
set cpoptions&vim
44

5+
let s:current = get(s:, 'current', {})
6+
let s:runner = get(s:, 'runner', {})
7+
8+
function! OmniSharp#testrunner#Init(buffers) abort
9+
let s:current.log = []
10+
let s:current.singlebuffer = len(a:buffers) == 1 ? a:buffers[0] : -1
11+
let s:current.testnames = {}
12+
endfunction
13+
14+
function! OmniSharp#testrunner#Log(message) abort
15+
call extend(s:current.log, a:message)
16+
endfunction
17+
518
function! OmniSharp#testrunner#Open() abort
619
if !OmniSharp#actions#test#Validate() | return | endif
720
call s:Open()
@@ -30,18 +43,18 @@ function s:Open() abort
3043
if &filetype !=# ft
3144
botright new
3245
endif
33-
let s:testrunner_bufnr = bufnr()
46+
let s:runner.bufnr = bufnr()
3447
let &filetype = ft
3548
execute 'file' title
3649
call s:Paint()
3750
endfunction
3851

3952
function! s:Repaint() abort
40-
if !exists('s:testrunner_bufnr') | return | endif
41-
if getbufvar(s:testrunner_bufnr, '&ft') !=# 'omnisharptest' | return | endif
53+
if !has_key(s:runner, 'bufnr') | return | endif
54+
if getbufvar(s:runner.bufnr, '&ft') !=# 'omnisharptest' | return | endif
4255
" If the buffer is listed in a window in the current tab, then focus it
4356
for winnr in range(1, winnr('$'))
44-
if winbufnr(winnr) == s:testrunner_bufnr
57+
if winbufnr(winnr) == s:runner.bufnr
4558
let l:winid = win_getid()
4659
call win_gotoid(win_getid(winnr))
4760
break
@@ -76,6 +89,16 @@ function! s:Paint() abort
7689
for errorline in errors
7790
call add(lines, '< ' . trim(errorline, ' ', 2))
7891
endfor
92+
" The diagnostic logs (build output) are only displayed when a single file
93+
" is tested, otherwise multiple build outputs are intermingled
94+
if OmniSharp#GetHost(s:current.singlebuffer).sln_or_dir ==# sln_or_dir
95+
if len(errors) > 0 && len(s:current.log) > 1
96+
call add(lines, '< ' . repeat(delimiter, 10))
97+
endif
98+
for log in s:current.log
99+
call add(lines, '< ' . trim(log, ' ', 2))
100+
endfor
101+
endif
79102
for testfile in sort(keys(job.tests[testproject]))
80103
call add(lines, ' ' . fnamemodify(testfile, ':.'))
81104
let tests = job.tests[testproject][testfile]
@@ -111,13 +134,13 @@ function! s:Paint() abort
111134
call add(lines, '')
112135
endfor
113136

114-
if bufnr() == s:testrunner_bufnr | let winview = winsaveview() | endif
115-
call setbufvar(s:testrunner_bufnr, '&modifiable', 1)
116-
call deletebufline(s:testrunner_bufnr, 1, '$')
117-
call setbufline(s:testrunner_bufnr, 1, lines)
118-
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
119-
call setbufvar(s:testrunner_bufnr, '&modified', 0)
120-
if bufnr() == s:testrunner_bufnr
137+
if bufnr() == s:runner.bufnr | let winview = winsaveview() | endif
138+
call setbufvar(s:runner.bufnr, '&modifiable', 1)
139+
call deletebufline(s:runner.bufnr, 1, '$')
140+
call setbufline(s:runner.bufnr, 1, lines)
141+
call setbufvar(s:runner.bufnr, '&modifiable', 0)
142+
call setbufvar(s:runner.bufnr, '&modified', 0)
143+
if bufnr() == s:runner.bufnr
121144
call winrestview(winview)
122145
syn sync fromstart
123146
endif
@@ -152,10 +175,9 @@ function! s:UpdateState(bufnr, state, ...) abort
152175
let projectname = s:utils.getProjectName(a:bufnr)
153176
let job.testerrors = get(job, 'testerrors', {})
154177
let job.testerrors[projectname] = get(opts, 'errors', [])
155-
" TODO: parse errors like the stacktrace
156178
let filename = fnamemodify(bufname(a:bufnr), ':p')
157179
let tests = job.tests[projectname][filename]
158-
for testname in get(opts, 'testnames', s:lasttestnames)
180+
for testname in get(opts, 'testnames', s:current.testnames[a:bufnr])
159181
if has_key(tests, testname)
160182
let stacktrace = []
161183
for st in get(opts, 'stacktrace', [])
@@ -207,7 +229,7 @@ endfunction
207229

208230
function! OmniSharp#testrunner#StateRunning(bufnr, testnames) abort
209231
let testnames = type(a:testnames) == type([]) ? a:testnames : [a:testnames]
210-
let s:lasttestnames = testnames
232+
let s:current.testnames[a:bufnr] = testnames
211233
call s:UpdateState(a:bufnr, 'Running', {'testnames': testnames})
212234
endfunction
213235

@@ -216,7 +238,7 @@ function! OmniSharp#testrunner#StateSkipped(bufnr) abort
216238
endfunction
217239

218240

219-
function! OmniSharp#testrunner#toggleBanner() abort
241+
function! OmniSharp#testrunner#ToggleBanner() abort
220242
let g:OmniSharp_testrunner_banner = 1 - get(g:, 'OmniSharp_testrunner_banner', 1)
221243
call s:Paint()
222244
endfunction
@@ -247,7 +269,7 @@ function! s:spinner.spin(test, lnum, timer) abort
247269
return
248270
endif
249271
let lnum = a:lnum + (get(g:, 'OmniSharp_testrunner_banner', 1) ? 8 : 0)
250-
let lines = getbufline(s:testrunner_bufnr, lnum)
272+
let lines = getbufline(s:runner.bufnr, lnum)
251273
if len(lines) == 0
252274
call timer_stop(a:timer)
253275
return
@@ -267,10 +289,10 @@ function! s:spinner.spin(test, lnum, timer) abort
267289
let step = steps[a:test.spinner.index]
268290
let line = substitute(line, ' -- \zs.*$', step, '')
269291
endif
270-
call setbufvar(s:testrunner_bufnr, '&modifiable', 1)
271-
call setbufline(s:testrunner_bufnr, lnum, line)
272-
call setbufvar(s:testrunner_bufnr, '&modifiable', 0)
273-
call setbufvar(s:testrunner_bufnr, '&modified', 0)
292+
call setbufvar(s:runner.bufnr, '&modifiable', 1)
293+
call setbufline(s:runner.bufnr, lnum, line)
294+
call setbufvar(s:runner.bufnr, '&modifiable', 0)
295+
call setbufvar(s:runner.bufnr, '&modified', 0)
274296
endfunction
275297

276298
function! s:spinner.start(test, lnum) abort

ftplugin/omnisharptest/OmniSharp.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set foldlevel=2
66
set foldmethod=syntax
77
set signcolumn=no
88
9-
nnoremap <silent> <buffer> <F1> :call OmniSharp#testrunner#toggleBanner()<CR>
9+
nnoremap <silent> <buffer> <F1> :call OmniSharp#testrunner#ToggleBanner()<CR>

syntax/omnisharptest.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ syn match ostBannerDelim "\%1l^.*$" contained
1414
syn match ostBannerDelim "\%3l^.*$" contained
1515
syn match ostBannerDelim "\%8l^.*$" contained
1616

17-
syn region ostProject start="^\a.*" end="^$"me=s-1 contains=TOP transparent fold
1817
syn match ostProjectName "^\a.*" contains=ostProjectError
1918
syn match ostProjectError " - ERROR$"hs=s+2 contained
20-
syn region ostFile start="^ \S.*" end="^__$"me=s-1 contains=TOP transparent fold
19+
syn region ostProject start="^\a.*" end="^$"me=s-1 contains=TOP transparent fold
20+
syn region ostError start="^<" end="^[^<]"me=s-1 contains=ostErrorPrefix,ostStackFile,ostStackFileNoLoc fold
21+
syn match ostErrorPrefix "^<" conceal contained
2122
syn match ostFileName "^ \S.*" contains=ostFilePath,ostFileExt
2223
syn match ostFilePath "^ \zs\%(\%(\f\+\.\)*\f\+\/\)*\ze\f\+\." conceal contained
2324
syn match ostFileExt "\%(\.\w\+\)\+" conceal contained
25+
syn region ostFile start="^ \S.*" end="^__$"me=s-1 contains=TOP transparent fold
2426
syn match ostFileDivider "^__$" conceal
2527

2628
syn match ostStateNotRun "^|.*" contains=ostStatePrefix,ostTestNamespace
@@ -34,8 +36,6 @@ syn match ostRunningSuffix " -- .*" contained contains=ostRunningSpinner,ostRun
3436
syn match ostRunningSuffixDivider " \zs--" conceal contained
3537
syn match ostRunningSpinner " -- \zs.*" contained
3638

37-
syn region ostError start="^<" end="^[^<]"me=s-1 contains=ostErrorPrefix,ostStackFile,ostStackFileNoLoc
38-
syn match ostErrorPrefix "^<" conceal contained
3939
syn region ostFailure start="^>" end="^[^>]"me=s-1 contains=ostFailurePrefix,ostStackFile,ostStackFileNoLoc fold
4040
syn match ostFailurePrefix "^>" conceal contained
4141
syn region ostStackFile start=" __ "hs=e+1 end=" __" contains=ostStackFileDelimiter,ostStackFileNamespace contained keepend

0 commit comments

Comments
 (0)