Skip to content

Commit bc40a7f

Browse files
Merge pull request #188 from DustinCampbell/update-omnisharp
Update with latest OmniSharp and pick correct version for current Linux distribution
2 parents d646e1c + e230b12 commit bc40a7f

5 files changed

+91
-17
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharp",
33
"publisher": "ms-vscode",
4-
"version": "1.0.1-rc2",
4+
"version": "1.0.2-rc2",
55
"description": "C# for Visual Studio Code (powered by OmniSharp).",
66
"displayName": "C#",
77
"author": "Microsoft Corporation",

src/omnisharpDownload.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,39 @@
88
import * as fs from 'fs-extra-promise';
99
import * as path from 'path';
1010
import * as tmp from 'tmp';
11+
import {SupportedPlatform, getSupportedPlatform} from './utils';
1112

1213
const Decompress = require('decompress');
1314
const Github = require('github-releases');
1415

1516
const OmnisharpRepo = 'OmniSharp/omnisharp-roslyn';
16-
const OmnisharpVersion = 'v1.9-alpha10';
17+
const OmnisharpVersion = 'v1.9-alpha13';
1718
const DefaultInstallLocation = path.join(__dirname, '../.omnisharp');
1819

1920
tmp.setGracefulCleanup();
2021

2122
function getOmnisharpAssetName(): string {
22-
switch (process.platform) {
23-
case 'win32':
23+
switch (getSupportedPlatform()) {
24+
case SupportedPlatform.Windows:
2425
return 'omnisharp-win-x64-net451.zip';
25-
case 'darwin':
26+
case SupportedPlatform.OSX:
2627
return 'omnisharp-osx-x64-netcoreapp1.0.tar.gz';
27-
case 'linux':
28-
return 'omnisharp-linux-x64-netcoreapp1.0.tar.gz';
28+
case SupportedPlatform.CentOS:
29+
return 'omnisharp-centos-x64-netcoreapp1.0.tar.gz';
30+
case SupportedPlatform.Debian:
31+
return 'omnisharp-debian-x64-netcoreapp1.0.tar.gz';
32+
case SupportedPlatform.RHEL:
33+
return 'omnisharp-rhel-x64-netcoreapp1.0.tar.gz';
34+
case SupportedPlatform.Ubuntu:
35+
return 'omnisharp-ubuntu-x64-netcoreapp1.0.tar.gz';
36+
2937
default:
30-
throw new Error(`Unsupported platform: ${process.platform}`);
38+
if (process.platform === 'linux') {
39+
throw new Error(`Unsupported linux distribution`);
40+
}
41+
else {
42+
throw new Error(`Unsupported platform: ${process.platform}`);
43+
}
3144
}
3245
}
3346

src/omnisharpServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export abstract class OmnisharpServer {
264264
this._fireEvent(Events.StdOut, `[INFO] Starting OmniSharp at '${solutionPath}'...\n`);
265265
this._fireEvent(Events.BeforeServerStart, solutionPath);
266266

267-
return omnisharpLauncher(cwd, argv).then(value => {
267+
return omnisharpLauncher(this._channel, cwd, argv).then(value => {
268268
this._serverProcess = value.process;
269269
this._requestDelays = {};
270270
this._fireEvent(Events.StdOut, `[INFO] Started OmniSharp from '${value.command}' with process id ${value.process.pid}...\n`);

src/omnisharpServerLauncher.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import {exists as fileExists} from 'fs';
99
import {spawn, ChildProcess} from 'child_process';
10-
import {workspace} from 'vscode';
10+
import {workspace, OutputChannel} from 'vscode';
1111
import {satisfies} from 'semver';
1212
import {join} from 'path';
1313
import {getOmnisharpLaunchFilePath} from './omnisharpPath';
1414
import {downloadOmnisharp} from './omnisharpDownload';
15+
import {SupportedPlatform, getSupportedPlatform} from './utils';
1516

1617
const isWindows = process.platform === 'win32';
1718

@@ -20,20 +21,34 @@ export interface LaunchResult {
2021
command: string;
2122
}
2223

23-
export function installOmnisharpIfNeeded(): Promise<string> {
24+
export function installOmnisharpIfNeeded(output: OutputChannel): Promise<string> {
2425
return getOmnisharpLaunchFilePath().catch(err => {
26+
if (getSupportedPlatform() == SupportedPlatform.None && process.platform === 'linux') {
27+
output.appendLine("[ERROR] Could not locate an OmniSharp server that supports your Linux distribution.");
28+
output.appendLine("");
29+
output.appendLine("OmniSharp provides a richer C# editing experience, with features like IntelliSense and Find All References.");
30+
output.appendLine("It is recommend that you download the version of OmniSharp that runs on Mono using the following steps:");
31+
output.appendLine(" 1. If it's not already installed, download and install Mono (http://www.mono-project.com)");
32+
output.appendLine(" 2. Download and untar https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.9-alpha13/omnisharp-linux-mono.tar.gz");
33+
output.appendLine(" 3. In Visual Studio Code, select Preferences->User Settings to open settings.json.");
34+
output.appendLine(" 4. In settings.json, add a new setting: \"csharp.omnisharp\": \"/path/to/omnisharp/OmniSharp.exe\"");
35+
output.appendLine(" 5. Restart Visual Studio Code.");
36+
output.show();
37+
throw err;
38+
}
39+
2540
return downloadOmnisharp().then(_ => {
2641
return getOmnisharpLaunchFilePath();
2742
})
2843
});
2944
}
3045

31-
export default function launch(cwd: string, args: string[]): Promise<LaunchResult> {
46+
export default function launch(output: OutputChannel, cwd: string, args: string[]): Promise<LaunchResult> {
3247

3348
return new Promise<LaunchResult>((resolve, reject) => {
3449

3550
try {
36-
(isWindows ? launchWindows(cwd, args) : launchNix(cwd, args)).then(value => {
51+
(isWindows ? launchWindows(output, cwd, args) : launchNix(output, cwd, args)).then(value => {
3752

3853
// async error - when target not not ENEOT
3954
value.process.on('error', reject);
@@ -52,8 +67,8 @@ export default function launch(cwd: string, args: string[]): Promise<LaunchResul
5267
});
5368
}
5469

55-
function launchWindows(cwd: string, args: string[]): Promise<LaunchResult> {
56-
return installOmnisharpIfNeeded().then(command => {
70+
function launchWindows(output: OutputChannel, cwd: string, args: string[]): Promise<LaunchResult> {
71+
return installOmnisharpIfNeeded(output).then(command => {
5772

5873
args = args.slice(0);
5974
args.unshift(command);
@@ -77,9 +92,9 @@ function launchWindows(cwd: string, args: string[]): Promise<LaunchResult> {
7792
});
7893
}
7994

80-
function launchNix(cwd: string, args: string[]): Promise<LaunchResult>{
95+
function launchNix(output: OutputChannel, cwd: string, args: string[]): Promise<LaunchResult>{
8196

82-
return installOmnisharpIfNeeded().then(command => {
97+
return installOmnisharpIfNeeded(output).then(command => {
8398
let process = spawn(command, args, {
8499
detached: false,
85100
// env: details.env,

src/utils.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as child_process from 'child_process'
9+
10+
export enum SupportedPlatform {
11+
None,
12+
Windows,
13+
OSX,
14+
CentOS,
15+
Debian,
16+
RHEL,
17+
Ubuntu
18+
}
19+
20+
export function getSupportedPlatform() {
21+
if (process.platform === 'win32') {
22+
return SupportedPlatform.Windows;
23+
}
24+
else if (process.platform === 'darwin') {
25+
return SupportedPlatform.OSX;
26+
}
27+
else if (process.platform === 'linux') {
28+
// Get the text of /etc/*-release to discover which Linux distribution we're running on.
29+
let release = child_process.execSync('cat /etc/*-release').toString().toLowerCase();
30+
31+
if (release.indexOf('ubuntu') >= 0) {
32+
return SupportedPlatform.Ubuntu;
33+
}
34+
else if (release.indexOf('centos') >= 0) {
35+
return SupportedPlatform.CentOS;
36+
}
37+
else if (release.indexOf('rhel') >= 0) {
38+
return SupportedPlatform.RHEL;
39+
}
40+
else if (release.indexOf('debian') >= 0) {
41+
return SupportedPlatform.Debian;
42+
}
43+
}
44+
45+
return SupportedPlatform.None;
46+
}

0 commit comments

Comments
 (0)