Skip to content

Commit 31eb7ab

Browse files
Launch OmniSharp on global Mono if its available
1 parent 64b4921 commit 31eb7ab

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/omnisharp/launcher.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,36 @@ function launch(cwd: string, args: string[]): Promise<LaunchResult> {
215215
args.push(`formattingOptions:indentationSize=${getConfigurationValue(globalConfig, csharpConfig, 'editor.tabSize', 4)}`);
216216
}
217217

218-
if (options.path && options.useMono) {
219-
return launchNixMono(options.path, cwd, args);
218+
// If the user has provide a path to OmniSharp, we'll use that.
219+
if (options.path) {
220+
if (platformInfo.isWindows()) {
221+
return launchWindows(options.path, cwd, args);
222+
}
223+
224+
// If we're launching on macOS/Linux, we have two possibilities:
225+
// 1. Launch using Mono
226+
// 2. Launch process directly (e.g. a 'run' script)
227+
return options.useMono
228+
? launchNixMono(options.path, cwd, args)
229+
: launchNix(options.path, cwd, args);
220230
}
221231

222-
const launchPath = options.path || getLaunchPath(platformInfo);
232+
// If the user has not provided a path, we'll use the locally-installed OmniSharp
233+
const basePath = path.resolve(util.getExtensionPath(), '.omnisharp');
223234

224235
if (platformInfo.isWindows()) {
225-
return launchWindows(launchPath, cwd, args);
226-
}
227-
else {
228-
return launchNix(launchPath, cwd, args);
236+
return launchWindows(path.join(basePath, 'OmniSharp.exe'), cwd, args);
229237
}
238+
239+
// If it's possible to launch on a global Mono, we'll do that. Otherwise, run with our
240+
// locally installed Mono runtime.
241+
return canLaunchMono()
242+
.then(() => {
243+
return launchNixMono(path.join(basePath, 'omnisharp', 'OmniSharp.exe'), cwd, args);
244+
})
245+
.catch(_ => {
246+
return launchNix(path.join(basePath, 'run'), cwd, args);
247+
});
230248
});
231249
}
232250

@@ -240,14 +258,6 @@ function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csha
240258
return globalConfig.get(configurationPath, defaultValue);
241259
}
242260

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-
251261
function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchResult {
252262
function escapeIfNeeded(arg: string) {
253263
const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/;

0 commit comments

Comments
 (0)