diff --git a/autoload/OmniSharp/actions/workspace.vim b/autoload/OmniSharp/actions/workspace.vim index 98d8ab1de..171e8feb1 100644 --- a/autoload/OmniSharp/actions/workspace.vim +++ b/autoload/OmniSharp/actions/workspace.vim @@ -32,18 +32,24 @@ function! s:ProjectsRH(job, response) abort 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"))}) + 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") - if index(projectFolders, host.sln_or_dir) < 0 || !host.initialized - 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 - endif + 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$' + for running in OmniSharp#proc#ListRunningJobs() + if index(projectFolders, running) >= 0 + call OmniSharp#StopServer(running) + endif + endfor + endif endfunction let &cpoptions = s:save_cpo