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

Enable usage of omnisharp.path option for downloading multiple versions of omnisharp #2028

Merged
merged 22 commits into from
Feb 14, 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
62 changes: 44 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"postinstall": "node ./node_modules/vscode/bin/install"
},
"dependencies": {
"chai-as-promised": "^7.1.1",
"fs-extra": "^5.0.0",
"http-proxy-agent": "^2.0.0",
"https-proxy-agent": "^2.1.1",
Expand Down Expand Up @@ -93,7 +94,8 @@
"architectures": [
"x86"
],
"installTestPath": "./.omnisharp/OmniSharp.exe"
"installTestPath": "./.omnisharp/OmniSharp.exe",
"experimentalPackageId": "win-x86"
},
{
"description": "OmniSharp for Windows (.NET 4.6 / x64)",
Expand All @@ -106,7 +108,8 @@
"architectures": [
"x86_64"
],
"installTestPath": "./.omnisharp/OmniSharp.exe"
"installTestPath": "./.omnisharp/OmniSharp.exe",
"experimentalPackageId": "win-x64"
},
{
"description": "OmniSharp for OSX",
Expand All @@ -120,7 +123,8 @@
"./mono.osx",
"./run"
],
"installTestPath": "./.omnisharp/mono.osx"
"installTestPath": "./.omnisharp/mono.osx",
"experimentalPackageId": "osx"
},
{
"description": "OmniSharp for Linux (x86)",
Expand All @@ -138,7 +142,8 @@
"./mono.linux-x86",
"./run"
],
"installTestPath": "./.omnisharp/mono.linux-x86"
"installTestPath": "./.omnisharp/mono.linux-x86",
"experimentalPackageId": "linux-x86"
},
{
"description": "OmniSharp for Linux (x64)",
Expand All @@ -155,7 +160,8 @@
"./mono.linux-x86_64",
"./run"
],
"installTestPath": "./.omnisharp/mono.linux-x86_64"
"installTestPath": "./.omnisharp/mono.linux-x86_64",
"experimentalPackageId": "linux-x64"
},
{
"description": ".NET Core Debugger (Windows / x64)",
Expand Down Expand Up @@ -361,7 +367,7 @@
"null"
],
"default": null,
"description": "Specifies the full path to the OmniSharp server."
"description": "Specifies how to acquire the OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder."
},
"omnisharp.useMono": {
"type": "boolean",
Expand Down Expand Up @@ -2125,4 +2131,4 @@
}
]
}
}
}
83 changes: 83 additions & 0 deletions src/OmnisharpDownload.Helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { PackageManager, Status, PackageError, Package } from './packages';
import { PlatformInformation } from './platform';
import { Logger } from './logger';
import TelemetryReporter from 'vscode-extension-telemetry';

export async function GetDependenciesAndDownloadPackages(packages: Package[], status: Status, platformInfo: PlatformInformation, packageManager: PackageManager, logger: Logger) {
const config = vscode.workspace.getConfiguration();
const proxy = config.get<string>('http.proxy');
const strictSSL = config.get('http.proxyStrictSSL', true);
await packageManager.DownloadPackages(logger, status, proxy, strictSSL);
}

export function SetStatus() {
let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
let status: Status = {
setMessage: text => {
statusItem.text = text;
statusItem.show();
},
setDetail: text => {
statusItem.tooltip = text;
statusItem.show();
}
};

return { StatusItem: statusItem, Status: status };
}

export async function GetAndLogPlatformInformation(logger: Logger): Promise<PlatformInformation> {
let platformInfo = await PlatformInformation.GetCurrent();

logger.appendLine(`Platform: ${platformInfo.toString()}`);
logger.appendLine();

return platformInfo;
}

export function ReportInstallationError(logger: Logger, error, telemetryProps: any, installationStage: string) {
let errorMessage: string;
if (error instanceof PackageError) {
// we can log the message in a PackageError to telemetry as we do not put PII in PackageError messages
telemetryProps['error.message'] = error.message;
if (error.innerError) {
errorMessage = error.innerError.toString();
}
else {
errorMessage = error.message;
}
if (error.pkg) {
telemetryProps['error.packageUrl'] = error.pkg.url;
}
}
else {
// do not log raw errorMessage in telemetry as it is likely to contain PII.
errorMessage = error.toString();
}

logger.appendLine(`Failed at stage: ${installationStage}`);
logger.appendLine(errorMessage);
}

export function SendInstallationTelemetry(logger: Logger, reporter: TelemetryReporter, telemetryProps: any, installationStage: string, platformInfo: PlatformInformation, statusItem: vscode.StatusBarItem) {
telemetryProps['installStage'] = installationStage;
telemetryProps['platform.architecture'] = platformInfo.architecture;
telemetryProps['platform.platform'] = platformInfo.platform;
if (platformInfo.distribution) {
telemetryProps['platform.distribution'] = platformInfo.distribution.toTelemetryString();
}
if (reporter) {
reporter.sendTelemetryEvent('Acquisition', telemetryProps);
}

logger.appendLine();
installationStage = '';
logger.appendLine('Finished');

statusItem.dispose();
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<{ init
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, logger, reporter);

// activate language services
let omniSharpPromise = OmniSharp.activate(context, reporter, _channel);
let omniSharpPromise = OmniSharp.activate(context, reporter, _channel, logger, extension.packageJSON);

// register JSON completion & hover providers for project.json
context.subscriptions.push(addJSONProviders());
Expand Down
72 changes: 72 additions & 0 deletions src/omnisharp/OmnisharpDownloader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { PackageManager, Package } from '../packages';
import { PlatformInformation } from '../platform';
import { Logger } from '../logger';
import TelemetryReporter from 'vscode-extension-telemetry';
import { GetPackagesFromVersion } from './OmnisharpPackageCreator';
import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../OmnisharpDownload.Helper';

export class OmnisharpDownloader {
public constructor(
private channel: vscode.OutputChannel,
private logger: Logger,
private packageJSON: any,
private reporter?: TelemetryReporter) {
}

public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string) {
if (!version) {
throw new Error('Invalid version');
}

this.logger.append('Installing Omnisharp Packages...');
this.logger.appendLine();
this.channel.show();

let statusObject = SetStatus();
let status = statusObject.Status;
let statusItem = statusObject.StatusItem;

let telemetryProps: any = {};
let installationStage = '';
let platformInfo: PlatformInformation;

if (this.reporter) {
this.reporter.sendTelemetryEvent("AcquisitionStart");
}

try {
installationStage = 'getPlatformInfo';
platformInfo = await GetAndLogPlatformInformation(this.logger);

installationStage = 'getPackageInfo';
let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath);

installationStage = 'downloadPackages';
let packageManager = new PackageManager(platformInfo, this.packageJSON);
// Specify the packages that the package manager needs to download
packageManager.SetVersionPackagesForDownload(packages);
await GetDependenciesAndDownloadPackages(packages,status, platformInfo, packageManager, this.logger);

this.logger.appendLine();

installationStage = 'installPackages';
await packageManager.InstallPackages(this.logger, status);

installationStage = 'completeSuccess';
}

catch (error) {
ReportInstallationError(this.logger, error, telemetryProps, installationStage);
throw error;// throw the error up to the server
}
finally {
SendInstallationTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem);
}
}
}
Loading