Skip to content

Commit f873429

Browse files
committed
Navigate to test locations
1 parent 7e0756d commit f873429

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

autoload/OmniSharp/testrunner.vim

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,102 @@ set cpoptions&vim
55
let s:current = get(s:, 'current', {})
66
let s:runner = get(s:, 'runner', {})
77

8+
9+
function! OmniSharp#testrunner#Debug() abort
10+
endfunction
11+
12+
813
function! OmniSharp#testrunner#Init(buffers) abort
914
let s:current.log = []
1015
let s:current.singlebuffer = len(a:buffers) == 1 ? a:buffers[0] : -1
1116
let s:current.testnames = {}
1217
endfunction
1318

19+
1420
function! OmniSharp#testrunner#Log(message) abort
1521
call extend(s:current.log, a:message)
1622
endfunction
1723

24+
25+
function! OmniSharp#testrunner#Run() abort
26+
endfunction
27+
28+
29+
function! OmniSharp#testrunner#Navigate() abort
30+
if &filetype !=# 'omnisharptest' | return | endif
31+
let bufnr = -1
32+
let filename = ''
33+
let lnum = -1
34+
let col = -1
35+
let line = getline('.')
36+
if line =~# '^\a'
37+
" Project selected - do nothing
38+
elseif line =~# '^ \f'
39+
" File selected
40+
let filename = trim(line)
41+
let bufnr = bufnr(filename)
42+
else
43+
" Stack trace with valid location (filename and possible line number)
44+
let parsed = matchlist(line, '^> \+__ .* ___ \(.*\) __ \%(line \(\d\+\)\)\?$')
45+
if len(parsed)
46+
let filename = parsed[1]
47+
if parsed[2] !=# ''
48+
let lnum = str2nr(parsed[2])
49+
endif
50+
endif
51+
if filename ==# ''
52+
" Search for test
53+
let testpattern = '[-|*!] \S'
54+
if line =~# testpattern
55+
let testline = line('.')
56+
else
57+
let testline = search(testpattern, 'bcnWz')
58+
endif
59+
if testline > 0
60+
let testname = matchlist(getline(testline), '[-|*!] \zs.*$')[0]
61+
let projectline = search('^\a', 'bcnWz')
62+
let projectname = matchlist(getline(projectline), '^\S\+')[0]
63+
let fileline = search('^ \f', 'bcnWz')
64+
let filename = matchlist(getline(fileline), '^ \zs.*$')[0]
65+
let filename = fnamemodify(filename, ':p')
66+
for sln_or_dir in OmniSharp#proc#ListRunningJobs()
67+
let job = OmniSharp#proc#GetJob(sln_or_dir)
68+
if has_key(job, 'tests') && has_key(job.tests, projectname)
69+
let lnum = job.tests[projectname][filename][testname].lnum
70+
break
71+
endif
72+
endfor
73+
endif
74+
endif
75+
endif
76+
if bufnr == -1
77+
if filename !=# ''
78+
let bufnr = bufnr(filename)
79+
if bufnr == -1
80+
let bufnr = bufadd(filename)
81+
call bufload(bufnr)
82+
endif
83+
endif
84+
if bufnr == -1 | return | endif
85+
endif
86+
for winnr in range(1, winnr('$'))
87+
if winbufnr(winnr) == bufnr
88+
call win_gotoid(win_getid(winnr))
89+
break
90+
endif
91+
endfor
92+
if bufnr() != bufnr
93+
execute 'aboveleft split' filename
94+
endif
95+
if lnum != -1
96+
call cursor(lnum, max([col, 0]))
97+
if col == -1
98+
normal! ^
99+
endif
100+
endif
101+
endfunction
102+
103+
18104
function! OmniSharp#testrunner#Open() abort
19105
if !OmniSharp#actions#test#Validate() | return | endif
20106
call s:Open()

0 commit comments

Comments
 (0)