@@ -197,7 +197,8 @@ export function launchOmniSharp(cwd: string, args: string[]): Promise<LaunchResu
197197 setTimeout ( function ( ) {
198198 resolve ( result ) ;
199199 } , 0 ) ;
200- } ) ;
200+ } )
201+ . catch ( reason => reject ( reason ) ) ;
201202 } ) ;
202203}
203204
@@ -215,18 +216,36 @@ function launch(cwd: string, args: string[]): Promise<LaunchResult> {
215216 args . push ( `formattingOptions:indentationSize=${ getConfigurationValue ( globalConfig , csharpConfig , 'editor.tabSize' , 4 ) } ` ) ;
216217 }
217218
218- if ( options . path && options . useMono ) {
219- return launchNixMono ( options . path , cwd , args ) ;
219+ // If the user has provide a path to OmniSharp, we'll use that.
220+ if ( options . path ) {
221+ if ( platformInfo . isWindows ( ) ) {
222+ return launchWindows ( options . path , cwd , args ) ;
223+ }
224+
225+ // If we're launching on macOS/Linux, we have two possibilities:
226+ // 1. Launch using Mono
227+ // 2. Launch process directly (e.g. a 'run' script)
228+ return options . useMono
229+ ? launchNixMono ( options . path , cwd , args )
230+ : launchNix ( options . path , cwd , args ) ;
220231 }
221232
222- const launchPath = options . path || getLaunchPath ( platformInfo ) ;
233+ // If the user has not provided a path, we'll use the locally-installed OmniSharp
234+ const basePath = path . resolve ( util . getExtensionPath ( ) , '.omnisharp' ) ;
223235
224236 if ( platformInfo . isWindows ( ) ) {
225- return launchWindows ( launchPath , cwd , args ) ;
226- }
227- else {
228- return launchNix ( launchPath , cwd , args ) ;
237+ return launchWindows ( path . join ( basePath , 'OmniSharp.exe' ) , cwd , args ) ;
229238 }
239+
240+ // If it's possible to launch on a global Mono, we'll do that. Otherwise, run with our
241+ // locally installed Mono runtime.
242+ return canLaunchMono ( )
243+ . then ( ( ) => {
244+ return launchNixMono ( path . join ( basePath , 'omnisharp' , 'OmniSharp.exe' ) , cwd , args ) ;
245+ } )
246+ . catch ( _ => {
247+ return launchNix ( path . join ( basePath , 'run' ) , cwd , args ) ;
248+ } ) ;
230249 } ) ;
231250}
232251
@@ -240,14 +259,6 @@ function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csha
240259 return globalConfig . get ( configurationPath , defaultValue ) ;
241260}
242261
243- function getLaunchPath ( platformInfo : PlatformInformation ) : string {
244- const binPath = path . resolve ( util . getExtensionPath ( ) , '.omnisharp' ) ;
245-
246- return platformInfo . isWindows ( )
247- ? path . join ( binPath , 'OmniSharp.exe' )
248- : path . join ( binPath , 'run' ) ;
249- }
250-
251262function launchWindows ( launchPath : string , cwd : string , args : string [ ] ) : LaunchResult {
252263 function escapeIfNeeded ( arg : string ) {
253264 const hasSpaceWithoutQuotes = / ^ [ ^ " ] .* .* [ ^ " ] / ;
@@ -294,8 +305,8 @@ function launchNixMono(launchPath: string, cwd: string, args: string[]): Promise
294305 return canLaunchMono ( )
295306 . then ( ( ) => {
296307 let argsCopy = args . slice ( 0 ) ; // create copy of details args
297- argsCopy . unshift ( "--assembly-loader=strict" ) ;
298308 argsCopy . unshift ( launchPath ) ;
309+ argsCopy . unshift ( "--assembly-loader=strict" ) ;
299310
300311 let process = spawn ( 'mono' , argsCopy , {
301312 detached : false ,
0 commit comments