Skip to content

Commit e06b571

Browse files
committed
Handle server-side errors and failed builds
1 parent 84127ca commit e06b571

File tree

3 files changed

+69
-52
lines changed

3 files changed

+69
-52
lines changed

autoload/OmniSharp/actions/test.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ endfunction
7676
function! s:debug.complete(response) abort
7777
if !a:response.Success
7878
call s:utils.log.warn(['Error debugging unit test', a:response.Message])
79+
call OmniSharp#testrunner#StateError(s:debug.bufnr,
80+
\ split(trim(a:response.Message), '\r\?\n', 1))
81+
else
82+
call OmniSharp#testrunner#StateSkipped(s:debug.bufnr)
7983
endif
80-
call OmniSharp#testrunner#StateSkipped(s:debug.bufnr)
8184
endfunction
8285

8386
function! s:debug.process.start(command) abort
@@ -273,8 +276,14 @@ endfunction
273276
" Response handler used when running a single test, or multiple tests in files
274277
function! s:run.process(Callback, bufnr, tests, response) abort
275278
let s:run.running = 0
276-
if !a:response.Success | return | endif
279+
if !a:response.Success
280+
call OmniSharp#testrunner#StateError(a:bufnr,
281+
\ split(trim(eval(a:response.Message)), '\r\?\n', 1))
282+
return s:utils.log.warn('An error has occurred. This may indicate a failed build')
283+
endif
277284
if type(a:response.Body.Results) != type([])
285+
call OmniSharp#testrunner#StateError(a:bufnr,
286+
\ split(trim(a:response.Body.Failure), '\r\?\n', 1))
278287
return s:utils.log.warn('Error: "' . a:response.Body.Failure .
279288
\ '" - this may indicate a failed build')
280289
endif

autoload/OmniSharp/testrunner.vim

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ function! s:Paint() abort
7171
let job = OmniSharp#proc#GetJob(sln_or_dir)
7272
if !has_key(job, 'tests') | continue | endif
7373
for testproject in sort(keys(job.tests))
74-
call add(lines, testproject)
74+
let errors = get(get(job, 'testerrors', {}), testproject, [])
75+
call add(lines, testproject . (len(errors) ? ' - ERROR' : ''))
76+
for errorline in errors
77+
call add(lines, '< ' . trim(errorline, ' ', 2))
78+
endfor
7579
for testfile in sort(keys(job.tests[testproject]))
7680
call add(lines, ' ' . fnamemodify(testfile, ':.'))
7781
let tests = job.tests[testproject][testfile]
@@ -82,33 +86,24 @@ function! s:Paint() abort
8286
if state ==# '-' && !has_key(test, 'spintimer')
8387
call s:spinner.start(test, len(lines))
8488
endif
85-
let message = get(test, 'message', [])
86-
if len(message)
87-
for messageline in message
88-
call add(lines, '> ' . trim(messageline, ' ', 2))
89-
endfor
90-
endif
91-
let stacktrace = get(test, 'stacktrace', [])
92-
if len(stacktrace)
93-
for st in stacktrace
94-
let line = trim(st.text)
95-
if has_key(st, 'filename')
96-
let line = '__ ' . line . ' __'
97-
else
98-
let line = '_._ ' . line . ' _._'
99-
endif
100-
if has_key(st, 'lnum')
101-
let line .= ' line ' . st.lnum
102-
endif
103-
call add(lines, '> ' . line)
104-
endfor
105-
endif
106-
let output = get(test, 'output', [])
107-
if len(output)
108-
for outputline in output
109-
call add(lines, '// ' . trim(outputline, ' ', 2))
110-
endfor
111-
endif
89+
for messageline in get(test, 'message', [])
90+
call add(lines, '> ' . trim(messageline, ' ', 2))
91+
endfor
92+
for stacktraceline in get(test, 'stacktrace', [])
93+
let line = trim(stacktraceline.text)
94+
if has_key(stacktraceline, 'filename')
95+
let line = '__ ' . line . ' __'
96+
else
97+
let line = '_._ ' . line . ' _._'
98+
endif
99+
if has_key(stacktraceline, 'lnum')
100+
let line .= ' line ' . stacktraceline.lnum
101+
endif
102+
call add(lines, '> ' . line)
103+
endfor
104+
for outputline in get(test, 'output', [])
105+
call add(lines, '// ' . trim(outputline, ' ', 2))
106+
endfor
112107
endfor
113108
call add(lines, '__')
114109
endfor
@@ -151,17 +146,19 @@ function! OmniSharp#testrunner#SetTests(bufferTests) abort
151146
call win_gotoid(winid)
152147
endfunction
153148

