Skip to content

Commit f03195d

Browse files
committed
Merge remote-tracking branch 'origin/use_buffer' into use_buffer
2 parents c5fec60 + 93850a9 commit f03195d

File tree

10 files changed

+267
-60
lines changed

10 files changed

+267
-60
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/features/codeActionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
3232
}
3333

3434
private _resetCachedOptions(): void {
35-
this._options = Options.Read();
35+
this._options = Options.Read(vscode);
3636
}
3737

3838
public async provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<vscode.Command[]> {

src/features/codeLensProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
3939
}
4040

4141
private _resetCachedOptions(): void {
42-
this._options = Options.Read();
42+
this._options = Options.Read(vscode);
4343
}
4444

4545
private static filteredSymbolNames: { [name: string]: boolean } = {

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
6161
eventStream.subscribe(omnisharpLogObserver.post);
6262
eventStream.subscribe(omnisharpChannelObserver.post);
6363

64-
let warningMessageObserver = new WarningMessageObserver(vscode, () => Options.Read().disableMSBuildDiagnosticWarning || false);
64+
let warningMessageObserver = new WarningMessageObserver(vscode, () => Options.Read(vscode).disableMSBuildDiagnosticWarning || false);
6565
eventStream.subscribe(warningMessageObserver.post);
6666

6767
let informationMessageObserver = new InformationMessageObserver(vscode);

src/omnisharp/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function activate(context: vscode.ExtensionContext, eventStream: Ev
4343
scheme: 'file' // only files from disk
4444
};
4545

46-
const options = Options.Read();
46+
const options = Options.Read(vscode);
4747
const server = new OmniSharpServer(vscode, provider, eventStream, packageJSON, platformInfo);
4848
omnisharp = server;
4949
const advisor = new Advisor(server); // create before server is started

src/omnisharp/launcher.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function findLaunchTargets(): Thenable<LaunchTarget[]> {
4141
return Promise.resolve([]);
4242
}
4343

44-
const options = Options.Read();
44+
const options = Options.Read(vscode);
4545

4646
return vscode.workspace.findFiles(
4747
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
@@ -204,9 +204,9 @@ export interface LaunchResult {
204204
monoVersion?: string;
205205
}
206206

207-
export async function launchOmniSharp(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation): Promise<LaunchResult> {
207+
export async function launchOmniSharp(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation, options: Options): Promise<LaunchResult> {
208208
return new Promise<LaunchResult>((resolve, reject) => {
209-
launch(cwd, args, launchInfo, platformInfo)
209+
launch(cwd, args, launchInfo, platformInfo, options)
210210
.then(result => {
211211
// async error - when target not not ENEOT
212212
result.process.on('error', err => {
@@ -222,9 +222,7 @@ export async function launchOmniSharp(cwd: string, args: string[], launchInfo: L
222222
});
223223
}
224224

225-
async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation): Promise<LaunchResult> {
226-
const options = Options.Read();
227-
225+
async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation, options: Options): Promise<LaunchResult> {
228226
if (options.useEditorFormattingSettings) {
229227
let globalConfig = vscode.workspace.getConfiguration();
230228
let csharpConfig = vscode.workspace.getConfiguration('[csharp]');
@@ -242,16 +240,18 @@ async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platf
242240
let isValidMonoAvailable = await satisfies(monoVersion, '>=5.2.0');
243241

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

250-
return launchNixMono(launchInfo.LaunchPath, monoVersion, cwd, args);
248+
const launchPath = launchInfo.MonoLaunchPath || launchInfo.LaunchPath;
249+
250+
return launchNixMono(launchPath, monoVersion, cwd, args);
251251
}
252252

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

src/omnisharp/options.ts

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,43 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as vscode from 'vscode';
6+
import { vscode, WorkspaceConfiguration } from '../vscodeAdapter';
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) { }
23-
24-
public static Read(): Options {
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) { }
23+
24+
public static Read(vscode: vscode): 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

4440
// support the legacy "verbose" level as "debug"
45-
let loggingLevel = omnisharpConfig.get<string>('loggingLevel');
46-
if (loggingLevel.toLowerCase() === 'verbose') {
41+
let loggingLevel = omnisharpConfig.get<string>('loggingLevel', 'information');
42+
if (loggingLevel && loggingLevel.toLowerCase() === 'verbose') {
4743
loggingLevel = 'debug';
4844
}
4945

@@ -60,10 +56,11 @@ export class Options {
6056

6157
const disableCodeActions = csharpConfig.get<boolean>('disableCodeActions', false);
6258

63-
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning');
59+
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);
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: WorkspaceConfiguration, omnisharpConfig: 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>('omnisharp');
85+
}
86+
else {
87+
// Otherwise, null.
88+
return null;
89+
}
90+
}
91+
92+
private static readUseGlobalMonoOption(omnisharpConfig: WorkspaceConfiguration, csharpConfig: 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', "auto");
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
}

src/omnisharp/server.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export class OmniSharpServer {
8585
private _launchTarget: LaunchTarget;
8686
private _requestQueue: RequestQueueCollection;
8787
private _serverProcess: ChildProcess;
88-
private _options: Options;
8988

9089
private _omnisharpManager: OmnisharpManager;
9190
private updateProjectDebouncer = new Subject<ObservableEvents.ProjectModified>();
@@ -237,7 +236,7 @@ export class OmniSharpServer {
237236

238237
// --- start, stop, and connect
239238

240-
private async _start(launchTarget: LaunchTarget): Promise<void> {
239+
private async _start(launchTarget: LaunchTarget, options: Options): Promise<void> {
241240

242241
let disposables = new CompositeDisposable();
243242

@@ -292,25 +291,24 @@ export class OmniSharpServer {
292291

293292
const solutionPath = launchTarget.target;
294293
const cwd = path.dirname(solutionPath);
295-
this._options = Options.Read();
296294

297295
let args = [
298296
'-s', solutionPath,
299297
'--hostPID', process.pid.toString(),
300298
'--stdio',
301299
'DotNet:enablePackageRestore=false',
302300
'--encoding', 'utf-8',
303-
'--loglevel', this._options.loggingLevel
301+
'--loglevel', options.loggingLevel
304302
];
305303

306-
if (this._options.waitForDebugger === true) {
304+
if (options.waitForDebugger === true) {
307305
args.push('--debug');
308306
}
309307

310308
let launchInfo: LaunchInfo;
311309
try {
312310
let extensionPath = utils.getExtensionPath();
313-
launchInfo = await this._omnisharpManager.GetOmniSharpLaunchInfo(this.packageJSON.defaults.omniSharp, this._options.path, serverUrl, latestVersionFileServerPath, installPath, extensionPath);
311+
launchInfo = await this._omnisharpManager.GetOmniSharpLaunchInfo(this.packageJSON.defaults.omniSharp, options.path, serverUrl, latestVersionFileServerPath, installPath, extensionPath);
314312
}
315313
catch (error) {
316314
this.eventStream.post(new ObservableEvents.OmnisharpFailure(`Error occured in loading omnisharp from omnisharp.path\nCould not start the server due to ${error.toString()}`, error));
@@ -321,15 +319,15 @@ export class OmniSharpServer {
321319
this._fireEvent(Events.BeforeServerStart, solutionPath);
322320

323321
try {
324-
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo);
322+
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo, options);
325323
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.command, launchResult.process.pid));
326324

327325
this._serverProcess = launchResult.process;
328326
this._delayTrackers = {};
329327
this._setState(ServerState.Started);
330328
this._fireEvent(Events.ServerStart, solutionPath);
331329

332-
await this._doConnect();
330+
await this._doConnect(options);
333331

334332
this._telemetryIntervalId = setInterval(() => this._reportTelemetry(), TelemetryReportingDelay);
335333
this._requestQueue.drain();
@@ -417,7 +415,10 @@ export class OmniSharpServer {
417415
public async restart(launchTarget: LaunchTarget = this._launchTarget): Promise<void> {
418416
if (launchTarget) {
419417
await this.stop();
420-
await this._start(launchTarget);
418+
419+
const options = Options.Read(this.vscode);
420+
421+
await this._start(launchTarget, options);
421422
}
422423
}
423424

@@ -503,7 +504,7 @@ export class OmniSharpServer {
503504
});
504505
}
505506

506-
private async _doConnect(): Promise<void> {
507+
private async _doConnect(options: Options): Promise<void> {
507508

508509
this._serverProcess.stderr.on('data', (data: any) => {
509510
this._fireEvent('stderr', String(data));
@@ -519,7 +520,7 @@ export class OmniSharpServer {
519520
let listener: Disposable;
520521

521522
// Convert the timeout from the seconds to milliseconds, which is required by setTimeout().
522-
const timeoutDuration = this._options.projectLoadTimeout * 1000;
523+
const timeoutDuration = options.projectLoadTimeout * 1000;
523524

524525
// timeout logic
525526
const handle = setTimeout(() => {

0 commit comments

Comments
 (0)