Skip to content

Commit 222721c

Browse files
author
Minh-Tam TRAN
committed
feature (sln_scope_handling): stop running job only if completely covered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior
1 parent ee32c96 commit 222721c

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

autoload/OmniSharp.vim

+8-5
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ endfunction
106106
function! OmniSharp#FindSolutionOrDir(...) abort
107107
let interactive = a:0 ? a:1 : 1
108108
let bufnr = a:0 > 1 ? a:2 : bufnr('%')
109-
if empty(getbufvar(bufnr, 'OmniSharp_buf_server'))
109+
let cache = getbufvar(bufnr, 'OmniSharp_buf_server')
110+
if empty(cache) || index(OmniSharp#proc#ListJobs(), cache) < 0
110111
try
111112
let sln = s:FindSolution(interactive, bufnr)
113+
if sln != cache
112114
call setbufvar(bufnr, 'OmniSharp_buf_server', sln)
115+
endif
113116
catch
114117
return ''
115118
endtry
@@ -247,11 +250,11 @@ endfunction
247250

248251

249252
function! s:FindSolution(interactive, bufnr) abort
250-
let solution_files = s:FindSolutionsFiles(a:bufnr)
251-
if empty(solution_files)
252-
" This file has no parent solution, so check for running solutions
253-
return s:FindRunningServerForBuffer(a:bufnr)
253+
let running_server_for_buffer = s:FindRunningServerForBuffer(a:bufnr)
254+
if !empty(running_server_for_buffer)
255+
return running_server_for_buffer
254256
endif
257+
let solution_files = s:FindSolutionsFiles(a:bufnr)
255258

256259
if len(solution_files) == 1
257260
return solution_files[0]

autoload/OmniSharp/actions/workspace.vim

+35
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,41 @@ function! s:ProjectsRH(job, response) abort
3030
call OmniSharp#log#Log(a:job, 'Workspace complete: no projects')
3131
call OmniSharp#project#RegisterLoaded(a:job)
3232
endif
33+
34+
let projectFolders = mapnew(projects, {_,p -> fnamemodify(p.path, ':p:h') })
35+
for i in filter(range(1, bufnr('$')), {_,x -> bufexists(x) && !empty(getbufvar(x, "OmniSharp_host")) && getbufvar(x, "OmniSharp_host").sln_or_dir != a:job.sln_or_dir})
36+
let host = getbufvar(i, "OmniSharp_host")
37+
let filePath = fnamemodify(bufname(i), ':p')
38+
for projectFolder in projectFolders
39+
if stridx(filePath, projectFolder) == 0
40+
let host.sln_or_dir = a:job.sln_or_dir
41+
break
42+
endif
43+
endfor
44+
endfor
45+
46+
if a:job.sln_or_dir =~ '\.sln$' && get(g:, 'OmniSharp_stop_redundant_servers', 0)
47+
for runningJob in OmniSharp#proc#ListRunningJobs()
48+
let runningJobProjects = OmniSharp#proc#GetJob(running).projects
49+
let isCompletelyCoveredByNewestSolution = 1
50+
for i in range(1, len(runningJobProjects))
51+
let isProjectCoveredByNewestSolution = 0
52+
for j in range(1, len(projects))
53+
if runningJobProjects[i].path == projects[j].path
54+
let isProjectCoveredByNewestSolution = 1
55+
break
56+
endif
57+
endfor
58+
if !isProjectCoveredByNewestSolution
59+
let isCompletelyCoveredByNewestSolution = 0
60+
break
61+
endif
62+
endfor
63+
if isCompletelyCoveredByNewestSolution
64+
call OmniSharp#StopServer(runningJob)
65+
endif
66+
endfor
67+
endif
3368
endfunction
3469

3570
let &cpoptions = s:save_cpo

test/fixusings.vader

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Expect cs(should add required using):
4747

4848

4949
Given cs():
50+
<<<<<<< HEAD
5051
using System;
5152

5253
public class Test
@@ -106,6 +107,8 @@ Expect cs(should add another required using):
106107

107108

108109
Given cs():
110+
=======
111+
>>>>>>> 37fa24e (feature (sln_scope_handling): stop running job only if completely covered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior)
109112
public class test {
110113
class1 ns1 = new class1();
111114
}
@@ -121,7 +124,11 @@ Given cs():
121124
}
122125

123126
Execute (run fix usings):
127+
<<<<<<< HEAD
124128
call OmniSharpTestInitializeBuffer('FixUsings5')
129+
=======
130+
call OmniSharpTestInitializeBuffer('FixUsings3')
131+
>>>>>>> 37fa24e (feature (sln_scope_handling): stop running job only if completely covered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior)
125132
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
126133
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
127134

@@ -141,7 +148,11 @@ Expect cs(should not add ambiguous using):
141148
}
142149

143150
Execute (should return ambiguous usings to Callback):
151+
<<<<<<< HEAD
144152
call OmniSharpTestInitializeBuffer('FixUsings6')
153+
=======
154+
call OmniSharpTestInitializeBuffer('FixUsings4')
155+
>>>>>>> 37fa24e (feature (sln_scope_handling): stop running job only if completely covered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior)
145156
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
146157
let g:OmniSharp_test_locations = []
147158
function! s:CallbackFixUsings(locations)
@@ -162,7 +173,11 @@ Execute (should return ambiguous usings to Callback):
162173
AssertEqual g:OmniSharp_test_locations[0].lnum, 2
163174

164175
Execute (should add ambiguous usings to quickfix):
176+
<<<<<<< HEAD
165177
call OmniSharpTestInitializeBuffer('FixUsings7')
178+
=======
179+
call OmniSharpTestInitializeBuffer('FixUsings5')
180+
>>>>>>> 37fa24e (feature (sln_scope_handling): stop running job only if completely covered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior)
166181
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
167182
" Cannot use OmniSharpTestAwait, as the callback prevents the default quickfix
168183
" behaviour

0 commit comments

Comments
 (0)