154-
function! s:UpdateState(bufnr, testnames, state, ...) abort
155-
let message = a:0 ? a:1 : []
156-
let stacktraceraw = a:0 > 1 ? a:2 : []
157-
let output = a:0 > 2 ? a:3 : []
149+
function! s:UpdateState(bufnr, state, ...) abort
150+
let opts = a:0 ? a:1 : {}
151+
let job = OmniSharp#GetHost(a:bufnr).job
158152
let projectname = s:utils.getProjectName(a:bufnr)
153+
let job.testerrors = get(job, 'testerrors', {})
154+
let job.testerrors[projectname] = get(opts, 'errors', [])
155+
" TODO: parse errors like the stacktrace
159156
let filename = fnamemodify(bufname(a:bufnr), ':p')
160-
let tests = OmniSharp#GetHost(a:bufnr).job.tests[projectname][filename]
161-
for testname in a:testnames
157+
let tests = job.tests[projectname][filename]
158+
for testname in get(opts, 'testnames', s:lasttestnames)
162159
if has_key(tests, testname)
163160
let stacktrace = []
164-
for st in stacktraceraw
161+
for st in get(opts, 'stacktrace', [])
165162
let parsed = matchlist(st, 'at \(.\+\) in \([^:]\+\)\(:line \(\d\+\)\)\?')
166163
if len(parsed)
167164
call add(stacktrace, {
@@ -180,20 +177,14 @@ function! s:UpdateState(bufnr, testnames, state, ...) abort
180177
endfor
181178

182179
let tests[testname].state = a:state
183-
let tests[testname].message = message
180+
let tests[testname].message = get(opts, 'message', [])
184181
let tests[testname].stacktrace = stacktrace
185-
let tests[testname].output = output
182+
let tests[testname].output = get(opts, 'output', [])
186183
endif
187184
endfor
188185
call s:Repaint()
189186
endfunction
190187

191-
function! OmniSharp#testrunner#StateRunning(bufnr, testnames) abort
192-
let testnames = type(a:testnames) == type([]) ? a:testnames : [a:testnames]
193-
let s:lasttestnames = testnames
194-
call s:UpdateState(a:bufnr, testnames, 'Running')
195-
endfunction
196-
197188
function! OmniSharp#testrunner#StateComplete(location) abort
198189
if get(a:location, 'type', '') ==# 'E'
199190
let state = 'Failed'
@@ -202,14 +193,26 @@ function! OmniSharp#testrunner#StateComplete(location) abort
202193
else
203194
let state = 'Passed'
204195
endif
205-
call s:UpdateState(a:.location.bufnr, [a:location.fullname], state,
206-
\ get(a:location, 'message', []),
207-
\ get(a:location, 'stacktrace', []),
208-
\ get(a:location, 'output', []))
196+
call s:UpdateState(a:.location.bufnr, state, {
197+
\ 'testnames': [a:location.fullname],
198+
\ 'message': get(a:location, 'message', []),
199+
\ 'stacktrace': get(a:location, 'stacktrace', []),
200+
\ 'output': get(a:location, 'output', [])
201+
\})
202+
endfunction
203+
204+
function! OmniSharp#testrunner#StateError(bufnr, messages) abort
205+
call s:UpdateState(a:bufnr, 'Not run', {'errors': a:messages})
206+
endfunction
207+
208+
function! OmniSharp#testrunner#StateRunning(bufnr, testnames) abort
209+
let testnames = type(a:testnames) == type([]) ? a:testnames : [a:testnames]
210+
let s:lasttestnames = testnames
211+
call s:UpdateState(a:bufnr, 'Running', {'testnames': testnames})
209212
endfunction
210213

211214
function! OmniSharp#testrunner#StateSkipped(bufnr) abort
212-
call s:UpdateState(a:bufnr, s:lasttestnames, 'Not run')
215+
call s:UpdateState(a:bufnr, 'Not run')
213216
endfunction
214217

215218

syntax/omnisharptest.vim

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

17-
syn region ostProject matchgroup=ostProjectName start="^\a.*" end="^$"me=s-1 contains=TOP transparent fold
17+
syn region ostProject start="^\a.*" end="^$"me=s-1 contains=TOP transparent fold
18+
syn match ostProjectName "^\a.*" contains=ostProjectError
19+
syn match ostProjectError " - ERROR$"hs=s+2 contained
1820
syn region ostFile start="^ \S.*" end="^__$"me=s-1 contains=TOP transparent fold
1921
syn match ostFileName "^ \S.*" contains=ostFilePath,ostFileExt
20-
syn match ostFilePath "^ \zs\%(\%(\w\+\.\)*\w\+\/\)*\ze\w\+\." conceal contained
22+
syn match ostFilePath "^ \zs\%(\%(\f\+\.\)*\f\+\/\)*\ze\f\+\." conceal contained
2123
syn match ostFileExt "\%(\.\w\+\)\+" conceal contained
2224
syn match ostFileDivider "^__$" conceal
2325

@@ -32,6 +34,8 @@ syn match ostRunningSuffix " -- .*" contained contains=ostRunningSpinner,ostRun
3234
syn match ostRunningSuffixDivider " \zs--" conceal contained
3335
syn match ostRunningSpinner " -- \zs.*" contained
3436

37+
syn region ostError start="^<" end="^[^<]"me=s-1 contains=ostErrorPrefix,ostStackFile,ostStackFileNoLoc
38+
syn match ostErrorPrefix "^<" conceal contained
3539
syn region ostFailure start="^>" end="^[^>]"me=s-1 contains=ostFailurePrefix,ostStackFile,ostStackFileNoLoc fold
3640
syn match ostFailurePrefix "^>" conceal contained
3741
syn region ostStackFile start=" __ "hs=e+1 end=" __" contains=ostStackFileDelimiter,ostStackFileNamespace contained keepend
@@ -48,6 +52,7 @@ hi def link ostBannerHelp Comment
4852
hi def link ostBannerMap PreProc
4953
hi def link ostBannerLink Identifier
5054
hi def link ostProjectName Identifier
55+
hi def link ostProjectError WarningMsg
5156
hi def link ostFileName TypeDef
5257
hi def link ostStateNotRun Comment
5358
hi def link ostStateRunning Identifier

0 commit comments

Comments
 (0)