From e9457f2287a429e427039a4420442f0c69613004 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 22 Jan 2018 13:54:17 -0800 Subject: [PATCH 01/15] Enable usage of multiple versions of omnisharp --- package-lock.json | 5 +++ package.json | 5 +++ src/omnisharp/OmnisharpDownloader.ts | 20 +++++++++++ src/omnisharp/launcher.ts | 50 +++++++++++++++------------- src/omnisharp/options.ts | 22 +++++++----- src/omnisharp/server.ts | 17 +++++++++- 6 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 src/omnisharp/OmnisharpDownloader.ts diff --git a/package-lock.json b/package-lock.json index 878983cb61..5b32bdb865 100644 --- a/package-lock.json +++ b/package-lock.json @@ -516,6 +516,11 @@ "graceful-readlink": "1.0.1" } }, + "compare-versions": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.1.0.tgz", + "integrity": "sha512-4hAxDSBypT/yp2ySFD346So6Ragw5xmBn/e/agIGl3bZr6DLUqnoRZPusxKrXdYRZpgexO9daejmIenlq/wrIQ==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index e72c8d1f60..04d9eed8aa 100644 --- a/package.json +++ b/package.json @@ -363,6 +363,11 @@ "default": null, "description": "Specifies the full path to the OmniSharp server." }, + "omnisharp.experimentOmnisharp":{ + "type":"string", + "default": null, + "description": "Specifies if the user wants to use the experiment build. Possible values - latest or some version number" + }, "omnisharp.useMono": { "type": "boolean", "default": false, diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts new file mode 100644 index 0000000000..54f942a34a --- /dev/null +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -0,0 +1,20 @@ +import * as path from 'path'; +import * as utils from '../common'; +import * as fs from 'fs'; + +export class OmnisharpDownloader { + + public GetLatestExperimentVersion(): string { + let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experiment"); + let compareVersions = require('compare-versions'); + let latestVersion: string; + let items = fs.readdirSync(basePath); + if (items) { + items.sort(compareVersions); + latestVersion = items[items.length - 1]; + //get the latest version after sorting + } + + return latestVersion; + } +} \ No newline at end of file diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 2a70ac2737..648341ba7d 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -46,7 +46,7 @@ export function findLaunchTargets(): Thenable { const options = Options.Read(); return vscode.workspace.findFiles( - /*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}', + /*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}', /*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}', /*maxResults*/ options.maxProjectResults) .then(resourcesToLaunchTargets); @@ -88,8 +88,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { let targets: LaunchTarget[] = []; - workspaceFolderToUriMap.forEach((resources, folderIndex) => - { + workspaceFolderToUriMap.forEach((resources, folderIndex) => { let hasCsProjFiles = false, hasSlnFile = false, hasProjectJson = false, @@ -98,15 +97,15 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { hasCake = false; hasCsProjFiles = resources.some(isCSharpProject); - + let folder = vscode.workspace.workspaceFolders[folderIndex]; let folderPath = folder.uri.fsPath; - + resources.forEach(resource => { // Add .sln files if there are .csproj files if (hasCsProjFiles && isSolution(resource)) { hasSlnFile = true; - + targets.push({ label: path.basename(resource.fsPath), description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)), @@ -115,13 +114,13 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Solution }); } - + // Add project.json files if (isProjectJson(resource)) { const dirname = path.dirname(resource.fsPath); hasProjectJson = true; hasProjectJsonAtRoot = hasProjectJsonAtRoot || dirname === folderPath; - + targets.push({ label: path.basename(resource.fsPath), description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)), @@ -130,18 +129,18 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.ProjectJson }); } - + // Discover if there is any CSX file if (!hasCSX && isCsx(resource)) { hasCSX = true; } - + // Discover if there is any Cake file if (!hasCake && isCake(resource)) { hasCake = true; } }); - + // Add the root folder under the following circumstances: // * If there are .csproj files, but no .sln file, and none in the root. // * If there are project.json files, but none in the root. @@ -154,7 +153,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Folder }); } - + // if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder if (hasCSX) { targets.push({ @@ -165,7 +164,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Csx }); } - + // if we noticed any Cake file(s), add a single Cake-specific target pointing at the root folder if (hasCake) { targets.push({ @@ -207,9 +206,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[]): Promise { +export function launchOmniSharp(cwd: string, args: string[], experimentVersion: string): Promise { return new Promise((resolve, reject) => { - launch(cwd, args) + launch(cwd, args, experimentVersion) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -225,12 +224,11 @@ export function launchOmniSharp(cwd: string, args: string[]): Promise { +function launch(cwd: string, args: string[], experimentVersion: string): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); - if (options.useEditorFormattingSettings) - { + if (options.useEditorFormattingSettings) { let globalConfig = vscode.workspace.getConfiguration(); let csharpConfig = vscode.workspace.getConfiguration('[csharp]'); @@ -253,8 +251,14 @@ function launch(cwd: string, args: string[]): Promise { : launchNix(options.path, cwd, args); } - // If the user has not provided a path, we'll use the locally-installed OmniSharp - const basePath = path.resolve(util.getExtensionPath(), '.omnisharp'); + let basePath: string; + if (experimentVersion) { + basePath = path.resolve(util.getExtensionPath(), `.omnisharp/experiment/${experimentVersion}`); + } + else { + // If the user has not provided a path, we'll use the locally-installed OmniSharp + basePath = path.resolve(util.getExtensionPath(), '.omnisharp'); + } if (platformInfo.isWindows()) { return launchWindows(path.join(basePath, 'OmniSharp.exe'), cwd, args); @@ -274,11 +278,11 @@ function launch(cwd: string, args: string[]): Promise { function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csharpConfig: vscode.WorkspaceConfiguration, configurationPath: string, defaultValue: any): any { - + if (csharpConfig[configurationPath] != undefined) { return csharpConfig[configurationPath]; } - + return globalConfig.get(configurationPath, defaultValue); } @@ -287,7 +291,7 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/; return hasSpaceWithoutQuotes.test(arg) ? `"${arg}"` - : arg.replace("&","^&"); + : arg.replace("&", "^&"); } let argsCopy = args.slice(0); // create copy of args diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index 96aa6219de..ecb88d1518 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -18,7 +18,8 @@ export class Options { public useFormatting?: boolean, public showReferencesCodeLens?: boolean, public showTestsCodeLens?: boolean, - public disableCodeActions?: boolean) { } + public disableCodeActions?: boolean, + public experimentOmnisharp?: string) { } public static Read(): Options { // Extra effort is taken below to ensure that legacy versions of options @@ -59,17 +60,20 @@ export class Options { const disableCodeActions = csharpConfig.get('disableCodeActions', false); - return new Options(path, - useMono, + const experimentOmnisharp = omnisharpConfig.get('experimentOmnisharp'); + + return new Options(path, + useMono, waitForDebugger, - loggingLevel, - autoStart, - projectLoadTimeout, - maxProjectResults, - useEditorFormattingSettings, + loggingLevel, + autoStart, + projectLoadTimeout, + maxProjectResults, + useEditorFormattingSettings, useFormatting, showReferencesCodeLens, showTestsCodeLens, - disableCodeActions); + disableCodeActions, + experimentOmnisharp); } } \ No newline at end of file diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 61c002c058..dd82aa148d 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,6 +19,7 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; +import { OmnisharpDownloader } from './OmnisharpDownloader'; enum ServerState { Starting, @@ -259,6 +260,20 @@ export class OmniSharpServer { args.push('--debug'); } + let experimentVersion : string; + let experimentOption = this._options.experimentOmnisharp; + if(experimentOption == "latest"){ + let downloader = new OmnisharpDownloader(); + experimentVersion = downloader.GetLatestExperimentVersion(); + if(!experimentVersion){ + this._logger.appendLine('No directory present in the experiment folder. Using the release version instead'); + } + } + else if(experimentOption){ + //If experiment option is not null means it is set to some version value + experimentVersion = experimentOption; + } + this._logger.appendLine(`Starting OmniSharp server at ${new Date().toLocaleString()}`); this._logger.increaseIndent(); this._logger.appendLine(`Target: ${solutionPath}`); @@ -267,7 +282,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args).then(value => { + return launchOmniSharp(cwd, args, experimentVersion).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } From d24726d7315c1360de3a91318a149e4a170ae278 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 22 Jan 2018 14:24:13 -0800 Subject: [PATCH 02/15] Added file header --- src/omnisharp/OmnisharpDownloader.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 54f942a34a..898c6aba4e 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -1,3 +1,8 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + import * as path from 'path'; import * as utils from '../common'; import * as fs from 'fs'; From fc483424de30fcf65035550e106742b297dd85cb Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 23 Jan 2018 15:37:43 -0800 Subject: [PATCH 03/15] Renamed method and changed all occurences to experimental --- package.json | 2 +- src/omnisharp/OmnisharpDownloader.ts | 4 ++-- src/omnisharp/launcher.ts | 10 +++++----- src/omnisharp/options.ts | 6 +++--- src/omnisharp/server.ts | 20 ++++++++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 04d9eed8aa..faed05384a 100644 --- a/package.json +++ b/package.json @@ -363,7 +363,7 @@ "default": null, "description": "Specifies the full path to the OmniSharp server." }, - "omnisharp.experimentOmnisharp":{ + "omnisharp.experimentalOmnisharp":{ "type":"string", "default": null, "description": "Specifies if the user wants to use the experiment build. Possible values - latest or some version number" diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 898c6aba4e..6bb65f187f 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -9,8 +9,8 @@ import * as fs from 'fs'; export class OmnisharpDownloader { - public GetLatestExperimentVersion(): string { - let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experiment"); + public GetLatestInstalledExperimentalVersion(): string { + let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); let compareVersions = require('compare-versions'); let latestVersion: string; let items = fs.readdirSync(basePath); diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 648341ba7d..07d76cbae1 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -206,9 +206,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[], experimentVersion: string): Promise { +export function launchOmniSharp(cwd: string, args: string[], experimentalVersion: string): Promise { return new Promise((resolve, reject) => { - launch(cwd, args, experimentVersion) + launch(cwd, args, experimentalVersion) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -224,7 +224,7 @@ export function launchOmniSharp(cwd: string, args: string[], experimentVersion: }); } -function launch(cwd: string, args: string[], experimentVersion: string): Promise { +function launch(cwd: string, args: string[], experimentalVersion: string): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); @@ -252,8 +252,8 @@ function launch(cwd: string, args: string[], experimentVersion: string): Promise } let basePath: string; - if (experimentVersion) { - basePath = path.resolve(util.getExtensionPath(), `.omnisharp/experiment/${experimentVersion}`); + if (experimentalVersion) { + basePath = path.resolve(util.getExtensionPath(), `.omnisharp/experimental/${experimentalVersion}`); } else { // If the user has not provided a path, we'll use the locally-installed OmniSharp diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index ecb88d1518..f32809a660 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -19,7 +19,7 @@ export class Options { public showReferencesCodeLens?: boolean, public showTestsCodeLens?: boolean, public disableCodeActions?: boolean, - public experimentOmnisharp?: string) { } + public experimentalOmnisharp?: string) { } public static Read(): Options { // Extra effort is taken below to ensure that legacy versions of options @@ -60,7 +60,7 @@ export class Options { const disableCodeActions = csharpConfig.get('disableCodeActions', false); - const experimentOmnisharp = omnisharpConfig.get('experimentOmnisharp'); + const experimentalOmnisharp = omnisharpConfig.get('experimentalOmnisharp'); return new Options(path, useMono, @@ -74,6 +74,6 @@ export class Options { showReferencesCodeLens, showTestsCodeLens, disableCodeActions, - experimentOmnisharp); + experimentalOmnisharp); } } \ No newline at end of file diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index dd82aa148d..360302fe32 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -260,18 +260,18 @@ export class OmniSharpServer { args.push('--debug'); } - let experimentVersion : string; - let experimentOption = this._options.experimentOmnisharp; - if(experimentOption == "latest"){ + let experimentalVersion : string; + let experimentalOption = this._options.experimentalOmnisharp; + if(experimentalOption == "latest"){ let downloader = new OmnisharpDownloader(); - experimentVersion = downloader.GetLatestExperimentVersion(); - if(!experimentVersion){ - this._logger.appendLine('No directory present in the experiment folder. Using the release version instead'); + experimentalVersion = downloader.GetLatestInstalledExperimentalVersion(); + if(!experimentalVersion){ + this._logger.appendLine('No directory present in the experimental folder. Using the release version instead'); } } - else if(experimentOption){ - //If experiment option is not null means it is set to some version value - experimentVersion = experimentOption; + else if(experimentalOption){ + //If experimental option is not null means it is set to some version value + experimentalVersion = experimentalOption; } this._logger.appendLine(`Starting OmniSharp server at ${new Date().toLocaleString()}`); @@ -282,7 +282,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args, experimentVersion).then(value => { + return launchOmniSharp(cwd, args, experimentalVersion).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } From b657b8412f67df0d79b92a352403cfaff45ed5c5 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 23 Jan 2018 16:08:02 -0800 Subject: [PATCH 04/15] Modified comment and using reduce instead of sort --- src/omnisharp/OmnisharpDownloader.ts | 11 ++++++++--- src/omnisharp/launcher.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 6bb65f187f..fd47f71e05 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -12,12 +12,17 @@ export class OmnisharpDownloader { public GetLatestInstalledExperimentalVersion(): string { let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); let compareVersions = require('compare-versions'); + let latestVersion: string; let items = fs.readdirSync(basePath); if (items) { - items.sort(compareVersions); - latestVersion = items[items.length - 1]; - //get the latest version after sorting + latestVersion = items.reduce((latest, cur) => { + if (compareVersions(latest, cur)) { + return cur; + } + + return latest; + }); } return latestVersion; diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 07d76cbae1..4b73876e0d 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -256,7 +256,7 @@ function launch(cwd: string, args: string[], experimentalVersion: string): Promi basePath = path.resolve(util.getExtensionPath(), `.omnisharp/experimental/${experimentalVersion}`); } else { - // If the user has not provided a path, we'll use the locally-installed OmniSharp + // If the user has not provided a path and some experimental version, we'll use the locally-installed OmniSharp basePath = path.resolve(util.getExtensionPath(), '.omnisharp'); } From a3032982b80f613ffefdf502003702383226a731 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 23 Jan 2018 17:30:42 -0800 Subject: [PATCH 05/15] Using semver to validate packages --- package-lock.json | 5 ----- package.json | 6 +++--- src/omnisharp/OmnisharpDownloader.ts | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5b32bdb865..878983cb61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -516,11 +516,6 @@ "graceful-readlink": "1.0.1" } }, - "compare-versions": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.1.0.tgz", - "integrity": "sha512-4hAxDSBypT/yp2ySFD346So6Ragw5xmBn/e/agIGl3bZr6DLUqnoRZPusxKrXdYRZpgexO9daejmIenlq/wrIQ==" - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index faed05384a..b2f57d226c 100644 --- a/package.json +++ b/package.json @@ -363,10 +363,10 @@ "default": null, "description": "Specifies the full path to the OmniSharp server." }, - "omnisharp.experimentalOmnisharp":{ - "type":"string", + "omnisharp.experimentalOmnisharp": { + "type": "string", "default": null, - "description": "Specifies if the user wants to use the experiment build. Possible values - latest or some version number" + "description": "Specifies if the user wants to use the experiment build. Possible values - latest or some version number" }, "omnisharp.useMono": { "type": "boolean", diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index fd47f71e05..3da7061b01 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -11,18 +11,21 @@ export class OmnisharpDownloader { public GetLatestInstalledExperimentalVersion(): string { let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); - let compareVersions = require('compare-versions'); + const semver = require('semver'); let latestVersion: string; - let items = fs.readdirSync(basePath); - if (items) { - latestVersion = items.reduce((latest, cur) => { - if (compareVersions(latest, cur)) { - return cur; - } - - return latest; - }); + let installedItems = fs.readdirSync(basePath); + if (installedItems) { + let validVersions = installedItems.filter(value => semver.valid(value)); + if(validVersions){ + latestVersion = validVersions.reduce((latestTillNow, element) => { + if (semver.gt(latestTillNow, element)) { + return latestTillNow; + } + + return element; + }); + } } return latestVersion; From bac18df98cc125c17b0f24fcc747a6adeed85f98 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 24 Jan 2018 10:10:21 -0800 Subject: [PATCH 06/15] Changes for the downloader to take a path for getting the latest experiment version --- src/omnisharp/OmnisharpDownloader.ts | 3 +-- src/omnisharp/server.ts | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 3da7061b01..cb9d0bf51b 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -9,8 +9,7 @@ import * as fs from 'fs'; export class OmnisharpDownloader { - public GetLatestInstalledExperimentalVersion(): string { - let basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); + public GetLatestInstalledExperimentalVersion(basePath: string): string { const semver = require('semver'); let latestVersion: string; diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 360302fe32..e06ec7685b 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -264,7 +264,8 @@ export class OmniSharpServer { let experimentalOption = this._options.experimentalOmnisharp; if(experimentalOption == "latest"){ let downloader = new OmnisharpDownloader(); - experimentalVersion = downloader.GetLatestInstalledExperimentalVersion(); + const basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); + experimentalVersion = downloader.GetLatestInstalledExperimentalVersion(basePath); if(!experimentalVersion){ this._logger.appendLine('No directory present in the experimental folder. Using the release version instead'); } From 7237fd3f15ddcba460dfe493841e43e6ce1e1eb0 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 24 Jan 2018 13:42:20 -0800 Subject: [PATCH 07/15] Added unit test for testing latest experiment version --- src/omnisharp/OmnisharpDownloader.ts | 27 ++++----- test/unitTests/omnisharpDownloader.test.ts | 67 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 test/unitTests/omnisharpDownloader.test.ts diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index cb9d0bf51b..c8c00de0a7 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -3,27 +3,28 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import * as utils from '../common'; import * as fs from 'fs'; export class OmnisharpDownloader { - public GetLatestInstalledExperimentalVersion(basePath: string): string { + public GetLatestInstalledExperimentalVersion(basePath: string) { const semver = require('semver'); let latestVersion: string; - let installedItems = fs.readdirSync(basePath); - if (installedItems) { - let validVersions = installedItems.filter(value => semver.valid(value)); - if(validVersions){ - latestVersion = validVersions.reduce((latestTillNow, element) => { - if (semver.gt(latestTillNow, element)) { - return latestTillNow; - } - - return element; - }); + if (fs.existsSync(basePath)) { + let installedItems = fs.readdirSync(basePath); + if (installedItems && installedItems.length > 0) { + let validVersions = installedItems.filter(value => semver.valid(value)); + if (validVersions && validVersions.length > 0) { + latestVersion = validVersions.reduce((latestTillNow, element) => { + if (semver.gt(latestTillNow, element)) { + return latestTillNow; + } + + return element; + }); + } } } diff --git a/test/unitTests/omnisharpDownloader.test.ts b/test/unitTests/omnisharpDownloader.test.ts new file mode 100644 index 0000000000..9ece3b9685 --- /dev/null +++ b/test/unitTests/omnisharpDownloader.test.ts @@ -0,0 +1,67 @@ +/*--------------------------------------------------------------------------------------------- + * 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 * as path from 'path'; +import * as fs from 'fs'; +import { should, assert } from 'chai'; +import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; + +const tmp = require('tmp'); + +suite("Experiment Omnisharp - Latest Version", () => { + suiteSetup(() => should()); + + test('Returns latest version', () => { + let versions: string[] = ["1.28.0", "1.27.0", "1.26.0"]; + let latestVersion = GetLatestVersion(versions); + latestVersion.should.equal("1.28.0"); + }) + + test('Ignores unparseable strings', () => { + let versions: string[] = ["1.28.0", "1.27.0", "1.26.0", "a.b.c"]; + let latestVersion = GetLatestVersion(versions); + latestVersion.should.equal("1.28.0"); + }) + + test('Returns pre-release versions if they are the latest', () => { + let versions: string[] = ["1.28.0", "1.27.0", "1.26.0", "1.29.0-beta1"]; + let latestVersion = GetLatestVersion(versions); + latestVersion.should.equal("1.29.0-beta1"); + }) + + test('Returns undefined if no valid version exists', () => { + let versions: string[] = ["a.b.c"]; + let latestVersion = GetLatestVersion(versions); + assert.equal(latestVersion, undefined); + }) + + test('Returns undefined if folder is empty', () => { + let versions: string[] = []; + let latestVersion = GetLatestVersion(versions); + assert.equal(latestVersion, undefined); + }) + + test('Returns undefined if experimental folder doesnot exist', () => { + let downloader = new OmnisharpDownloader(); + let latestVersion = downloader.GetLatestInstalledExperimentalVersion(""); + assert.equal(latestVersion, undefined); + }) +}) + + +function GetLatestVersion(versions: string[]): string { + let downloader = new OmnisharpDownloader(); + let tmpObj = tmp.dirSync({ unsafeCleanup: true }); + addVersionsToDirectory(tmpObj.name, versions); + let latestVersion = downloader.GetLatestInstalledExperimentalVersion(tmpObj.name); + tmpObj.removeCallback(); + return latestVersion; +} + +function addVersionsToDirectory(dirPath: string, versions: string[]) { + for (let version of versions) { + fs.mkdir(`${dirPath}/${version}`, () => { }); + } +} \ No newline at end of file From 384b1900f59d4de20cb3df3f526e8e935ad55aac Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 24 Jan 2018 14:04:01 -0800 Subject: [PATCH 08/15] Remove unnecessary import --- src/omnisharp/OmnisharpDownloader.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index c8c00de0a7..62a63003db 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as utils from '../common'; import * as fs from 'fs'; export class OmnisharpDownloader { From 49f9d37b5328a7c8ff25135007595992558ff6b5 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 24 Jan 2018 14:28:02 -0800 Subject: [PATCH 09/15] Added checks for the pre-release versions --- test/unitTests/omnisharpDownloader.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/unitTests/omnisharpDownloader.test.ts b/test/unitTests/omnisharpDownloader.test.ts index 9ece3b9685..4778f7d308 100644 --- a/test/unitTests/omnisharpDownloader.test.ts +++ b/test/unitTests/omnisharpDownloader.test.ts @@ -10,7 +10,7 @@ import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; const tmp = require('tmp'); -suite("Experiment Omnisharp - Latest Version", () => { +suite("Experimental Omnisharp - Latest Version", () => { suiteSetup(() => should()); test('Returns latest version', () => { @@ -31,6 +31,18 @@ suite("Experiment Omnisharp - Latest Version", () => { latestVersion.should.equal("1.29.0-beta1"); }) + test('Returns the latest pre-release version', () => { + let versions: string[] = ["1.28.0", "1.27.0", "1.29.0-beta2", "1.29.0-beta1"]; + let latestVersion = GetLatestVersion(versions); + latestVersion.should.equal("1.29.0-beta2"); + }) + + test('Returns the prod version over pre-release version', () => { + let versions: string[] = ["1.28.0", "1.27.0", "1.29.0", "1.29.0-beta1"]; + let latestVersion = GetLatestVersion(versions); + latestVersion.should.equal("1.29.0"); + }) + test('Returns undefined if no valid version exists', () => { let versions: string[] = ["a.b.c"]; let latestVersion = GetLatestVersion(versions); From 05a3cdb2a09a017b8a38388d75dce7081c01ba4e Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 24 Jan 2018 16:43:19 -0800 Subject: [PATCH 10/15] ExtensionPath Calculation only in server.ts --- src/omnisharp/launcher.ts | 10 +++++----- src/omnisharp/server.ts | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 4b73876e0d..6581ca4a91 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -206,9 +206,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[], experimentalVersion: string): Promise { +export function launchOmniSharp(cwd: string, args: string[], extensionPath: string, experimentalVersion: string): Promise { return new Promise((resolve, reject) => { - launch(cwd, args, experimentalVersion) + launch(cwd, args, extensionPath, experimentalVersion) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -224,7 +224,7 @@ export function launchOmniSharp(cwd: string, args: string[], experimentalVersion }); } -function launch(cwd: string, args: string[], experimentalVersion: string): Promise { +function launch(cwd: string, args: string[], extensionPath: string, experimentalVersion: string): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); @@ -253,11 +253,11 @@ function launch(cwd: string, args: string[], experimentalVersion: string): Promi let basePath: string; if (experimentalVersion) { - basePath = path.resolve(util.getExtensionPath(), `.omnisharp/experimental/${experimentalVersion}`); + basePath = path.resolve(extensionPath, `.omnisharp/experimental/${experimentalVersion}`); } else { // If the user has not provided a path and some experimental version, we'll use the locally-installed OmniSharp - basePath = path.resolve(util.getExtensionPath(), '.omnisharp'); + basePath = path.resolve(extensionPath, '.omnisharp'); } if (platformInfo.isWindows()) { diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index e06ec7685b..b5c30eb975 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -262,9 +262,11 @@ export class OmniSharpServer { let experimentalVersion : string; let experimentalOption = this._options.experimentalOmnisharp; + let extensionPath = utils.getExtensionPath(); + if(experimentalOption == "latest"){ let downloader = new OmnisharpDownloader(); - const basePath = path.resolve(utils.getExtensionPath(), ".omnisharp/experimental"); + const basePath = path.resolve(extensionPath, ".omnisharp/experimental"); experimentalVersion = downloader.GetLatestInstalledExperimentalVersion(basePath); if(!experimentalVersion){ this._logger.appendLine('No directory present in the experimental folder. Using the release version instead'); @@ -283,7 +285,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args, experimentalVersion).then(value => { + return launchOmniSharp(cwd, args, extensionPath, experimentalVersion).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } From 924db95ae20b0ed0fa8325ffb5ea6de969ffe169 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 25 Jan 2018 16:26:38 +0000 Subject: [PATCH 11/15] remove unused import to comply with tslint added colomn to test functions --- src/omnisharp/launcher.ts | 3 +-- test/unitTests/omnisharpDownloader.test.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 6581ca4a91..3be7ef01a4 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -10,7 +10,6 @@ import { satisfies } from 'semver'; import { PlatformInformation } from '../platform'; import * as path from 'path'; import * as vscode from 'vscode'; -import * as util from '../common'; import { Options } from './options'; export enum LaunchTargetKind { @@ -61,7 +60,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { // // TODO: // * It should be possible to choose a .csproj as a launch target - // * It should be possible to choose a .sln file even when no .csproj files are found + // * It should be possible to choose a .sln file even when no .csproj files are found // within the root. if (!Array.isArray(resources)) { diff --git a/test/unitTests/omnisharpDownloader.test.ts b/test/unitTests/omnisharpDownloader.test.ts index 4778f7d308..8ab268d718 100644 --- a/test/unitTests/omnisharpDownloader.test.ts +++ b/test/unitTests/omnisharpDownloader.test.ts @@ -17,50 +17,50 @@ suite("Experimental Omnisharp - Latest Version", () => { let versions: string[] = ["1.28.0", "1.27.0", "1.26.0"]; let latestVersion = GetLatestVersion(versions); latestVersion.should.equal("1.28.0"); - }) + }); test('Ignores unparseable strings', () => { let versions: string[] = ["1.28.0", "1.27.0", "1.26.0", "a.b.c"]; let latestVersion = GetLatestVersion(versions); latestVersion.should.equal("1.28.0"); - }) + }); test('Returns pre-release versions if they are the latest', () => { let versions: string[] = ["1.28.0", "1.27.0", "1.26.0", "1.29.0-beta1"]; let latestVersion = GetLatestVersion(versions); latestVersion.should.equal("1.29.0-beta1"); - }) + }); test('Returns the latest pre-release version', () => { let versions: string[] = ["1.28.0", "1.27.0", "1.29.0-beta2", "1.29.0-beta1"]; let latestVersion = GetLatestVersion(versions); latestVersion.should.equal("1.29.0-beta2"); - }) + }); test('Returns the prod version over pre-release version', () => { let versions: string[] = ["1.28.0", "1.27.0", "1.29.0", "1.29.0-beta1"]; let latestVersion = GetLatestVersion(versions); latestVersion.should.equal("1.29.0"); - }) + }); test('Returns undefined if no valid version exists', () => { let versions: string[] = ["a.b.c"]; let latestVersion = GetLatestVersion(versions); assert.equal(latestVersion, undefined); - }) + }); test('Returns undefined if folder is empty', () => { let versions: string[] = []; let latestVersion = GetLatestVersion(versions); assert.equal(latestVersion, undefined); - }) + }); test('Returns undefined if experimental folder doesnot exist', () => { let downloader = new OmnisharpDownloader(); let latestVersion = downloader.GetLatestInstalledExperimentalVersion(""); assert.equal(latestVersion, undefined); - }) -}) + }); +}); function GetLatestVersion(versions: string[]): string { From 031aa4fe2e32614c9225e8132d6da2a635fe706d Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 25 Jan 2018 10:00:43 -0800 Subject: [PATCH 12/15] Manually deleting the files in tmp directory --- test/unitTests/omnisharpDownloader.test.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/unitTests/omnisharpDownloader.test.ts b/test/unitTests/omnisharpDownloader.test.ts index 8ab268d718..d8808da0fa 100644 --- a/test/unitTests/omnisharpDownloader.test.ts +++ b/test/unitTests/omnisharpDownloader.test.ts @@ -62,18 +62,26 @@ suite("Experimental Omnisharp - Latest Version", () => { }); }); - function GetLatestVersion(versions: string[]): string { let downloader = new OmnisharpDownloader(); - let tmpObj = tmp.dirSync({ unsafeCleanup: true }); - addVersionsToDirectory(tmpObj.name, versions); - let latestVersion = downloader.GetLatestInstalledExperimentalVersion(tmpObj.name); - tmpObj.removeCallback(); + let tmpDir = tmp.dirSync(); + let dirPath = tmpDir.name; + AddVersionsToDirectory(dirPath, versions); + let latestVersion = downloader.GetLatestInstalledExperimentalVersion(dirPath); + CleanUpDirectory(dirPath); + tmpDir.removeCallback(); return latestVersion; } -function addVersionsToDirectory(dirPath: string, versions: string[]) { +function AddVersionsToDirectory(dirPath: string, versions: string[]) { for (let version of versions) { fs.mkdir(`${dirPath}/${version}`, () => { }); } -} \ No newline at end of file +} + +function CleanUpDirectory(dirPath: string) { + let installedVersions = fs.readdirSync(dirPath); + for (let version of installedVersions) { + fs.rmdirSync(`${dirPath}/${version}`); + } +} From 498ccab2682045778ef9294cabe9d260516e1c03 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 26 Jan 2018 11:30:09 -0800 Subject: [PATCH 13/15] Separated the feature in two options and removed the downloader class --- package.json | 11 +++++-- src/omnisharp/OmnisharpDownloader.ts | 32 ------------------- src/omnisharp/latestVersionSelector.ts | 28 ++++++++++++++++ src/omnisharp/launcher.ts | 32 +++++++++++++++---- src/omnisharp/options.ts | 11 ++++--- src/omnisharp/server.ts | 20 +----------- ....test.ts => latestVersionSelector.test.ts} | 18 +++++------ 7 files changed, 77 insertions(+), 75 deletions(-) delete mode 100644 src/omnisharp/OmnisharpDownloader.ts create mode 100644 src/omnisharp/latestVersionSelector.ts rename test/unitTests/{omnisharpDownloader.test.ts => latestVersionSelector.test.ts} (81%) diff --git a/package.json b/package.json index b2f57d226c..ec02eafe2e 100644 --- a/package.json +++ b/package.json @@ -363,10 +363,15 @@ "default": null, "description": "Specifies the full path to the OmniSharp server." }, - "omnisharp.experimentalOmnisharp": { + "omnisharp.useLatestExperimentalBuild": { + "type": "boolean", + "default": false, + "description": "Specifies whether the latest experimental omnisharp build must be used" + }, + "omnisharp.alternateVersion": { "type": "string", "default": null, - "description": "Specifies if the user wants to use the experiment build. Possible values - latest or some version number" + "description": "Specifies which alternate omnisharp version must be used" }, "omnisharp.useMono": { "type": "boolean", @@ -2130,4 +2135,4 @@ } ] } -} +} \ No newline at end of file diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts deleted file mode 100644 index 62a63003db..0000000000 --- a/src/omnisharp/OmnisharpDownloader.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as fs from 'fs'; - -export class OmnisharpDownloader { - - public GetLatestInstalledExperimentalVersion(basePath: string) { - const semver = require('semver'); - - let latestVersion: string; - if (fs.existsSync(basePath)) { - let installedItems = fs.readdirSync(basePath); - if (installedItems && installedItems.length > 0) { - let validVersions = installedItems.filter(value => semver.valid(value)); - if (validVersions && validVersions.length > 0) { - latestVersion = validVersions.reduce((latestTillNow, element) => { - if (semver.gt(latestTillNow, element)) { - return latestTillNow; - } - - return element; - }); - } - } - } - - return latestVersion; - } -} \ No newline at end of file diff --git a/src/omnisharp/latestVersionSelector.ts b/src/omnisharp/latestVersionSelector.ts new file mode 100644 index 0000000000..7d71f30358 --- /dev/null +++ b/src/omnisharp/latestVersionSelector.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as fs from 'fs'; +import * as semver from 'semver'; + +export function GetLatestInstalledExperimentalVersion(basePath: string) { + let latestVersion: string = ''; + if (fs.existsSync(basePath)) { + let installedItems = fs.readdirSync(basePath); + if (installedItems && installedItems.length > 0) { + let validVersions = installedItems.filter(value => semver.valid(value)); + if (validVersions && validVersions.length > 0) { + latestVersion = validVersions.reduce((latestTillNow, element) => { + if (semver.gt(latestTillNow, element)) { + return latestTillNow; + } + + return element; + }); + } + } + } + + return latestVersion; +} \ No newline at end of file diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 3be7ef01a4..d70206d77a 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -10,7 +10,9 @@ import { satisfies } from 'semver'; import { PlatformInformation } from '../platform'; import * as path from 'path'; import * as vscode from 'vscode'; +import * as util from '../common'; import { Options } from './options'; +import { GetLatestInstalledExperimentalVersion } from './latestVersionSelector'; export enum LaunchTargetKind { Solution, @@ -205,9 +207,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[], extensionPath: string, experimentalVersion: string): Promise { +export function launchOmniSharp(cwd: string, args: string[]): Promise { return new Promise((resolve, reject) => { - launch(cwd, args, extensionPath, experimentalVersion) + launch(cwd, args) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -223,7 +225,7 @@ export function launchOmniSharp(cwd: string, args: string[], extensionPath: stri }); } -function launch(cwd: string, args: string[], extensionPath: string, experimentalVersion: string): Promise { +function launch(cwd: string, args: string[]): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); @@ -250,12 +252,16 @@ function launch(cwd: string, args: string[], extensionPath: string, experimental : launchNix(options.path, cwd, args); } + let extensionPath = util.getExtensionPath(); let basePath: string; - if (experimentalVersion) { - basePath = path.resolve(extensionPath, `.omnisharp/experimental/${experimentalVersion}`); + if (options.alternateVersion) { + basePath = path.resolve(extensionPath,`.omnisharp/experimental/${options.alternateVersion}`); + } + else if (options.useLatestExperimentalBuild) { + basePath = getLatestExperimentalBuildPath(extensionPath); } else { - // If the user has not provided a path and some experimental version, we'll use the locally-installed OmniSharp + // If the user has neither provided a path not set any options for using other versions, we'll use the locally-installed OmniSharp basePath = path.resolve(extensionPath, '.omnisharp'); } @@ -275,6 +281,18 @@ function launch(cwd: string, args: string[], extensionPath: string, experimental }); } +function getLatestExperimentalBuildPath(extensionPath: string) { + let dirPath = path.resolve(extensionPath, `.omnisharp/experimental`); + let latestVersion = GetLatestInstalledExperimentalVersion(dirPath); + if (latestVersion && latestVersion.length>0) { + return path.resolve(extensionPath, `.omnisharp/experimental/${latestVersion}`); + } + else { + //If there is no latest version present in experimental folder, use the release version + return path.resolve(extensionPath, `.omnisharp`); + } +} + function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csharpConfig: vscode.WorkspaceConfiguration, configurationPath: string, defaultValue: any): any { @@ -398,4 +416,4 @@ export function hasMono(range?: string): Promise { resolve(ret); }); }); -} \ No newline at end of file +} diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index f32809a660..2b90ecf267 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -19,7 +19,8 @@ export class Options { public showReferencesCodeLens?: boolean, public showTestsCodeLens?: boolean, public disableCodeActions?: boolean, - public experimentalOmnisharp?: string) { } + public alternateVersion?: string, + public useLatestExperimentalBuild?: boolean) { } public static Read(): Options { // Extra effort is taken below to ensure that legacy versions of options @@ -60,8 +61,9 @@ export class Options { const disableCodeActions = csharpConfig.get('disableCodeActions', false); - const experimentalOmnisharp = omnisharpConfig.get('experimentalOmnisharp'); - + const alternateVersion = omnisharpConfig.get('alternateVersion'); + const useLatestExperimentalBuild = omnisharpConfig.get('useLatestExperimentalBuild', false); + return new Options(path, useMono, waitForDebugger, @@ -74,6 +76,7 @@ export class Options { showReferencesCodeLens, showTestsCodeLens, disableCodeActions, - experimentalOmnisharp); + alternateVersion, + useLatestExperimentalBuild); } } \ No newline at end of file diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index b5c30eb975..61c002c058 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,7 +19,6 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; -import { OmnisharpDownloader } from './OmnisharpDownloader'; enum ServerState { Starting, @@ -260,23 +259,6 @@ export class OmniSharpServer { args.push('--debug'); } - let experimentalVersion : string; - let experimentalOption = this._options.experimentalOmnisharp; - let extensionPath = utils.getExtensionPath(); - - if(experimentalOption == "latest"){ - let downloader = new OmnisharpDownloader(); - const basePath = path.resolve(extensionPath, ".omnisharp/experimental"); - experimentalVersion = downloader.GetLatestInstalledExperimentalVersion(basePath); - if(!experimentalVersion){ - this._logger.appendLine('No directory present in the experimental folder. Using the release version instead'); - } - } - else if(experimentalOption){ - //If experimental option is not null means it is set to some version value - experimentalVersion = experimentalOption; - } - this._logger.appendLine(`Starting OmniSharp server at ${new Date().toLocaleString()}`); this._logger.increaseIndent(); this._logger.appendLine(`Target: ${solutionPath}`); @@ -285,7 +267,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args, extensionPath, experimentalVersion).then(value => { + return launchOmniSharp(cwd, args).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } diff --git a/test/unitTests/omnisharpDownloader.test.ts b/test/unitTests/latestVersionSelector.test.ts similarity index 81% rename from test/unitTests/omnisharpDownloader.test.ts rename to test/unitTests/latestVersionSelector.test.ts index d8808da0fa..298d494fac 100644 --- a/test/unitTests/omnisharpDownloader.test.ts +++ b/test/unitTests/latestVersionSelector.test.ts @@ -6,7 +6,7 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; import { should, assert } from 'chai'; -import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; +import { GetLatestInstalledExperimentalVersion } from '../../src/omnisharp/latestVersionSelector'; const tmp = require('tmp'); @@ -46,28 +46,26 @@ suite("Experimental Omnisharp - Latest Version", () => { test('Returns undefined if no valid version exists', () => { let versions: string[] = ["a.b.c"]; let latestVersion = GetLatestVersion(versions); - assert.equal(latestVersion, undefined); + latestVersion.should.equal(""); }); - test('Returns undefined if folder is empty', () => { + test('Returns empty if folder is empty', () => { let versions: string[] = []; let latestVersion = GetLatestVersion(versions); - assert.equal(latestVersion, undefined); + latestVersion.should.equal(""); }); - test('Returns undefined if experimental folder doesnot exist', () => { - let downloader = new OmnisharpDownloader(); - let latestVersion = downloader.GetLatestInstalledExperimentalVersion(""); - assert.equal(latestVersion, undefined); + test('Returns empty if experimental folder doesnot exist', () => { + let latestVersion = GetLatestInstalledExperimentalVersion(""); + latestVersion.should.equal(""); }); }); function GetLatestVersion(versions: string[]): string { - let downloader = new OmnisharpDownloader(); let tmpDir = tmp.dirSync(); let dirPath = tmpDir.name; AddVersionsToDirectory(dirPath, versions); - let latestVersion = downloader.GetLatestInstalledExperimentalVersion(dirPath); + let latestVersion = GetLatestInstalledExperimentalVersion(dirPath); CleanUpDirectory(dirPath); tmpDir.removeCallback(); return latestVersion; From 23819e979d194b4fe14a30f95eb71ec0568a4200 Mon Sep 17 00:00:00 2001 From: akshita31 Date: Fri, 26 Jan 2018 14:02:34 -0800 Subject: [PATCH 14/15] Remove unnecessary import --- test/unitTests/latestVersionSelector.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unitTests/latestVersionSelector.test.ts b/test/unitTests/latestVersionSelector.test.ts index 298d494fac..2f50ddbbca 100644 --- a/test/unitTests/latestVersionSelector.test.ts +++ b/test/unitTests/latestVersionSelector.test.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; -import { should, assert } from 'chai'; +import { should } from 'chai'; import { GetLatestInstalledExperimentalVersion } from '../../src/omnisharp/latestVersionSelector'; const tmp = require('tmp'); From cc6f081eb129c0e55691379c75b168a18965897a Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 29 Jan 2018 17:57:20 -0800 Subject: [PATCH 15/15] Synchronous creation of directories --- test/unitTests/latestVersionSelector.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unitTests/latestVersionSelector.test.ts b/test/unitTests/latestVersionSelector.test.ts index 2f50ddbbca..a2d2f04b56 100644 --- a/test/unitTests/latestVersionSelector.test.ts +++ b/test/unitTests/latestVersionSelector.test.ts @@ -73,7 +73,7 @@ function GetLatestVersion(versions: string[]): string { function AddVersionsToDirectory(dirPath: string, versions: string[]) { for (let version of versions) { - fs.mkdir(`${dirPath}/${version}`, () => { }); + fs.mkdirSync(`${dirPath}/${version}`); } }