Skip to content

Commit de51104

Browse files
committed
Use /projects endpoint as part of load process
1 parent b09b00d commit de51104

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let s:save_cpo = &cpoptions
2+
set cpoptions&vim
3+
4+
let s:attempts = 0
5+
6+
function! OmniSharp#actions#workspace#Get(job) abort
7+
let opts = {
8+
\ 'ResponseHandler': function('s:ProjectsRH', [a:job]),
9+
\ 'AllowUnloaded': 1
10+
\}
11+
let s:attempts += 1
12+
call OmniSharp#stdio#RequestGlobal(a:job, '/projects', opts)
13+
endfunction
14+
15+
function! s:ProjectsRH(job, response) abort
16+
" If this request fails, retry up to 5 times
17+
if !a:response.Success
18+
if s:attempts < 5
19+
call OmniSharp#actions#workspace#Get(a:job)
20+
endif
21+
return
22+
endif
23+
" If no projects have been loaded by the time this callback is reached, there
24+
" are no projects and the job can be marked as ready
25+
let projects = get(get(a:response.Body, 'MsBuild', {}), 'Projects', {})
26+
let a:job.projects = map(projects,
27+
\ {_,project -> {"name": project.AssemblyName, "path": project.Path}})
28+
if get(a:job, 'projects_total', 0) > 0
29+
call OmniSharp#log#Log(a:job, 'Workspace complete: ' . a:job.projects_total . ' project(s)')
30+
else
31+
call OmniSharp#log#Log(a:job, 'Workspace complete: no projects')
32+
call OmniSharp#project#RegisterLoaded(a:job)
33+
endif
34+
endfunction
35+
36+
let &cpoptions = s:save_cpo
37+
unlet s:save_cpo
38+
39+
" vim:et:sw=2:sts=2

autoload/OmniSharp/project.vim

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,38 @@ function! OmniSharp#project#CountTotal() abort
1313
return get(OmniSharp#proc#GetJob(host.sln_or_dir), 'projects_total', 0)
1414
endfunction
1515

16+
function! OmniSharp#project#RegisterLoaded(job) abort
17+
if a:job.loaded | return | endif
18+
if g:OmniSharp_server_display_loading
19+
let elapsed = reltimefloat(reltime(a:job.start_time))
20+
echomsg printf('Loaded server for %s in %.1fs',
21+
\ a:job.sln_or_dir, elapsed)
22+
endif
23+
let a:job.loaded = 1
24+
silent doautocmd <nomodeline> User OmniSharpReady
25+
26+
" TODO: Remove this delay once we have better information about
27+
" when the server is completely initialised:
28+
" https://github.com/OmniSharp/omnisharp-roslyn/issues/1521
29+
call timer_start(1000, function('OmniSharp#stdio#ReplayRequests', [a:job]))
30+
" call OmniSharp#stdio#ReplayRequests(a:job)
31+
endfunction
32+
1633
" Listen for stdio server-loaded events
1734
function! OmniSharp#project#ParseEvent(job, event, eventBody) abort
1835
if g:OmniSharp_server_stdio_quickload
1936

20-
" Quick load: Mark server as loaded as soon as configuration is finished
37+
" Quick load: Mark server as ready as soon as configuration is finished.
38+
" WARNING: This will _not_ result in fully functional server interaction.
2139
if a:job.loaded | return | endif
2240
let message = get(a:eventBody, 'Message', '')
2341
if message ==# 'Configuration finished.'
24-
let a:job.loaded = 1
25-
silent doautocmd <nomodeline> User OmniSharpReady
26-
call OmniSharp#stdio#ReplayRequests()
42+
call OmniSharp#project#RegisterLoaded(a:job)
2743
endif
2844

2945
else
3046

31-
" Complete load: Wait for all projects to be loaded before marking server as
32-
" loaded
47+
" Full load: Wait for all projects to load before marking server as ready
3348
let projects_loaded = get(a:job, 'projects_loaded', 0)
3449
let projects_total = get(a:job, 'projects_total', 0)
3550
if a:job.loaded && projects_loaded == projects_total | return | endif
@@ -46,7 +61,9 @@ function! OmniSharp#project#ParseEvent(job, event, eventBody) abort
4661
endif
4762
let name = get(a:eventBody, 'Name', '')
4863
let message = get(a:eventBody, 'Message', '')
49-
if name ==# 'OmniSharp.MSBuild.ProjectManager'
64+
if a:event ==# 'started'
65+
call OmniSharp#actions#workspace#Get(a:job)
66+
elseif name ==# 'OmniSharp.MSBuild.ProjectManager'
5067
let project = matchstr(message, '''\zs.*\ze''')
5168
if message =~# '^Queue project'
5269
call add(a:job.loading, project)
@@ -64,20 +81,7 @@ function! OmniSharp#project#ParseEvent(job, event, eventBody) abort
6481
let a:job.projects_loaded = projects_loaded + 1
6582
silent doautocmd <nomodeline> User OmniSharpProjectUpdated
6683
if len(a:job.loading) == 0
67-
if g:OmniSharp_server_display_loading
68-
let elapsed = reltimefloat(reltime(a:job.start_time))
69-
echomsg printf('Loaded server for %s in %.1fs',
70-
\ a:job.sln_or_dir, elapsed)
71-
endif
72-
let a:job.loaded = 1
73-
silent doautocmd <nomodeline> User OmniSharpReady
74-
75-
" TODO: Remove this delay once we have better information about
76-
" when the server is completely initialised:
77-
" https://github.com/OmniSharp/omnisharp-roslyn/issues/1521
78-
call timer_start(1000, function('OmniSharp#stdio#ReplayRequests'))
79-
" call OmniSharp#stdio#ReplayRequests()
80-
84+
call OmniSharp#project#RegisterLoaded(a:job)
8185
unlet a:job.loading
8286
call timer_stop(a:job.loading_timeout)
8387
unlet a:job.loading_timeout

autoload/OmniSharp/stdio.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ function! s:Request(job, body, command, opts, ...) abort
196196
return 1
197197
endfunction
198198

199-
function! OmniSharp#stdio#ReplayRequests(...) abort
199+
function! OmniSharp#stdio#ReplayRequests(job, ...) abort
200+
call OmniSharp#log#Log(a:job, 'Replaying requests')
200201
for key in keys(s:pendingRequests)
201202
call OmniSharp#stdio#Request(key, s:pendingRequests[key])
202203
unlet s:pendingRequests[key]

0 commit comments

Comments
 (0)