Skip to content

Commit 8c6a0f6

Browse files
committed
Debug test from test runner
1 parent 92841ce commit 8c6a0f6

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

autoload/OmniSharp/actions/test.vim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,29 @@ let s:utils = {}
1111
let s:utils.init = {}
1212
let s:utils.log = {}
1313

14-
function! OmniSharp#actions#test#Debug(nobuild) abort
14+
function! OmniSharp#actions#test#Debug(nobuild, ...) abort
1515
if !s:utils.capabilities() | return | endif
1616
let s:nobuild = a:nobuild
1717
if !OmniSharp#util#HasVimspector()
1818
return s:utils.log.warn('Vimspector required to debug tests')
1919
endif
20-
call s:utils.initialize([bufnr('%')], s:debug.prepare)
20+
let bufnr = a:0 ? (type(a:1) == type('') ? bufnr(a:1) : a:1) : bufnr('%')
21+
let DebugTest = funcref('s:debug.prepare', [a:0 > 1 ? a:2 : ''])
22+
call s:utils.initialize([bufnr], DebugTest)
2123
endfunction
2224

23-
function! s:debug.prepare(bufferTests) abort
25+
function! s:debug.prepare(testName, bufferTests) abort
2426
let bufnr = a:bufferTests[0].bufnr
2527
let tests = a:bufferTests[0].tests
26-
let currentTest = s:utils.findTest(tests, '')
28+
let currentTest = s:utils.findTest(tests, a:testName)
2729
if type(currentTest) != type({})
2830
return s:utils.log.warn('No test found')
2931
endif
3032
let project = OmniSharp#GetHost(bufnr).project
3133
let targetFramework = project.MsBuildProject.TargetFramework
3234
let opts = {
3335
\ 'ResponseHandler': funcref('s:debug.launch', [bufnr, currentTest.name]),
36+
\ 'BufNum': bufnr,
3437
\ 'Parameters': {
3538
\ 'MethodName': currentTest.name,
3639
\ 'NoBuild': get(s:, 'nobuild', 0),

autoload/OmniSharp/testrunner.vim

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ let s:runner = get(s:, 'runner', {})
77

88

99
function! OmniSharp#testrunner#Debug() abort
10+
let filename = ''
11+
let line = getline('.')
12+
if line =~# '^\a' || line =~# '^ \f'
13+
return s:utils.log.warn('Select a test to debug')
14+
else
15+
let test = s:utils.findTest()
16+
if has_key(test, 'filename')
17+
call OmniSharp#actions#test#Debug(0, test.filename, test.name)
18+
endif
19+
endif
1020
endfunction
1121

1222

@@ -243,23 +253,18 @@ endfunction
243253

244254
function! OmniSharp#testrunner#SetBreakpoints() abort
245255
if !OmniSharp#util#HasVimspector()
246-
echohl WarningMsg
247-
echomsg 'Vimspector required to set breakpoints'
248-
echohl None
249-
return
256+
return s:utils.log.warn('Vimspector required to set breakpoints')
250257
endif
251258
let line = getline('.')
252259
" Stack trace with valid location (filename and possible line number)
253260
let parsed = matchlist(line, '^> \+__ .* ___ \(.*\) __ \%(line \(\d\+\)\)\?$')
254261
if len(parsed) && parsed[2] !=# ''
255262
call vimspector#SetLineBreakpoint(parsed[1], str2nr(parsed[2]))
256-
echomsg 'Break point set'
257-
return
263+
return s:utils.log.emphasize('Break point set')
258264
endif
259265
let test = s:utils.findTest()
260266
if !has_key(test, 'stacktrace')
261-
echo 'No breakpoints added'
262-
return
267+
return s:utils.log.emphasize('No breakpoints added')
263268
endif
264269
let bps = filter(copy(test.stacktrace),
265270
\ "has_key(v:val, 'filename') && has_key(v:val, 'lnum')")
@@ -268,7 +273,7 @@ function! OmniSharp#testrunner#SetBreakpoints() abort
268273
endfor
269274
let n = len(bps)
270275
let message = printf('%d break point%s set', n, n == 1 ? '' : 's')
271-
echomsg message
276+
return s:utils.log.emphasize(message)
272277
endfunction
273278

274279

@@ -434,6 +439,7 @@ endfunction
434439

435440

436441
let s:utils = {}
442+
let s:utils.log = {}
437443

438444
let s:utils.state2char = {
439445
\ 'Not run': '|',
@@ -474,6 +480,24 @@ function! s:utils.getProjectName(bufnr) abort
474480
return get(msbuildproject, 'AssemblyName', '_Default')
475481
endfunction
476482

483+
function! s:utils.log.echo(highlightGroup, message) abort
484+
let messageLines = type(a:message) == type([]) ? a:message : [a:message]
485+
execute 'echohl' a:highlightGroup
486+
for messageLine in messageLines
487+
echomsg messageLine
488+
endfor
489+
echohl None
490+
endfunction
491+
492+
function! s:utils.log.emphasize(message) abort
493+
call self.echo('Title', a:message)
494+
return 1
495+
endfunction
496+
497+
function! s:utils.log.warn(message) abort
498+
call self.echo('WarningMsg', a:message)
499+
return 0
500+
endfunction
477501

478502
let &cpoptions = s:save_cpo
479503
unlet s:save_cpo

0 commit comments

Comments
 (0)