Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/update 'omnisharp.useGlobalMono' option #2244

Merged
merged 4 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,20 @@
"default": null,
"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."
},
"omnisharp.useMono": {
"type": "boolean",
"default": false,
"description": "Launch OmniSharp with Mono."
"omnisharp.useGlobalMono": {
"type": "string",
"default": "auto",
"enum": [
"auto",
"always",
"never"
],
"enumDescriptions": [
"Automatically launch OmniSharp with \"mono\" if version 5.2.0 or greater is available on the PATH.",
"Always launch OmniSharp with \"mono\". If version 5.2.0 or greater is not available on the PATH, an error will be printed.",
"Never launch OmniSHarp on a globally-installed Mono."
],
"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."
},
"omnisharp.waitForDebugger": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion src/features/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
}

private _resetCachedOptions(): void {
this._options = Options.Read();
this._options = Options.Read(vscode);
}

public async provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<vscode.Command[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/features/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
}

private _resetCachedOptions(): void {
this._options = Options.Read();
this._options = Options.Read(vscode);
}

private static filteredSymbolNames: { [name: string]: boolean } = {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
eventStream.subscribe(omnisharpLogObserver.post);
eventStream.subscribe(omnisharpChannelObserver.post);

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

let informationMessageObserver = new InformationMessageObserver(vscode);
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function activate(context: vscode.ExtensionContext, eventStream: Ev
scheme: 'file' // only files from disk
};

const options = Options.Read();
const options = Options.Read(vscode);
const server = new OmniSharpServer(vscode, provider, eventStream, packageJSON, platformInfo);
omnisharp = server;
const advisor = new Advisor(server); // create before server is started
Expand Down
18 changes: 9 additions & 9 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function findLaunchTargets(): Thenable<LaunchTarget[]> {
return Promise.resolve([]);
}

const options = Options.Read();
const options = Options.Read(vscode);

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

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

async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation): Promise<LaunchResult> {
const options = Options.Read();

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

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

return launchNixMono(launchInfo.LaunchPath, monoVersion, cwd, args);
const launchPath = launchInfo.MonoLaunchPath || launchInfo.LaunchPath;

return launchNixMono(launchPath, monoVersion, cwd, args);
}

