@@ -48,7 +48,6 @@ function! OmniSharp#testrunner#FoldText() abort
48
48
elseif line = ~# ' ^ \f'
49
49
" File
50
50
let filename = trim (line )
51
- let fullpath = fnamemodify (filename, ' :p' )
52
51
let displayname = matchlist (filename, ' ^\f\{-}\([^/\\]\+\)\.csx\?$' )[1 ]
53
52
" Position the cursor so that search() is relative to the fold, not the
54
53
" actual cursor position
@@ -57,7 +56,7 @@ function! OmniSharp#testrunner#FoldText() abort
57
56
let projectline = search (' ^;' , ' bcnWz' )
58
57
call winrestview (winview)
59
58
let projectkey = matchlist (getline (projectline), ' ^\S\+' )[0 ]
60
- let ntests = len (s: tests [projectkey].files [fullpath ].tests)
59
+ let ntests = len (s: tests [projectkey].files [filename ].tests)
61
60
return printf (' %s [%d]' , displayname, ntests)
62
61
elseif line = ~# ' ^<'
63
62
return printf (' Error details (%d lines)' , v: foldend - v: foldstart + 1 )
@@ -106,7 +105,7 @@ function! OmniSharp#testrunner#Remove() abort
106
105
let s: tests [projectkey].visible = 0
107
106
elseif line = ~# ' ^ \f'
108
107
" File selected
109
- let filename = fnamemodify ( trim (line ), ' :p ' )
108
+ let filename = trim (line )
110
109
let projectline = search (' ^;' , ' bcnWz' )
111
110
let projectkey = matchlist (getline (projectline), ' ^\S\+' )[0 ]
112
111
let s: tests [projectkey].files [filename].visible = 0
@@ -225,23 +224,9 @@ function! s:buffer.focus() abort
225
224
return v: false
226
225
endfunction
227
226
228
- function ! s: buffer .bannerlines () abort
229
- let lines = []
230
- let delimiter = get (g: , ' OmniSharp_testrunner_banner_delimeter' , ' ─' )
231
- call add (lines , ' `' . repeat (delimiter , 80 ))
232
- call add (lines , ' ` OmniSharp Test Runner' )
233
- call add (lines , ' ` ' . repeat (delimiter , 76 ))
234
- call add (lines , ' ` <F1> Toggle this menu (:help omnisharp-test-runner for more)' )
235
- call add (lines , ' ` <F5> Run test or tests in file under cursor' )
236
- call add (lines , ' ` <F6> Debug test under cursor' )
237
- call add (lines , ' ` <CR> Navigate to test or stack trace' )
238
- call add (lines , ' `' . repeat (delimiter , 80 ))
239
- return lines
240
- endfunction
241
-
242
227
function ! s: buffer .paint () abort
243
228
if get (g: , ' OmniSharp_testrunner_banner' , 1 )
244
- let lines = self .bannerlines ()
229
+ let lines = self .paintbanner ()
245
230
else
246
231
let lines = []
247
232
endif
@@ -271,33 +256,10 @@ function! s:buffer.paint() abort
271
256
for testfile in sort (keys (s: tests [key ].files ))
272
257
if ! s: tests [key ].files [testfile].visible | continue | endif
273
258
let tests = s: tests [key ].files [testfile].tests
274
- call add (lines , ' ' . fnamemodify ( testfile, ' :. ' ) )
259
+ call add (lines , ' ' . testfile)
275
260
for name in sort (keys (tests), {a ,b - > tests[a ].lnum > tests[b ].lnum})
276
261
let test = tests[name]
277
- if test.state == # ' hidden' | continue | endif
278
- let state = s: utils .state2char[test.state ]
279
- call add (lines , printf (' %s %s' , state , name))
280
- if state == # ' -' && ! has_key (test, ' spintimer' )
281
- call s: spinner .start (test, len (lines ))
282
- endif
283
- for messageline in get (test, ' message' , [])
284
- call add (lines , ' > ' . trim (messageline, ' ' , 2 ))
285
- endfor
286
- for stacktraceline in get (test, ' stacktrace' , [])
287
- let line = trim (stacktraceline.text)
288
- if has_key (stacktraceline, ' filename' )
289
- let line = ' __ ' . line . ' ___ ' . stacktraceline.filename . ' __ '
290
- else
291
- let line = ' _._ ' . line . ' _._ '
292
- endif
293
- if has_key (stacktraceline, ' lnum' )
294
- let line .= ' line ' . stacktraceline.lnum
295
- endif
296
- call add (lines , ' > ' . line )
297
- endfor
298
- for outputline in get (test, ' output' , [])
299
- call add (lines , ' // ' . trim (outputline, ' ' , 2 ))
300
- endfor
262
+ call extend (lines , self .painttest (test, len (lines ) + 1 ))
301
263
endfor
302
264
call add (lines , ' __' )
303
265
endfor
@@ -316,6 +278,51 @@ function! s:buffer.paint() abort
316
278
endif
317
279
endfunction
318
280
281
+ function ! s: buffer .paintbanner () abort
282
+ let lines = []
283
+ let delimiter = get (g: , ' OmniSharp_testrunner_banner_delimeter' , ' ─' )
284
+ call add (lines , ' `' . repeat (delimiter , 80 ))
285
+ call add (lines , ' ` OmniSharp Test Runner' )
286
+ call add (lines , ' ` ' . repeat (delimiter , 76 ))
287
+ call add (lines , ' ` <F1> Toggle this menu (:help omnisharp-test-runner for more)' )
288
+ call add (lines , ' ` <F5> Run test or tests in file under cursor' )
289
+ call add (lines , ' ` <F6> Debug test under cursor' )
290
+ call add (lines , ' ` <CR> Navigate to test or stack trace' )
291
+ call add (lines , ' `' . repeat (delimiter , 80 ))
292
+ return lines
293
+ endfunction
294
+
295
+ function ! s: buffer .painttest (test, lnum) abort
296
+ if a: test .state == # ' hidden'
297
+ return []
298
+ endif
299
+ let lines = []
300
+ let state = s: utils .state2char[a: test .state ]
301
+ call add (lines , printf (' %s %s' , state , a: test .name))
302
+ if state == # ' -' && ! has_key (a: test , ' spintimer' )
303
+ call s: spinner .start (a: test , a: lnum )
304
+ endif
305
+ for messageline in get (a: test , ' message' , [])
306
+ call add (lines , ' > ' . trim (messageline, ' ' , 2 ))
307
+ endfor
308
+ for stacktraceline in get (a: test , ' stacktrace' , [])
309
+ let line = trim (stacktraceline.text)
310
+ if has_key (stacktraceline, ' filename' )
311
+ let line = ' __ ' . line . ' ___ ' . stacktraceline.filename . ' __ '
312
+ else
313
+ let line = ' _._ ' . line . ' _._ '
314
+ endif
315
+ if has_key (stacktraceline, ' lnum' )
316
+ let line .= ' line ' . stacktraceline.lnum
317
+ endif
318
+ call add (lines , ' > ' . line )
319
+ endfor
320
+ for outputline in get (a: test , ' output' , [])
321
+ call add (lines , ' // ' . trim (outputline, ' ' , 2 ))
322
+ endfor
323
+ return lines
324
+ endfunction
325
+
319
326
320
327
function ! OmniSharp#testrunner#SetBreakpoints () abort
321
328
if ! OmniSharp#util#HasVimspector ()
@@ -397,19 +404,33 @@ function! s:UpdateState(bufnr, state, ...) abort
397
404
endif
398
405
endif
399
406
endfor
400
-
401
- let tests[testname].state = a: state
402
- let tests[testname].message = get (opts, ' message' , [])
403
- let tests[testname].stacktrace = stacktrace
404
- let tests[testname].output = get (opts, ' output' , [])
407
+ let test = tests[testname]
408
+ let test.state = a: state
409
+ let test.message = get (opts, ' message' , [])
410
+ let test.stacktrace = stacktrace
411
+ let test.output = get (opts, ' output' , [])
412
+
413
+ call setbufvar (s: runner .bufnr , ' &modifiable' , 1 )
414
+ let lines = getbufline (s: runner .bufnr , 1 , ' $' )
415
+ let pattern = ' ^ ' . substitute (filename, ' /' , ' \\/' , ' g' )
416
+ let fileline = match (lines , pattern) + 1
417
+ let pattern = ' ^[-|*!] ' . testname
418
+ let testline = match (lines , pattern, fileline) + 1
419
+
420
+ let patterns = [' ^[-|*!] \S' , ' ^__$' , ' ^$' ]
421
+ let endline = min (
422
+ \ filter (
423
+ \ map (
424
+ \ patterns,
425
+ \ {_,pattern - > match (lines , pattern, testline)}),
426
+ \ {_,matchline - > matchline >= testline}))
427
+ let testlines = s: buffer .painttest (test, testline)
428
+ call deletebufline (s: runner .bufnr , testline, endline)
429
+ call appendbufline (s: runner .bufnr , testline - 1 , testlines)
430
+ call setbufvar (s: runner .bufnr , ' &modifiable' , 0 )
431
+ call setbufvar (s: runner .bufnr , ' &modified' , 0 )
405
432
endif
406
433
endfor
407
- let l: winid = win_getid ()
408
- let l: focused = s: buffer .focus ()
409
- call s: buffer .paint ()
410
- if l: focused
411
- call win_gotoid (l: winid )
412
- endif
413
434
endfunction
414
435
415
436
function ! OmniSharp#testrunner#StateComplete (location) abort
@@ -449,9 +470,9 @@ function! OmniSharp#testrunner#ToggleBanner() abort
449
470
let displayed = getline (1 ) = ~# ' `'
450
471
call setbufvar (s: runner .bufnr , ' &modifiable' , 1 )
451
472
if g: OmniSharp_testrunner_banner && ! displayed
452
- call appendbufline (s: runner .bufnr , 0 , s: buffer .bannerlines ())
473
+ call appendbufline (s: runner .bufnr , 0 , s: buffer .paintbanner ())
453
474
elseif ! g: OmniSharp_testrunner_banner && displayed
454
- call deletebufline (s: runner .bufnr , 1 , len (s: buffer .bannerlines ()))
475
+ call deletebufline (s: runner .bufnr , 1 , len (s: buffer .paintbanner ()))
455
476
endif
456
477
call setbufvar (s: runner .bufnr , ' &modifiable' , 0 )
457
478
call setbufvar (s: runner .bufnr , ' &modified' , 0 )
@@ -481,22 +502,27 @@ let s:spinner.steps_utf8 = [
481
502
function ! s: spinner .spin (test, lnum, timer) abort
482
503
if s: utils .state2char[a: test .state ] !=# ' -'
483
504
call timer_stop (a: timer )
484
- return
485
505
endif
486
506
let lnum = a: lnum + (get (g: , ' OmniSharp_testrunner_banner' , 1 ) ? 8 : 0 )
487
507
let lines = getbufline (s: runner .bufnr , lnum)
488
508
if len (lines ) == 0
489
509
call timer_stop (a: timer )
490
510
return
491
511
endif
512
+ " TODO: find the test by name, instead of line number
492
513
let line = lines [0 ]
493
514
let steps = get (g: , ' OmniSharp_testrunner_spinnersteps' ,
494
515
\ get (g: , ' OmniSharp_testrunner_spinner_ascii' )
495
516
\ ? self .steps_ascii : self .steps_utf8)
496
517
if ! has_key (a: test .spinner, ' index' )
518
+ " Starting
497
519
let line .= ' -- ' . steps[0 ]
498
520
let a: test .spinner.index = 0
521
+ elseif s: utils .state2char[a: test .state ] !=# ' -'
522
+ " Stopping
523
+ let line = substitute (line , ' -- .*$' , ' ' , ' ' )
499
524
else
525
+ " Stepping
500
526
let a: test .spinner.index += 1
501
527
if a: test .spinner.index >= len (steps)
502
528
let a: test .spinner.index = 0
@@ -545,7 +571,6 @@ function! s:utils.findTest() abort
545
571
let projectkey = matchlist (getline (projectline), ' ^\S\+' )[0 ]
546
572
let fileline = search (' ^ \f' , ' bcnWz' )
547
573
let filename = matchlist (getline (fileline), ' ^ \zs.*$' )[0 ]
548
- let filename = fnamemodify (filename, ' :p' )
549
574
return s: tests [projectkey].files [filename].tests[testname]
550
575
endif
551
576
return {}
0 commit comments