Skip to content
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
13 changes: 5 additions & 8 deletions src/CSharpExtDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as util from './common';
import { GetNetworkConfiguration, GetStatus } from './downloader.helper';
import { GetNetworkConfiguration } from './downloader.helper';
import { PackageManager } from './packages';
import { PlatformInformation } from './platform';
import { PackageInstallation, LogPlatformInfo, InstallationSuccess, InstallationFailure } from './omnisharp/loggingEvents';
Expand All @@ -21,9 +21,7 @@ export class CSharpExtDownloader {
}

public async installRuntimeDependencies(): Promise<boolean> {
this.eventStream.post(new PackageInstallation("C# dependencies" ));

let status = GetStatus();
this.eventStream.post(new PackageInstallation("C# dependencies"));
let installationStage = 'touchBeginFile';
let success = false;

Expand All @@ -32,17 +30,17 @@ export class CSharpExtDownloader {

let packageManager = new PackageManager(this.platformInfo, this.packageJSON);
// Display platform information and RID
this.eventStream.post(new LogPlatformInfo(this.platformInfo ));
this.eventStream.post(new LogPlatformInfo(this.platformInfo));

installationStage = 'downloadPackages';
let networkConfiguration = GetNetworkConfiguration();
const proxy = networkConfiguration.Proxy;
const strictSSL = networkConfiguration.StrictSSL;

await packageManager.DownloadPackages(this.eventStream, status, proxy, strictSSL);
await packageManager.DownloadPackages(this.eventStream, proxy, strictSSL);

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

installationStage = 'touchLockFile';
await util.touchInstallFile(util.InstallFileType.Lock);
Expand All @@ -54,7 +52,6 @@ export class CSharpExtDownloader {
this.eventStream.post(new InstallationFailure(installationStage, error));
}
finally {
status.dispose();
// We do this step at the end so that we clean up the begin file in the case that we hit above catch block
// Attach a an empty catch to this so that errors here do not propogate
try {
Expand Down
20 changes: 0 additions & 20 deletions src/downloader.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Status } from './packages';

export function GetNetworkConfiguration() {
const config = vscode.workspace.getConfiguration();
const proxy = config.get<string>('http.proxy');
const strictSSL = config.get('http.proxyStrictSSL', true);
return { Proxy: proxy, StrictSSL: strictSSL };
}

export function GetStatus(): Status {
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();
},
dispose: () => {
statusItem.dispose();
}
};

return status;
}
4 changes: 3 additions & 1 deletion src/observers/BaseStatusBarItemObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ export abstract class BaseStatusBarItemObserver {
constructor(private statusBarItem: StatusBarItem) {
}

public SetAndShowStatusBar(text: string, command: string, color?: string) {
public SetAndShowStatusBar(text: string, command: string, color?: string, tooltip?: string) {
this.statusBarItem.text = text;
this.statusBarItem.command = command;
this.statusBarItem.color = color;
this.statusBarItem.tooltip = tooltip;
this.statusBarItem.show();
}

public ResetAndHideStatusBar() {
this.statusBarItem.text = undefined;
this.statusBarItem.command = undefined;
this.statusBarItem.color = undefined;
this.statusBarItem.tooltip = undefined;
this.statusBarItem.hide();
}

Expand Down
24 changes: 18 additions & 6 deletions src/observers/CsharpLoggerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ export class CsharpLoggerObserver extends BaseLoggerObserver {
case Event.ProjectJsonDeprecatedWarning.name:
this.logger.appendLine("Warning: project.json is no longer a supported project format for .NET Core applications. Update to the latest version of .NET Core (https://aka.ms/netcoredownload) and use 'dotnet migrate' to upgrade your project (see https://aka.ms/netcoremigrate for details).");
break;
case Event.DownloadFallBack.name:
this.handleDownloadFallback(<Event.DownloadFallBack>event);
break;
case Event.DownloadSizeObtained.name:
this.handleDownloadSizeObtained(<Event.DownloadSizeObtained>event);
break;
}
}

private handleDownloadSizeObtained(event: Event.DownloadSizeObtained) {
this.logger.append(`(${Math.ceil(event.packageSize / 1024)} KB)`);
}

private handleDownloadFallback(event: Event.DownloadFallBack) {
this.logger.append(`\tRetrying from '${event.fallbackUrl}' `);
}

private handleEventWithMessage(event: Event.EventWithMessage) {
this.logger.appendLine(event.message);
}
Expand Down Expand Up @@ -81,19 +95,17 @@ export class CsharpLoggerObserver extends BaseLoggerObserver {

private handleDownloadProgress(event: Event.DownloadProgress) {
let newDots = Math.ceil(event.downloadPercentage / 5);
if (newDots > this.dots) {
this.logger.append('.'.repeat(newDots - this.dots));
this.dots = newDots;
}
this.logger.append('.'.repeat(newDots - this.dots));
this.dots = newDots;
}

private handleDownloadStart(event: Event.DownloadStart) {
this.logger.append(event.message);
this.logger.append(`Downloading package '${event.packageDescription}' `);
this.dots = 0;
}

private handleInstallationProgress(event: Event.InstallationProgress) {
this.logger.appendLine(event.message);
this.logger.appendLine(`Installing package '${event.packageDescription}'`);
this.logger.appendLine();
}
}
20 changes: 15 additions & 5 deletions src/observers/OmnisharpStatusBarObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,36 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { OmnisharpServerOnServerError, BaseEvent, OmnisharpOnBeforeServerInstall, OmnisharpOnBeforeServerStart, OmnisharpServerOnStop, OmnisharpServerOnStart } from "../omnisharp/loggingEvents";
import { OmnisharpServerOnServerError, BaseEvent, OmnisharpOnBeforeServerInstall, OmnisharpOnBeforeServerStart, OmnisharpServerOnStop, OmnisharpServerOnStart, DownloadStart, InstallationProgress, DownloadProgress } from "../omnisharp/loggingEvents";
import { BaseStatusBarItemObserver } from './BaseStatusBarItemObserver';

export class OmnisharpStatusBarObserver extends BaseStatusBarItemObserver {
public post = (event: BaseEvent) => {
switch (event.constructor.name) {
case OmnisharpServerOnServerError.name:
this.SetAndShowStatusBar('$(flame) Error starting OmniSharp', 'o.showOutput', '');
this.SetAndShowStatusBar('$(flame)', 'o.showOutput', 'rgb(218,0,0)', 'Error starting OmniSharp');
break;
case OmnisharpOnBeforeServerInstall.name:
this.SetAndShowStatusBar('$(flame) Installing OmniSharp...', 'o.showOutput', '');
this.SetAndShowStatusBar('$(flame) Installing OmniSharp...', 'o.showOutput');
break;
case OmnisharpOnBeforeServerStart.name:
this.SetAndShowStatusBar('$(flame) Starting...', 'o.showOutput', '');
this.SetAndShowStatusBar('$(flame)', 'o.showOutput', 'rgb(218,218,0)', 'Starting OmniSharp server');
break;
case OmnisharpServerOnStop.name:
this.ResetAndHideStatusBar();
break;
case OmnisharpServerOnStart.name:
this.SetAndShowStatusBar('$(flame) Running', 'o.showOutput', '');
this.SetAndShowStatusBar('$(flame)', 'o.showOutput', 'rgb(0, 218, 0)', 'OmniSharp server is running');
break;
case DownloadStart.name:
this.SetAndShowStatusBar("$(cloud-download) Downloading packages", '', '', `Downloading package '${(<DownloadStart>event).packageDescription}...' `);
break;
case InstallationProgress.name:
this.SetAndShowStatusBar("$(desktop-download) Installing packages...", '', '', `Installing package '${(<InstallationProgress>event).packageDescription}'`);
break;
case DownloadProgress.name:
let progressEvent = <DownloadProgress>event;
this.SetAndShowStatusBar("$(cloud-download) Downloading packages", '', '', `Downloading package '${progressEvent.packageDescription}'... ${progressEvent.downloadPercentage}%`);
break;
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/omnisharp/OmnisharpDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { GetNetworkConfiguration, GetStatus } from '../downloader.helper';
import { GetNetworkConfiguration } from '../downloader.helper';
import { GetPackagesFromVersion, GetVersionFilePackage } from './OmnisharpPackageCreator';
import { Package, PackageManager, Status } from '../packages';
import { Package, PackageManager } from '../packages';
import { PlatformInformation } from '../platform';
import { PackageInstallation, LogPlatformInfo, InstallationSuccess, InstallationFailure, InstallationProgress } from './loggingEvents';
import { EventStream } from '../EventStream';
Expand All @@ -16,7 +16,6 @@ export interface IPackageManagerFactory {
}

export class OmnisharpDownloader {
private status: Status;
private proxy: string;
private strictSSL: boolean;
private packageManager: PackageManager;
Expand All @@ -27,7 +26,6 @@ export class OmnisharpDownloader {
private platformInfo: PlatformInformation,
packageManagerFactory: IPackageManagerFactory = defaultPackageManagerFactory) {

this.status = GetStatus();
let networkConfiguration = GetNetworkConfiguration();
this.proxy = networkConfiguration.Proxy;
this.strictSSL = networkConfiguration.StrictSSL;
Expand All @@ -47,20 +45,17 @@ export class OmnisharpDownloader {
installationStage = 'downloadPackages';
// Specify the packages that the package manager needs to download
this.packageManager.SetVersionPackagesForDownload(packages);
await this.packageManager.DownloadPackages(this.eventStream, this.status, this.proxy, this.strictSSL);
await this.packageManager.DownloadPackages(this.eventStream, this.proxy, this.strictSSL);

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

this.eventStream.post(new InstallationSuccess());
}
catch (error) {
this.eventStream.post(new InstallationFailure(installationStage, error));
throw error;// throw the error up to the server
}
finally {
this.status.dispose();
}
}

public async GetLatestVersion(serverUrl: string, latestVersionFileServerPath: string): Promise<string> {
Expand All @@ -70,7 +65,7 @@ export class OmnisharpDownloader {
//The package manager needs a package format to download, hence we form a package for the latest version file
let filePackage = GetVersionFilePackage(serverUrl, latestVersionFileServerPath);
//Fetch the latest version information from the file
return await this.packageManager.GetLatestVersionFromFile(this.eventStream, this.status, this.proxy, this.strictSSL, filePackage);
return await this.packageManager.GetLatestVersionFromFile(this.eventStream, this.proxy, this.strictSSL, filePackage);
}
catch (error) {
this.eventStream.post(new InstallationFailure(installationStage, error));
Expand Down
3 changes: 2 additions & 1 deletion src/omnisharp/OmnisharpPackageCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function GetPackage(inputPackage: Package, serverUrl: string, version: string, i
"description": `${inputPackage.description}, Version = ${version}`,
"url": `${serverUrl}/releases/${version}/omnisharp-${inputPackage.platformId}.zip`,
"installPath": `${installPath}/${version}`,
"installTestPath": `./${installPath}/${version}/${installBinary}`
"installTestPath": `./${installPath}/${version}/${installBinary}`,
"fallbackUrl": "" //setting to empty so that we dont use the fallback url of the default packages
};

return versionPackage;
Expand Down
17 changes: 14 additions & 3 deletions src/omnisharp/loggingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export class LogPlatformInfo implements BaseEvent {
}

export class InstallationProgress implements BaseEvent {
constructor(public stage: string, public message: string) { }
constructor(public stage: string, public packageDescription: string) { }
}

export class InstallationFailure implements BaseEvent {
constructor(public stage: string, public error: any) { }
}

export class DownloadProgress implements BaseEvent {
constructor(public downloadPercentage: number) { }
constructor(public downloadPercentage: number, public packageDescription: string) { }
}

export class OmnisharpFailure implements BaseEvent {
Expand Down Expand Up @@ -106,12 +106,23 @@ export class EventWithMessage implements BaseEvent {
constructor(public message: string) { }
}

export class DownloadStart implements BaseEvent {
constructor(public packageDescription: string) { }
}

export class DownloadFallBack implements BaseEvent {
constructor(public fallbackUrl: string) { }
}

export class DownloadSizeObtained implements BaseEvent {
constructor(public packageSize: number) { }
}

export class DebuggerPrerequisiteFailure extends EventWithMessage { }
export class DebuggerPrerequisiteWarning extends EventWithMessage { }
export class CommandDotNetRestoreProgress extends EventWithMessage { }
export class CommandDotNetRestoreSucceeded extends EventWithMessage { }
export class CommandDotNetRestoreFailed extends EventWithMessage { }
export class DownloadStart extends EventWithMessage { }
export class DownloadSuccess extends EventWithMessage { }
export class DownloadFailure extends EventWithMessage { }
export class OmnisharpServerOnStdErr extends EventWithMessage { }
Expand Down
Loading