Skip to content

Commit cefa8dd

Browse files
Add/update 'omnisharp.useGlobalMono' option
This change updates the name of the 'omnisharp.useMono' option to 'omnisharp.useGlobalMono', and makes it a tri-state value rather than a boolean. It now has three possible values: * "auto": Launch OmniSharp on the globally-installed Mono if it's available. * "always": Always try to launch OmniSharp on the globally-installed Mono and error if it's not available. * "never": Never launch OmniSharp on the globall-installed Mono.
1 parent 83b52ff commit cefa8dd

File tree

3 files changed

+77
-29
lines changed

3 files changed

+77
-29
lines changed

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,20 @@
521521
"default": null,
522522
"description": "Specifies the path to OmniSharp. This can be the absolute path to an OmniSharp executable, a specific version number, or \"latest\". If a version number or \"latest\" is specified, the appropriate version of OmniSharp will be downloaded on your behalf."
523523
},
524-
"omnisharp.useMono": {
525-
"type": "boolean",
526-
"default": false,
527-
"description": "Launch OmniSharp with Mono."
524+
"omnisharp.useGlobalMono": {
525+
"type": "string",
526+
"default": "auto",
527+
"enum": [
528+
"auto",
529+
"always",
530+
"never"
531+
],
532+
"enumDescriptions": [
533+
"Automatically launch OmniSharp with \"mono\" if version 5.2.0 or greater is available on the PATH.",
534+
"Always launch OmniSharp with \"mono\". If version 5.2.0 or greater is not available on the PATH, an error will be printed.",
535+
"Never launch OmniSHarp on a globally-installed Mono."
536+
],
537+
"description": "Launch OmniSharp with the globally-installed Mono. If set to \"always\", \"mono\" version 5.2.0 or greater must be available on the PATH. If set to \"auto\", OmniSharp will be launched with \"mono\" if version 5.2.0 or greater is available on the PATH."
528538
},
529539
"omnisharp.waitForDebugger": {
530540
"type": "boolean",

src/omnisharp/launcher.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,18 @@ async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platf
242242
let isValidMonoAvailable = await satisfies(monoVersion, '>=5.2.0');
243243

244244
// If the user specifically said that they wanted to launch on Mono, respect their wishes.
245-
if (options.useMono) {
245+
if (options.useGlobalMono === "always") {
246246
if (!isValidMonoAvailable) {
247247
throw new Error('Cannot start OmniSharp because Mono version >=5.2.0 is required.');
248248
}
249249

250-
return launchNixMono(launchInfo.LaunchPath, monoVersion, cwd, args);
250+
const launchPath = launchInfo.MonoLaunchPath || launchInfo.LaunchPath;
251+
252+
return launchNixMono(launchPath, monoVersion, cwd, args);
251253
}
252254

253255
// If we can launch on the global Mono, do so; otherwise, launch directly;
254-
if (isValidMonoAvailable && launchInfo.MonoLaunchPath) {
256+
if (options.useGlobalMono === "auto" && isValidMonoAvailable && launchInfo.MonoLaunchPath) {
255257
return launchNixMono(launchInfo.MonoLaunchPath, monoVersion, cwd, args);
256258
}
257259
else {

src/omnisharp/options.ts

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,33 @@ import * as vscode from 'vscode';
77

88
export class Options {
99
constructor(
10-
public path?: string,
11-
public useMono?: boolean,
12-
public waitForDebugger?: boolean,
13-
public loggingLevel?: string,
14-
public autoStart?: boolean,
15-
public projectLoadTimeout?: number,
16-
public maxProjectResults?: number,
17-
public useEditorFormattingSettings?: boolean,
18-
public useFormatting?: boolean,
19-
public showReferencesCodeLens?: boolean,
20-
public showTestsCodeLens?: boolean,
21-
public disableCodeActions?: boolean,
22-
public disableMSBuildDiagnosticWarning?: boolean) { }
10+
public path: string,
11+
public useGlobalMono: string,
12+
public waitForDebugger: boolean,
13+
public loggingLevel: string,
14+
public autoStart: boolean,
15+
public projectLoadTimeout: number,
16+
public maxProjectResults: number,
17+
public useEditorFormattingSettings: boolean,
18+
public useFormatting: boolean,
19+
public showReferencesCodeLens: boolean,
20+
public showTestsCodeLens: boolean,
21+
public disableCodeActions: boolean,
22+
public disableMSBuildDiagnosticWarning: boolean) { }
2323

2424
public static Read(): Options {
2525
// Extra effort is taken below to ensure that legacy versions of options
2626
// are supported below. In particular, these are:
2727
//
2828
// - "csharp.omnisharp" -> "omnisharp.path"
2929
// - "csharp.omnisharpUsesMono" -> "omnisharp.useMono"
30+
// - "omnisharp.useMono" -> "omnisharp.useGlobalMono"
3031

3132
const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
3233
const csharpConfig = vscode.workspace.getConfiguration('csharp');
3334

34-
const path = csharpConfig.has('omnisharp')
35-
? csharpConfig.get<string>('omnisharp')
36-
: omnisharpConfig.get<string>('path');
37-
38-
const useMono = csharpConfig.has('omnisharpUsesMono')
39-
? csharpConfig.get<boolean>('omnisharpUsesMono')
40-
: omnisharpConfig.get<boolean>('useMono');
35+
const path = Options.readPathOption(csharpConfig, omnisharpConfig);
36+
const useGlobalMono = Options.readUseGlobalMonoOption(omnisharpConfig, csharpConfig);
4137

4238
const waitForDebugger = omnisharpConfig.get<boolean>('waitForDebugger', false);
4339

@@ -62,8 +58,9 @@ export class Options {
6258

6359
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning');
6460

65-
return new Options(path,
66-
useMono,
61+
return new Options(
62+
path,
63+
useGlobalMono,
6764
waitForDebugger,
6865
loggingLevel,
6966
autoStart,
@@ -76,4 +73,43 @@ export class Options {
7673
disableCodeActions,
7774
disableMSBuildDiagnosticWarning);
7875
}
76+
77+
private static readPathOption(csharpConfig: vscode.WorkspaceConfiguration, omnisharpConfig: vscode.WorkspaceConfiguration): string | null {
78+
if (omnisharpConfig.has('path')) {
79+
// If 'omnisharp.path' setting was found, use it.
80+
return omnisharpConfig.get<string>('path');
81+
}
82+
else if (csharpConfig.has('omnisharp')) {
83+
// BACKCOMPAT: If 'csharp.omnisharp' setting was found, use it.
84+
return csharpConfig.get<string>('path');
85+
}
86+
else {
87+
// Otherwise, null.
88+
return null;
89+
}
90+
}
91+
92+
private static readUseGlobalMonoOption(omnisharpConfig: vscode.WorkspaceConfiguration, csharpConfig: vscode.WorkspaceConfiguration): string {
93+
function toUseGlobalMonoValue(value: boolean): string {
94+
// True means 'always' and false means 'auto'.
95+
return value ? "always" : "auto";
96+
}
97+
98+
if (omnisharpConfig.has('useGlobalMono')) {
99+
// If 'omnisharp.useGlobalMono' setting was found, just use it.
100+
return omnisharpConfig.get<string>('useGlobalMono');
101+
}
102+
else if (omnisharpConfig.has('useMono')) {
103+
// BACKCOMPAT: If 'omnisharp.useMono' setting was found, true maps to "always" and false maps to "auto"
104+
return toUseGlobalMonoValue(omnisharpConfig.get<boolean>('useMono'));
105+
}
106+
else if (csharpConfig.has('omnisharpUsesMono')) {
107+
// BACKCOMPAT: If 'csharp.omnisharpUsesMono' setting was found, true maps to "always" and false maps to "auto"
108+
return toUseGlobalMonoValue(csharpConfig.get<boolean>('omnisharpUsesMono'));
109+
}
110+
else {
111+
// Otherwise, the default value is "auto".
112+
return "auto";
113+
}
114+
}
79115
}

0 commit comments

Comments
 (0)