Skip to content

Commit

Permalink
feature (sln_scope_handling): stop running job only if completely cov…
Browse files Browse the repository at this point in the history
…ered by newly started job. Use g:OmniSharp_stop_redundant_servers to change that default behavior
  • Loading branch information
Minh-Tam TRAN committed Oct 16, 2021
1 parent ee32c96 commit 222721c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
13 changes: 8 additions & 5 deletions autoload/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ endfunction
function! OmniSharp#FindSolutionOrDir(...) abort
let interactive = a:0 ? a:1 : 1
let bufnr = a:0 > 1 ? a:2 : bufnr('%')
if empty(getbufvar(bufnr, 'OmniSharp_buf_server'))
let cache = getbufvar(bufnr, 'OmniSharp_buf_server')
if empty(cache) || index(OmniSharp#proc#ListJobs(), cache) < 0
try
let sln = s:FindSolution(interactive, bufnr)
if sln != cache
call setbufvar(bufnr, 'OmniSharp_buf_server', sln)
endif
catch
return ''
endtry
Expand Down Expand Up @@ -247,11 +250,11 @@ endfunction


function! s:FindSolution(interactive, bufnr) abort
let solution_files = s:FindSolutionsFiles(a:bufnr)
if empty(solution_files)
" This file has no parent solution, so check for running solutions
return s:FindRunningServerForBuffer(a:bufnr)
let running_server_for_buffer = s:FindRunningServerForBuffer(a:bufnr)
if !empty(running_server_for_buffer)
return running_server_for_buffer
endif
let solution_files = s:FindSolutionsFiles(a:bufnr)

if len(solution_files) == 1
return solution_files[0]
Expand Down
35 changes: 35 additions & 0 deletions autoload/OmniSharp/actions/workspace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ function! s:ProjectsRH(job, response) abort
call OmniSharp#log#Log(a:job, 'Workspace complete: no projects')
call OmniSharp#project#RegisterLoaded(a:job)
endif

let projectFolders = mapnew(projects, {_,p -> fnamemodify(p.path, ':p:h') })
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})
let host = getbufvar(i, "OmniSharp_host")
let filePath = fnamemodify(bufname(i), ':p')
for projectFolder in projectFolders
if stridx(filePath, projectFolder) == 0
let host.sln_or_dir = a:job.sln_or_dir
break
endif
endfor
endfor

if a:job.sln_or_dir =~ '\.sln$' && get(g:, 'OmniSharp_stop_redundant_servers', 0)
for runningJob in OmniSharp#proc#ListRunningJobs()
let runningJobProjects = OmniSharp#proc#GetJob(running).projects
let isCompletelyCoveredByNewestSolution = 1
for i in range(1, len(runningJobProjects))
let isProjectCoveredByNewestSolution = 0
for j in range(1, len(projects))
if runningJobProjects[i].path == projects[j].path
let isProjectCoveredByNewestSolution = 1
break
endif
endfor
if !isProjectCoveredByNewestSolution
let isCompletelyCoveredByNewestSolution = 0
break
endif
endfor
if isCompletelyCoveredByNewestSolution
call OmniSharp#StopServer(runningJob)
endif
endfor
endif
endfunction

let &cpoptions = s:save_cpo
Expand Down
15 changes: 15 additions & 0 deletions test/fixusings.vader
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Expect cs(should add required using):


Given cs():
<<<<<<< HEAD
using System;

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


Given cs():
=======
>>>>>>> 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)
public class test {
class1 ns1 = new class1();
}
Expand All @@ -121,7 +124,11 @@ Given cs():
}

Execute (run fix usings):
<<<<<<< HEAD
call OmniSharpTestInitializeBuffer('FixUsings5')
=======
call OmniSharpTestInitializeBuffer('FixUsings3')
>>>>>>> 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)
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])

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

Execute (should return ambiguous usings to Callback):
<<<<<<< HEAD
call OmniSharpTestInitializeBuffer('FixUsings6')
=======
call OmniSharpTestInitializeBuffer('FixUsings4')
>>>>>>> 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)
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
let g:OmniSharp_test_locations = []
function! s:CallbackFixUsings(locations)
Expand All @@ -162,7 +173,11 @@ Execute (should return ambiguous usings to Callback):
AssertEqual g:OmniSharp_test_locations[0].lnum, 2

Execute (should add ambiguous usings to quickfix):
<<<<<<< HEAD
call OmniSharpTestInitializeBuffer('FixUsings7')
=======
call OmniSharpTestInitializeBuffer('FixUsings5')
>>>>>>> 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)
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
" Cannot use OmniSharpTestAwait, as the callback prevents the default quickfix
" behaviour
Expand Down

0 comments on commit 222721c

Please sign in to comment.