Skip to content

Commit 78d45f5

Browse files
committed
Use server projects to find sln_or_dir for buffer
1 parent 032e10a commit 78d45f5

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

autoload/OmniSharp.vim

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ function! OmniSharp#FindSolutionOrDir(...) abort
238238
let interactive = a:0 ? a:1 : 1
239239
let bufnr = a:0 > 1 ? a:2 : bufnr('%')
240240
if empty(getbufvar(bufnr, 'OmniSharp_buf_server'))
241-
let dir = s:FindServerRunningOnParentDirectory(bufnr)
242-
if !empty(dir)
243-
call setbufvar(bufnr, 'OmniSharp_buf_server', dir)
241+
let sln_or_dir = s:FindRunningServerForBuffer(bufnr)
242+
if !empty(sln_or_dir)
243+
call setbufvar(bufnr, 'OmniSharp_buf_server', sln_or_dir)
244244
else
245245
try
246246
let sln = s:FindSolution(interactive, bufnr)
@@ -429,26 +429,31 @@ function! s:FindSolution(interactive, bufnr) abort
429429
endif
430430
endfunction
431431

432-
function! s:FindServerRunningOnParentDirectory(bufnr) abort
432+
" Check whether filename is in the same directory or subdirectory of a running
433+
" server solution, or one of the solution's included projects
434+
function! s:FindRunningServerForBuffer(bufnr) abort
433435
let filename = expand('#' . a:bufnr . ':p')
436+
let selected_sln_or_dir = ''
434437
let longest_dir_match = ''
435438
let longest_dir_length = 0
436439
let running_jobs = OmniSharp#proc#ListRunningJobs()
437440
for sln_or_dir in running_jobs
438-
if isdirectory(sln_or_dir) && s:DirectoryContainsFile(sln_or_dir, filename)
439-
let dir_length = len(sln_or_dir)
440-
if dir_length > longest_dir_length
441-
let longest_dir_match = sln_or_dir
442-
let longest_dir_length = dir_length
441+
let paths = [sln_or_dir]
442+
for project in get(OmniSharp#proc#GetJob(sln_or_dir), 'projects', [])
443+
call add(paths, project.path)
444+
endfor
445+
for path in paths
446+
let directory = isdirectory(path) ? path : fnamemodify(path, ':h')
447+
if stridx(filename, directory) == 0
448+
if len(path) > longest_dir_length
449+
let longest_dir_match = path
450+
let selected_sln_or_dir = sln_or_dir
451+
let longest_dir_length = len(path)
452+
endif
443453
endif
444-
endif
454+
endfor
445455
endfor
446-
return longest_dir_match
447-
endfunction
448-
449-
function! s:DirectoryContainsFile(directory, file) abort
450-
let idx = stridx(a:file, a:directory)
451-
return (idx == 0)
456+
return selected_sln_or_dir
452457
endfunction
453458

454459

0 commit comments

Comments
 (0)