Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Improve sln scope handling #711

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions autoload/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ function! OmniSharp#CompleteRunningSln(arglead, cmdline, cursorpos) abort
return filter(jobs, {_,job -> job =~? a:arglead})
endfunction

function! OmniSharp#CompleteOtherRunningSlnOrDirCoveringCurrentFile(arglead, cmdline, cursorpos) abort
let slnsOrDirsCoveringCurrentFile = []
let filePath = fnamemodify(expand('%'), ':p')
let currentlyAssignedJob = get(OmniSharp#GetHost(), 'sln_or_dir')
for runningJob in filter(OmniSharp#proc#ListRunningJobs(), {_,x -> x != currentlyAssignedJob})
for runningJobProjectPath in map(copy(OmniSharp#proc#GetJob(runningJob).projects), "fnamemodify(v:val.path, ':p:h')")
if stridx(filePath, runningJobProjectPath) == 0
call add(slnsOrDirsCoveringCurrentFile, runningJob)
break
endif
endfor
endfor
return filter(slnsOrDirsCoveringCurrentFile, {_,sln_or_dir -> sln_or_dir =~? a:arglead})
endfunction

function! OmniSharp#IsAnyServerRunning() abort
return !empty(OmniSharp#proc#ListRunningJobs())
Expand Down Expand Up @@ -106,10 +120,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 @@ -245,13 +262,17 @@ function! OmniSharp#RestartAllServers() abort
endfor
endfunction

function! OmniSharp#PickRunningServer(server) abort
let host = get(b:, 'OmniSharp_host', {})
let host.sln_or_dir = a:server
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 = map(copy(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', 1)
for runningJob in OmniSharp#proc#ListRunningJobs()
let isCompletelyCoveredByNewestSolution = 1
let runningJobProjectsPaths = map(copy(OmniSharp#proc#GetJob(runningJob).projects), "fnamemodify(v:val.path, ':p:h')")
for i in range(len(runningJobProjectsPaths))
let isProjectCoveredByNewestSolution = 0
for j in range(len(projects))
if runningJobProjectsPaths[i] == 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
3 changes: 3 additions & 0 deletions ftplugin/cs/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ command! -buffer -bar OmniSharpRestartServer call OmniSharp#RestartServer()
command! -buffer -bar -nargs=? -complete=file OmniSharpStartServer call OmniSharp#StartServer(<q-args>)
command! -buffer -bar OmniSharpStopAllServers call OmniSharp#StopAllServers()
command! -buffer -bar -nargs=? -bang -complete=customlist,OmniSharp#CompleteRunningSln OmniSharpStopServer call OmniSharp#StopServer(<bang>0, <q-args>)
command! -buffer -bar -nargs=? -complete=customlist,OmniSharp#CompleteOtherRunningSlnOrDirCoveringCurrentFile OmniSharpPickRunningServer call OmniSharp#PickRunningServer(<q-args>)

command! -buffer -bar OmniSharpCodeFormat call OmniSharp#actions#format#Format()
command! -buffer -bar OmniSharpDocumentation call OmniSharp#actions#documentation#Documentation()
Expand Down Expand Up @@ -68,6 +69,7 @@ nnoremap <buffer> <Plug>(omnisharp_go_to_definition) :OmniSharpGotoDefinition<CR
nnoremap <buffer> <Plug>(omnisharp_highlight) :OmniSharpHighlight<CR>
nnoremap <buffer> <Plug>(omnisharp_navigate_up) :OmniSharpNavigateUp<CR>
nnoremap <buffer> <Plug>(omnisharp_navigate_down) :OmniSharpNavigateDown<CR>
nnoremap <buffer> <Plug>(omnisharp_pick_running_server) :OmniSharpPickRunningServer
nnoremap <buffer> <Plug>(omnisharp_preview_definition) :OmniSharpPreviewDefinition<CR>
nnoremap <buffer> <Plug>(omnisharp_preview_implementation) :OmniSharpPreviewImplementation<CR>
nnoremap <buffer> <Plug>(omnisharp_rename) :OmniSharpRename<CR>
Expand Down Expand Up @@ -114,6 +116,7 @@ let b:undo_ftplugin .= '
\| delcommand OmniSharpHighlightTypes
\| delcommand OmniSharpNavigateUp
\| delcommand OmniSharpNavigateDown
\| delcommand OmniSharpPickRunningServer
\| delcommand OmniSharpPreviewDefinition
\| delcommand OmniSharpPreviewImplementation
\| delcommand OmniSharpRename
Expand Down
2 changes: 2 additions & 0 deletions plugin/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ let g:OmniSharp_completion_without_overloads = get(g:, 'OmniSharp_completion_wit

let g:omnicomplete_fetch_full_documentation = get(g:, 'omnicomplete_fetch_full_documentation', 1)

let g:OmniSharp_stop_redundant_servers = get(g:, 'OmniSharp_stop_redundant_servers', 1)

command! -bar -nargs=? OmniSharpInstall call OmniSharp#Install(<f-args>)
command! -bar -nargs=? OmniSharpOpenLog call OmniSharp#log#Open(<q-args>)
command! -bar -bang OmniSharpStatus call OmniSharp#Status(<bang>0)
Expand Down