@@ -238,9 +238,9 @@ function! OmniSharp#FindSolutionOrDir(...) abort
238
238
let interactive = a: 0 ? a: 1 : 1
239
239
let bufnr = a: 0 > 1 ? a: 2 : bufnr (' %' )
240
240
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 )
244
244
else
245
245
try
246
246
let sln = s: FindSolution (interactive, bufnr )
@@ -429,26 +429,31 @@ function! s:FindSolution(interactive, bufnr) abort
429
429
endif
430
430
endfunction
431
431
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
433
435
let filename = expand (' #' . a: bufnr . ' :p' )
436
+ let selected_sln_or_dir = ' '
434
437
let longest_dir_match = ' '
435
438
let longest_dir_length = 0
436
439
let running_jobs = OmniSharp#proc#ListRunningJobs ()
437
440
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
443
453
endif
444
- endif
454
+ endfor
445
455
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
452
457
endfunction
453
458
454
459
0 commit comments