// If we can launch on the global Mono, do so; otherwise, launch directly;
if (isValidMonoAvailable && launchInfo.MonoLaunchPath) {
if (options.useGlobalMono === "auto" && isValidMonoAvailable && launchInfo.MonoLaunchPath) {
return launchNixMono(launchInfo.MonoLaunchPath, monoVersion, cwd, args);
}
else {
Expand Down
92 changes: 64 additions & 28 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,43 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { vscode, WorkspaceConfiguration } from '../vscodeAdapter';

export class Options {
constructor(
public path?: string,
public useMono?: boolean,
public waitForDebugger?: boolean,
public loggingLevel?: string,
public autoStart?: boolean,
public projectLoadTimeout?: number,
public maxProjectResults?: number,
public useEditorFormattingSettings?: boolean,
public useFormatting?: boolean,
public showReferencesCodeLens?: boolean,
public showTestsCodeLens?: boolean,
public disableCodeActions?: boolean,
public disableMSBuildDiagnosticWarning?: boolean) { }

public static Read(): Options {
public path: string,
public useGlobalMono: string,
public waitForDebugger: boolean,
public loggingLevel: string,
public autoStart: boolean,
public projectLoadTimeout: number,
public maxProjectResults: number,
public useEditorFormattingSettings: boolean,
public useFormatting: boolean,
public showReferencesCodeLens: boolean,
public showTestsCodeLens: boolean,
public disableCodeActions: boolean,
public disableMSBuildDiagnosticWarning: boolean) { }

public static Read(vscode: vscode): Options {
// Extra effort is taken below to ensure that legacy versions of options
// are supported below. In particular, these are:
//
// - "csharp.omnisharp" -> "omnisharp.path"
// - "csharp.omnisharpUsesMono" -> "omnisharp.useMono"
// - "omnisharp.useMono" -> "omnisharp.useGlobalMono"

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

const path = csharpConfig.has('omnisharp')
? csharpConfig.get<string>('omnisharp')
: omnisharpConfig.get<string>('path');

const useMono = csharpConfig.has('omnisharpUsesMono')
? csharpConfig.get<boolean>('omnisharpUsesMono')
: omnisharpConfig.get<boolean>('useMono');
const path = Options.readPathOption(csharpConfig, omnisharpConfig);
const useGlobalMono = Options.readUseGlobalMonoOption(omnisharpConfig, csharpConfig);

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

// support the legacy "verbose" level as "debug"
let loggingLevel = omnisharpConfig.get<string>('loggingLevel');
if (loggingLevel.toLowerCase() === 'verbose') {
let loggingLevel = omnisharpConfig.get<string>('loggingLevel', 'information');
if (loggingLevel && loggingLevel.toLowerCase() === 'verbose') {
loggingLevel = 'debug';
}

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

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

const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning');
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);

return new Options(path,
useMono,
return new Options(
path,
useGlobalMono,
waitForDebugger,
loggingLevel,
autoStart,
Expand All @@ -76,4 +73,43 @@ export class Options {
disableCodeActions,
disableMSBuildDiagnosticWarning);
}

private static readPathOption(csharpConfig: WorkspaceConfiguration, omnisharpConfig: WorkspaceConfiguration): string | null {
if (omnisharpConfig.has('path')) {
// If 'omnisharp.path' setting was found, use it.
return omnisharpConfig.get<string>('path');
}
else if (csharpConfig.has('omnisharp')) {
// BACKCOMPAT: If 'csharp.omnisharp' setting was found, use it.
return csharpConfig.get<string>('omnisharp');
}
else {
// Otherwise, null.
return null;
}
}

private static readUseGlobalMonoOption(omnisharpConfig: WorkspaceConfiguration, csharpConfig: WorkspaceConfiguration): string {
function toUseGlobalMonoValue(value: boolean): string {
// True means 'always' and false means 'auto'.
return value ? "always" : "auto";
}

if (omnisharpConfig.has('useGlobalMono')) {
// If 'omnisharp.useGlobalMono' setting was found, just use it.
return omnisharpConfig.get<string>('useGlobalMono', "auto");
}
else if (omnisharpConfig.has('useMono')) {
// BACKCOMPAT: If 'omnisharp.useMono' setting was found, true maps to "always" and false maps to "auto"
return toUseGlobalMonoValue(omnisharpConfig.get<boolean>('useMono'));
}
else if (csharpConfig.has('omnisharpUsesMono')) {
// BACKCOMPAT: If 'csharp.omnisharpUsesMono' setting was found, true maps to "always" and false maps to "auto"
return toUseGlobalMonoValue(csharpConfig.get<boolean>('omnisharpUsesMono'));
}
else {
// Otherwise, the default value is "auto".
return "auto";
}
}
}
23 changes: 12 additions & 11 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class OmniSharpServer {
private _launchTarget: LaunchTarget;
private _requestQueue: RequestQueueCollection;
private _serverProcess: ChildProcess;
private _options: Options;

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

// --- start, stop, and connect

private async _start(launchTarget: LaunchTarget): Promise<void> {
private async _start(launchTarget: LaunchTarget, options: Options): Promise<void> {

let disposables = new CompositeDisposable();

Expand Down Expand Up @@ -292,25 +291,24 @@ export class OmniSharpServer {

const solutionPath = launchTarget.target;
const cwd = path.dirname(solutionPath);
this._options = Options.Read();

let args = [
'-s', solutionPath,
'--hostPID', process.pid.toString(),
'--stdio',
'DotNet:enablePackageRestore=false',
'--encoding', 'utf-8',
'--loglevel', this._options.loggingLevel
'--loglevel', options.loggingLevel
];

if (this._options.waitForDebugger === true) {
if (options.waitForDebugger === true) {
args.push('--debug');
}

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

try {
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo);
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo, options);
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.command, launchResult.process.pid));

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

await this._doConnect();
await this._doConnect(options);

this._telemetryIntervalId = setInterval(() => this._reportTelemetry(), TelemetryReportingDelay);
this._requestQueue.drain();
Expand Down Expand Up @@ -417,7 +415,10 @@ export class OmniSharpServer {
public async restart(launchTarget: LaunchTarget = this._launchTarget): Promise<void> {
if (launchTarget) {
await this.stop();
await this._start(launchTarget);

const options = Options.Read(this.vscode);

await this._start(launchTarget, options);
}
}

Expand Down Expand Up @@ -503,7 +504,7 @@ export class OmniSharpServer {
});
}

private async _doConnect(): Promise<void> {
private async _doConnect(options: Options): Promise<void> {

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

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

// timeout logic
const handle = setTimeout(() => {
Expand Down
Loading