Skip to content

Commit 0d0a8d8

Browse files
committed
Add test Discover function
1 parent a0b6da2 commit 0d0a8d8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

autoload/OmniSharp/testrunner.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,49 @@ function! OmniSharp#testrunner#GetTests() abort
1212
endfunction
1313

1414

15+
" Discover all tests in the project.
16+
" Optional argument: A dict containing the following optional items:
17+
" Callback: funcref to be called after the response is returned
18+
" Display: flag indicating that the tests should immediately be displayed in
19+
" the testrunner
20+
function! OmniSharp#testrunner#Discover(bufnr, ...) abort
21+
if a:0 && type(a:1) == type(function('tr'))
22+
let opts = { 'Callback': a:1 }
23+
else
24+
let opts = a:0 ? a:1 : {}
25+
endif
26+
let opts.Display = get(opts, 'Display', 1)
27+
if !has_key(OmniSharp#GetHost(a:bufnr), 'project')
28+
" Fetch the project structure, then call this function again
29+
call OmniSharp#actions#project#Get(a:bufnr,
30+
\ function('OmniSharp#testrunner#Discover', [a:bufnr, opts]))
31+
return
32+
endif
33+
let project = OmniSharp#GetHost(a:bufnr).project
34+
let opts = {
35+
\ 'ResponseHandler': function('s:DiscoverRH', [a:bufnr, opts]),
36+
\ 'BufNum': a:bufnr,
37+
\ 'Parameters': {
38+
\ 'TargetFrameworkVersion': project['MsBuildProject']['TargetFramework']
39+
\ },
40+
\ 'SendBuffer': 0
41+
\}
42+
call OmniSharp#stdio#Request('/v2/discovertests', opts)
43+
endfunction
44+
45+
function! s:DiscoverRH(bufnr, opts, response) abort
46+
if !a:response.Success | return | endif
47+
let project = OmniSharp#GetHost(a:bufnr).project
48+
let project.tests = a:response.Body.Tests
49+
if a:opts.Display
50+
" TODO: add tests to testrunner display
51+
endif
52+
if has_key(a:opts, 'Callback')
53+
call a:opts.Callback(a:response)
54+
endif
55+
endfunction
56+
57+
1558
function! OmniSharp#testrunner#Debug() abort
1659
let filename = ''
1760
let line = getline('.')

0 commit comments

Comments
 (0)