Skip to content

Commit 7e3f874

Browse files
Rationalize (and improve) code to detect the current linux distribution
1 parent 56973aa commit 7e3f874

File tree

6 files changed

+281
-144
lines changed

6 files changed

+281
-144
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"compile": "node ./node_modules/vscode/bin/compile -p ./",
2323
"watch": "node ./node_modules/vscode/bin/compile -watch -p ./",
24-
"test": "mocha --timeout 15000 -u tdd ./out/test/**/*.tests.js",
24+
"test": "mocha --timeout 15000 -u tdd ./out/test/*.tests.js ./out/test/**/*.tests.js",
2525
"postinstall": "node ./node_modules/vscode/bin/install"
2626
},
2727
"dependencies": {

src/coreclr-debug/activate.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe
3939
let installer = new debugInstall.DebugInstaller(_util);
4040
_util.createInstallLog();
4141

42-
let runtimeId = getPlatformRuntimeId();
43-
4442
let statusBarMessage = vscode.window.setStatusBarMessage("Downloading and configuring the .NET Core Debugger...");
4543

44+
let runtimeId: string = '';
4645
let installStage: string = "installBegin";
4746
let installError: string = '';
4847
let moreErrors: string = '';
4948

50-
writeInstallBeginFile().then(() => {
49+
getPlatformRuntimeId().then(rid => {
50+
runtimeId = rid;
51+
}).then(() => {
52+
return writeInstallBeginFile();
53+
}).then(() => {
5154
return installer.install(runtimeId);
5255
}).then(() => {
5356
installStage = "completeSuccess";
@@ -162,32 +165,34 @@ function deleteInstallBeginFile() {
162165
}
163166
}
164167

165-
function getPlatformRuntimeId() : string {
168+
function getPlatformRuntimeId(): Promise<string> {
166169
switch (process.platform) {
167170
case 'win32':
168-
return 'win7-x64';
171+
return Promise.resolve('win7-x64');
169172
case 'darwin':
170-
return 'osx.10.11-x64';
173+
return Promise.resolve('osx.10.11-x64');
171174
case 'linux':
172-
switch (getCurrentPlatform())
173-
{
174-
case Platform.CentOS:
175-
return 'centos.7-x64';
176-
case Platform.Fedora:
177-
return 'fedora.23-x64';
178-
case Platform.OpenSUSE:
179-
return 'opensuse.13.2-x64';
180-
case Platform.RHEL:
181-
return 'rhel.7-x64';
182-
case Platform.Debian:
183-
return 'debian.8-x64';
184-
case Platform.Ubuntu14:
185-
return 'ubuntu.14.04-x64';
186-
case Platform.Ubuntu16:
187-
return 'ubuntu.16.04-x64';
188-
default:
189-
throw Error('Error: Unsupported linux platform');
190-
}
175+
return getCurrentPlatform().then(platform => {
176+
switch (platform)
177+
{
178+
case Platform.CentOS:
179+
return 'centos.7-x64';
180+
case Platform.Fedora:
181+
return 'fedora.23-x64';
182+
case Platform.OpenSUSE:
183+
return 'opensuse.13.2-x64';
184+
case Platform.RHEL:
185+
return 'rhel.7-x64';
186+
case Platform.Debian:
187+
return 'debian.8-x64';
188+
case Platform.Ubuntu14:
189+
return 'ubuntu.14.04-x64';
190+
case Platform.Ubuntu16:
191+
return 'ubuntu.16.04-x64';
192+
default:
193+
throw Error('Error: Unsupported linux platform');
194+
}
195+
});
191196
default:
192197
_util.log('Error: Unsupported platform ' + process.platform);
193198
throw Error('Unsupported platform ' + process.platform);

src/omnisharp/launcher.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import * as omnisharp from './omnisharp';
1212
import * as path from 'path';
1313
import * as vscode from 'vscode';
1414

15-
const platform = getCurrentPlatform();
16-
1715
export enum LaunchTargetKind {
1816
Solution,
1917
ProjectJson,
@@ -34,7 +32,7 @@ export interface LaunchTarget {
3432
export function getDefaultFlavor(kind: LaunchTargetKind) {
3533
// Default to desktop (for Windows) or mono (for OSX/Linux) for solution files; otherwise, CoreCLR.
3634
if (kind === LaunchTargetKind.Solution) {
37-
if (platform === Platform.Windows) {
35+
if (process.platform === 'win32') {
3836
return omnisharp.Flavor.Desktop;
3937
}
4038

@@ -174,12 +172,14 @@ export function launchOmniSharp(details: LaunchDetails): Promise<LaunchResult> {
174172
}
175173

176174
function launch(details: LaunchDetails): Promise<LaunchResult> {
177-
if (platform === Platform.Windows) {
178-
return launchWindows(details);
179-
}
180-
else {
181-
return launchNix(details);
182-
}
175+
return getCurrentPlatform().then(platform => {
176+
if (platform === Platform.Windows) {
177+
return launchWindows(details);
178+
}
179+
else {
180+
return launchNix(details);
181+
}
182+
});
183183
}
184184

185185
function launchWindows(details: LaunchDetails): Promise<LaunchResult> {

src/omnisharp/server.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -423,32 +423,33 @@ export abstract class OmnisharpServer {
423423
}).catch(err => {
424424
return omnisharp.findServerPath(installDirectory);
425425
}).catch(err => {
426-
const platform = getCurrentPlatform();
427-
if (platform == Platform.Unknown && process.platform === 'linux') {
428-
this._channel.appendLine("[ERROR] Could not locate an OmniSharp server that supports your Linux distribution.");
429-
this._channel.appendLine("");
430-
this._channel.appendLine("OmniSharp provides a richer C# editing experience, with features like IntelliSense and Find All References.");
431-
this._channel.appendLine("It is recommend that you download the version of OmniSharp that runs on Mono using the following steps:");
432-
this._channel.appendLine(" 1. If it's not already installed, download and install Mono (https://www.mono-project.com)");
433-
this._channel.appendLine(" 2. Download and untar the latest OmniSharp Mono release from https://github.com/OmniSharp/omnisharp-roslyn/releases/");
434-
this._channel.appendLine(" 3. In Visual Studio Code, select Preferences->User Settings to open settings.json.");
435-
this._channel.appendLine(" 4. In settings.json, add a new setting: \"omnisharp.path\": \"/path/to/omnisharp/OmniSharp.exe\"");
436-
this._channel.appendLine(" 5. In settings.json, add a new setting: \"omnisharp.useMono\": true");
437-
this._channel.appendLine(" 6. Restart Visual Studio Code.");
438-
this._channel.show();
439-
440-
throw err;
441-
}
426+
return getCurrentPlatform().then(platform => {
427+
if (platform === Platform.Unknown && process.platform === 'linux') {
428+
this._channel.appendLine("[ERROR] Could not locate an OmniSharp server that supports your Linux distribution.");
429+
this._channel.appendLine("");
430+
this._channel.appendLine("OmniSharp provides a richer C# editing experience, with features like IntelliSense and Find All References.");
431+
this._channel.appendLine("It is recommend that you download the version of OmniSharp that runs on Mono using the following steps:");
432+
this._channel.appendLine(" 1. If it's not already installed, download and install Mono (https://www.mono-project.com)");
433+
this._channel.appendLine(" 2. Download and untar the latest OmniSharp Mono release from https://github.com/OmniSharp/omnisharp-roslyn/releases/");
434+
this._channel.appendLine(" 3. In Visual Studio Code, select Preferences->User Settings to open settings.json.");
435+
this._channel.appendLine(" 4. In settings.json, add a new setting: \"omnisharp.path\": \"/path/to/omnisharp/OmniSharp.exe\"");
436+
this._channel.appendLine(" 5. In settings.json, add a new setting: \"omnisharp.useMono\": true");
437+
this._channel.appendLine(" 6. Restart Visual Studio Code.");
438+
this._channel.show();
439+
440+
throw err;
441+
}
442442

443-
const config = vscode.workspace.getConfiguration();
444-
const proxy = config.get<string>('http.proxy');
445-
const strictSSL = config.get('http.proxyStrictSSL', true);
446-
const logger = (message: string) => { this._logger.appendLine(message); };
443+
const config = vscode.workspace.getConfiguration();
444+
const proxy = config.get<string>('http.proxy');
445+
const strictSSL = config.get('http.proxyStrictSSL', true);
446+
const logger = (message: string) => { this._logger.appendLine(message); };
447447

448-
this._fireEvent(Events.BeforeServerInstall, this);
448+
this._fireEvent(Events.BeforeServerInstall, this);
449449

450-
return download.go(flavor, platform, this._logger, proxy, strictSSL).then(_ => {
451-
return omnisharp.findServerPath(installDirectory);
450+
return download.go(flavor, platform, this._logger, proxy, strictSSL).then(_ => {
451+
return omnisharp.findServerPath(installDirectory);
452+
});
452453
});
453454
});
454455
}

0 commit comments

Comments
 (0)