Skip to content

Commit 2b9b110

Browse files
Merge pull request #710 from DustinCampbell/omnisharp-options
Improve OmniSharp options
2 parents 76f7c20 + 1e2dc9f commit 2b9b110

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@
7777
"type": "boolean",
7878
"default": false,
7979
"description": "Suppress the warning that the .NET CLI is not on the path."
80+
},
81+
"omnisharp.path": {
82+
"type": [
83+
"string",
84+
"null"
85+
],
86+
"default": null,
87+
"description": "Specifies the full path to the OmniSharp server."
88+
},
89+
"omnisharp.useMono": {
90+
"type": "boolean",
91+
"default": false,
92+
"description": "Launch OmniSharp with Mono."
93+
},
94+
"omnisharp.loggingLevel": {
95+
"type": "string",
96+
"default": "default",
97+
"enum": [
98+
"default",
99+
"verbose"
100+
],
101+
"description": "Specifies the level of logging output from the OmniSharp server."
80102
}
81103
}
82104
},

src/omnisharp/omnisharp.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import * as fs from 'fs-extra-promise';
1414
import * as path from 'path';
1515

1616
export interface Options {
17-
path?: string;
18-
usesMono?: boolean;
17+
path?: string;
18+
useMono?: boolean;
19+
loggingLevel?: string;
1920
}
2021

2122
export enum Flavor {

src/omnisharp/server.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,26 @@ export abstract class OmnisharpServer {
104104
}
105105

106106
private _readOptions(): omnisharp.Options {
107-
const config = vscode.workspace.getConfiguration('csharp');
107+
// Extra effort is taken below to ensure that legacy versions of options
108+
// are supported below. In particular, these are:
109+
//
110+
// - "csharp.omnisharp" -> "omnisharp.path"
111+
// - "csharp.omnisharpUsesMono" -> "omnisharp.useMono"
108112

109-
return {
110-
path: config.get<string>('omnisharp'),
111-
usesMono: config.get<boolean>('omnisharpUsesMono')
112-
};
113+
const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
114+
const csharpConfig = vscode.workspace.getConfiguration('csharp');
115+
116+
const path = omnisharpConfig.has('path')
117+
? omnisharpConfig.get<string>('path')
118+
: csharpConfig.get<string>('omnisharp');
119+
120+
const useMono = omnisharpConfig.has('useMono')
121+
? omnisharpConfig.get<boolean>('useMono')
122+
: csharpConfig.get<boolean>('omnisharpUsesMono');
123+
124+
const loggingLevel = omnisharpConfig.get<string>('loggingLevel');
125+
126+
return { path, useMono, loggingLevel };
113127
}
114128

115129
private _recordRequestDelay(requestName: string, elapsedTime: number) {
@@ -237,7 +251,7 @@ export abstract class OmnisharpServer {
237251
const options = this._readOptions();
238252

239253
let flavor: omnisharp.Flavor;
240-
if (options.path !== undefined && options.usesMono === true) {
254+
if (options.path !== undefined && options.useMono === true) {
241255
flavor = omnisharp.Flavor.Mono;
242256
}
243257
else {
@@ -250,11 +264,17 @@ export abstract class OmnisharpServer {
250264

251265
const solutionPath = launchTarget.target;
252266
const cwd = dirname(solutionPath);
253-
const args = [
267+
let args = [
254268
'-s', solutionPath,
255269
'--hostPID', process.pid.toString(),
256270
'DotNet:enablePackageRestore=false'
257-
].concat(this._extraArgs);
271+
];
272+
273+
if (options.loggingLevel === 'verbose') {
274+
args.push('-v');
275+
}
276+
277+
args = args.concat(this._extraArgs);
258278

259279
this._fireEvent(Events.StdOut, `[INFO] Starting OmniSharp at '${solutionPath}'...\n`);
260280
this._fireEvent(Events.BeforeServerStart, solutionPath);
@@ -391,7 +411,7 @@ export abstract class OmnisharpServer {
391411
return omnisharp.findServerPath(options.path).then(serverPath => {
392412
return resolve(serverPath);
393413
}).catch(err => {
394-
vscode.window.showWarningMessage(`Invalid "csharp.omnisharp" user setting specified ('${options.path}).`);
414+
vscode.window.showWarningMessage(`Invalid value specified for "omnisharp.path" ('${options.path}).`);
395415
return reject(err);
396416
});
397417
}
@@ -409,9 +429,9 @@ export abstract class OmnisharpServer {
409429
this._channel.appendLine(" 1. If it's not already installed, download and install Mono (https://www.mono-project.com)");
410430
this._channel.appendLine(" 2. Download and untar the latest OmniSharp Mono release from https://github.com/OmniSharp/omnisharp-roslyn/releases/");
411431
this._channel.appendLine(" 3. In Visual Studio Code, select Preferences->User Settings to open settings.json.");
412-
this._channel.appendLine(" 4. In settings.json, add a new setting: \"csharp.omnisharp\": \"/path/to/omnisharp/OmniSharp.exe\"");
413-
this._channel.appendLine(" 4. In settings.json, add a new setting: \"csharp.omnisharpUsesMono\": true");
414-
this._channel.appendLine(" 5. Restart Visual Studio Code.");
432+
this._channel.appendLine(" 4. In settings.json, add a new setting: \"omnisharp.path\": \"/path/to/omnisharp/OmniSharp.exe\"");
433+
this._channel.appendLine(" 5. In settings.json, add a new setting: \"omnisharp.useMono\": true");
434+
this._channel.appendLine(" 6. Restart Visual Studio Code.");
415435
this._channel.show();
416436

417437
throw err;

0 commit comments

Comments
 (0)