Skip to content

Commit a193348

Browse files
Merge pull request #585 from DustinCampbell/dual-omnisharp
Support using dual OmniSharp servers to improve handling of .csproj and project.json
2 parents 2801e0f + 735f90a commit a193348

13 files changed

+674
-498
lines changed

gulpfile.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ const vsce = require('vsce');
1515
const debugUtil = require('./out/coreclr-debug/util.js');
1616
const debugInstall = require('./out/coreclr-debug/install.js');
1717
const fs_extra = require('fs-extra-promise');
18-
const omnisharpDownload = require('./out/omnisharp/download');
18+
const omnisharp = require('./out/omnisharp/omnisharp');
19+
const download = require('./out/omnisharp/download');
20+
const platform = require('./out/platform');
1921
const child_process = require('child_process');
2022

21-
const OmniSharpVersion = omnisharpDownload.OmniSharpVersion;
23+
const Flavor = omnisharp.Flavor;
24+
const Platform = platform.Platform;
2225

2326
/// used in offline packaging run so does not clean .vsix
2427
function clean() {
@@ -31,9 +34,9 @@ gulp.task('clean', ['omnisharp:clean', 'debugger:clean', 'package:clean'], () =
3134
});
3235

3336
/// Omnisharp Tasks
34-
function installOmnisharp(omnisharpAssetName) {
35-
const logFunction = (message) => { console.log(message); };
36-
return omnisharpDownload.downloadOmnisharp(logFunction, omnisharpAssetName);
37+
function installOmnisharp(flavor, platform) {
38+
const logger = (message) => { console.log(message); };
39+
return download.go(flavor, platform, logger);
3740
}
3841

3942
function cleanOmnisharp() {
@@ -45,8 +48,10 @@ gulp.task('omnisharp:clean', () => {
4548
});
4649

4750
gulp.task('omnisharp:install', ['omnisharp:clean'], () => {
48-
var asset = gulpUtil.env.asset || omnisharpDownload.getOmnisharpAssetName();
49-
return installOmnisharp(asset);
51+
const flavor = gulpUtil.env.flavor || Flavor.CoreCLR;
52+
const platform = gulpUtil.env.platform || platform.getCurrentPlatform();
53+
54+
return installOmnisharp(flavor, platform);
5055
});
5156

5257
/// Debugger Tasks
@@ -97,11 +102,11 @@ function doPackageSync(packageName) {
97102
}
98103
}
99104

100-
function doOfflinePackage(runtimeId, omnisharpAsset, packageName) {
105+
function doOfflinePackage(runtimeId, flavor, platform, packageName) {
101106
return clean().then(() => {
102107
return installDebugger(runtimeId);
103108
}).then(() => {
104-
return installOmnisharp(omnisharpAsset);
109+
return installOmnisharp(flavor, platform);
105110
}).then(() => {
106111
doPackageSync(packageName + '-' + runtimeId + '.vsix');
107112
});
@@ -122,21 +127,21 @@ gulp.task('package:offline', ['clean'], () => {
122127
var packageName = name + '.' + version;
123128

124129
var packages = [];
125-
packages.push({rid: 'win7-x64', omni: `omnisharp-${OmniSharpVersion}-win-x64-net451.zip`});
126-
packages.push({rid: 'osx.10.11-x64', omni: `omnisharp-${OmniSharpVersion}-osx-x64-netcoreapp1.0.tar.gz`});
127-
packages.push({rid: 'centos.7-x64', omni: `omnisharp-${OmniSharpVersion}-centos-x64-netcoreapp1.0.tar.gz`});
128-
packages.push({rid: 'debian.8-x64', omni: `omnisharp-${OmniSharpVersion}-debian-x64-netcoreapp1.0.tar.gz`});
129-
packages.push({rid: 'fedora.23-x64', omni: `omnisharp-${OmniSharpVersion}-fedora-x64-netcoreapp1.0.tar.gz`});
130-
packages.push({rid: 'opensuse.13.2-x64', omni: `omnisharp-${OmniSharpVersion}-opensuse-x64-netcoreapp1.0.tar.gz`});
131-
packages.push({rid: 'rhel.7.2-x64', omni: `omnisharp-${OmniSharpVersion}-rhel-x64-netcoreapp1.0.tar.gz`});
132-
packages.push({rid: 'ubuntu.14.04-x64', omni: `omnisharp-${OmniSharpVersion}-ubuntu14-x64-netcoreapp1.0.tar.gz`});
133-
packages.push({rid: 'ubuntu.16.04-x64', omni: `omnisharp-${OmniSharpVersion}-ubuntu16-x64-netcoreapp1.0.tar.gz`});
130+
packages.push({rid: 'win7-x64', flavor: Flavor.Desktop, platform: Platform.Windows});
131+
packages.push({rid: 'osx.10.11-x64', flavor: Flavor.CoreCLR, platform: Platform.OSX});
132+
packages.push({rid: 'centos.7-x64', flavor: Flavor.CoreCLR, platform: Platform.CentOS});
133+
packages.push({rid: 'debian.8-x64', flavor: Flavor.CoreCLR, platform: Platform.Debian});
134+
packages.push({rid: 'fedora.23-x64', flavor: Flavor.CoreCLR, platform: Platform.Fedora});
135+
packages.push({rid: 'opensuse.13.2-x64', flavor: Flavor.CoreCLR, platform: Platform.OpenSUSE});
136+
packages.push({rid: 'rhel.7.2-x64', flavor: Flavor.CoreCLR, platform: Platform.RHEL});
137+
packages.push({rid: 'ubuntu.14.04-x64', flavor: Flavor.CoreCLR, platform: Platform.Ubuntu14});
138+
packages.push({rid: 'ubuntu.16.04-x64', flavor: Flavor.CoreCLR, platform: Platform.Ubuntu16});
134139

135140
var promise = Promise.resolve();
136141

137-
packages.forEach(pair => {
142+
packages.forEach(data => {
138143
promise = promise.then(() => {
139-
return doOfflinePackage(pair.rid, pair.omni, packageName);
144+
return doOfflinePackage(data.rid, data.flavor, data.platform, packageName);
140145
})
141146
});
142147

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.3.0",
4+
"version": "1.3.0-beta1",
55
"description": "C# for Visual Studio Code (powered by OmniSharp).",
66
"displayName": "C#",
77
"author": "Microsoft Corporation",

src/coreclr-debug/activate.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as path from 'path';
1111
import TelemetryReporter from 'vscode-extension-telemetry';
1212
import { CoreClrDebugUtil } from './util';
1313
import * as debugInstall from './install';
14-
import { SupportedPlatform, getSupportedPlatform } from './../utils';
14+
import { Platform, getCurrentPlatform } from './../platform';
1515

1616
let _reporter: TelemetryReporter = null;
1717
let _channel: vscode.OutputChannel = null;
@@ -114,21 +114,21 @@ function getPlatformRuntimeId() : string {
114114
case 'darwin':
115115
return 'osx.10.11-x64';
116116
case 'linux':
117-
switch (getSupportedPlatform())
117+
switch (getCurrentPlatform())
118118
{
119-
case SupportedPlatform.CentOS:
119+
case Platform.CentOS:
120120
return 'centos.7-x64';
121-
case SupportedPlatform.Fedora:
121+
case Platform.Fedora:
122122
return 'fedora.23-x64';
123-
case SupportedPlatform.OpenSUSE:
123+
case Platform.OpenSUSE:
124124
return 'opensuse.13.2-x64';
125-
case SupportedPlatform.RHEL:
125+
case Platform.RHEL:
126126
return 'rhel.7-x64';
127-
case SupportedPlatform.Debian:
127+
case Platform.Debian:
128128
return 'debian.8-x64';
129-
case SupportedPlatform.Ubuntu14:
129+
case Platform.Ubuntu14:
130130
return 'ubuntu.14.04-x64';
131-
case SupportedPlatform.Ubuntu16:
131+
case Platform.Ubuntu16:
132132
return 'ubuntu.16.04-x64';
133133
default:
134134
throw Error('Error: Unsupported linux platform');

src/features/commands.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {OmnisharpServer} from '../omnisharp/server';
99
import * as serverUtils from '../omnisharp/utils';
10-
import findLaunchTargets from '../omnisharp/launchTargetFinder';
10+
import {findLaunchTargets} from '../omnisharp/launcher';
1111
import * as cp from 'child_process';
1212
import * as fs from 'fs-extra-promise';
1313
import * as path from 'path';
@@ -47,7 +47,7 @@ function pickProjectAndStart(server: OmnisharpServer) {
4747
let currentPath = server.getSolutionPathOrFolder();
4848
if (currentPath) {
4949
for (let target of targets) {
50-
if (target.target.fsPath === currentPath) {
50+
if (target.target === currentPath) {
5151
target.label = `\u2713 ${target.label}`;
5252
}
5353
}
@@ -56,9 +56,9 @@ function pickProjectAndStart(server: OmnisharpServer) {
5656
return vscode.window.showQuickPick(targets, {
5757
matchOnDescription: true,
5858
placeHolder: `Select 1 of ${targets.length} projects`
59-
}).then(target => {
60-
if (target) {
61-
return server.restart(target.target.fsPath);
59+
}).then(launchTarget => {
60+
if (launchTarget) {
61+
return server.restart(launchTarget);
6262
}
6363
});
6464
});

src/features/status.ts

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
9090
render();
9191
}));
9292

93+
disposables.push(server.onBeforeServerInstall(() => {
94+
defaultStatus.text = '$(flame) Installing OmniSharp...';
95+
defaultStatus.command = 'o.showOutput';
96+
defaultStatus.color = '';
97+
render();
98+
}));
99+
93100
disposables.push(server.onBeforeServerStart(path => {
94101
defaultStatus.text = '$(flame) Starting...';
95102
defaultStatus.command = 'o.showOutput';

src/omnisharp/download.ts

+72-37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/*
7+
* Note that this file intentionally does not import 'vscode' as the code within is intended
8+
* to be usable outside of VS Code.
9+
*/
10+
611
'use strict';
712

813
import * as fs from 'fs-extra-promise';
@@ -11,46 +16,70 @@ import * as https from 'https';
1116
import * as stream from 'stream';
1217
import * as tmp from 'tmp';
1318
import {parse} from 'url';
14-
import {SupportedPlatform, getSupportedPlatform} from '../utils';
19+
import {Flavor, getInstallDirectory} from './omnisharp';
20+
import {Platform} from '../platform';
1521
import {getProxyAgent} from '../proxy';
1622

1723
const decompress = require('decompress');
1824

1925
const BaseDownloadUrl = 'https://omnisharpdownload.blob.core.windows.net/ext';
20-
const DefaultInstallLocation = path.join(__dirname, '../.omnisharp');
21-
export const OmniSharpVersion = '1.9-beta11';
26+
const OmniSharpVersion = '1.9-beta12';
2227

2328
tmp.setGracefulCleanup();
2429

25-
export function getOmnisharpAssetName(): string {
26-
switch (getSupportedPlatform()) {
27-
case SupportedPlatform.Windows:
28-
return `omnisharp-${OmniSharpVersion}-win-x64-net451.zip`;
29-
case SupportedPlatform.OSX:
30-
return `omnisharp-${OmniSharpVersion}-osx-x64-netcoreapp1.0.tar.gz`;
31-
case SupportedPlatform.CentOS:
32-
return `omnisharp-${OmniSharpVersion}-centos-x64-netcoreapp1.0.tar.gz`;
33-
case SupportedPlatform.Debian:
34-
return `omnisharp-${OmniSharpVersion}-debian-x64-netcoreapp1.0.tar.gz`;
35-
case SupportedPlatform.Fedora:
36-
return `omnisharp-${OmniSharpVersion}-fedora-x64-netcoreapp1.0.tar.gz`;
37-
case SupportedPlatform.OpenSUSE:
38-
return `omnisharp-${OmniSharpVersion}-opensuse-x64-netcoreapp1.0.tar.gz`;
39-
case SupportedPlatform.RHEL:
40-
return `omnisharp-${OmniSharpVersion}-rhel-x64-netcoreapp1.0.tar.gz`;
41-
case SupportedPlatform.Ubuntu14:
42-
return `omnisharp-${OmniSharpVersion}-ubuntu14-x64-netcoreapp1.0.tar.gz`;
43-
case SupportedPlatform.Ubuntu16:
44-
return `omnisharp-${OmniSharpVersion}-ubuntu16-x64-netcoreapp1.0.tar.gz`;
45-
46-
default:
47-
if (process.platform === 'linux') {
48-
throw new Error(`Unsupported linux distribution`);
49-
}
50-
else {
51-
throw new Error(`Unsupported platform: ${process.platform}`);
52-
}
30+
function getDownloadFileName(flavor: Flavor, platform: Platform): string {
31+
let fileName = `omnisharp-${OmniSharpVersion}-`;
32+
33+
if (flavor === Flavor.CoreCLR) {
34+
switch (platform) {
35+
case Platform.Windows:
36+
fileName += 'win-x64-netcoreapp1.0.zip';
37+
break;
38+
case Platform.OSX:
39+
fileName += 'osx-x64-netcoreapp1.0.tar.gz';
40+
break;
41+
case Platform.CentOS:
42+
fileName += 'centos-x64-netcoreapp1.0.tar.gz';
43+
break;
44+
case Platform.Debian:
45+
fileName += 'debian-x64-netcoreapp1.0.tar.gz';
46+
break;
47+
case Platform.Fedora:
48+
fileName += 'fedora-x64-netcoreapp1.0.tar.gz';
49+
break;
50+
case Platform.OpenSUSE:
51+
fileName += 'opensuse-x64-netcoreapp1.0.tar.gz';
52+
break;
53+
case Platform.RHEL:
54+
fileName += 'rhel-x64-netcoreapp1.0.tar.gz';
55+
break;
56+
case Platform.Ubuntu14:
57+
fileName += 'ubuntu14-x64-netcoreapp1.0.tar.gz';
58+
break;
59+
case Platform.Ubuntu16:
60+
fileName += 'ubuntu16-x64-netcoreapp1.0.tar.gz';
61+
break;
62+
63+
default:
64+
if (process.platform === 'linux') {
65+
throw new Error(`Unsupported linux distribution`);
66+
}
67+
else {
68+
throw new Error(`Unsupported platform: ${process.platform}`);
69+
}
70+
}
71+
}
72+
else if (flavor === Flavor.Desktop) {
73+
fileName += 'win-x64-net451.zip';
5374
}
75+
else if (flavor === Flavor.Mono) {
76+
fileName += 'mono.tar.gz';
77+
}
78+
else {
79+
throw new Error(`Unexpected OmniSharp flavor specified: ${flavor}`);
80+
}
81+
82+
return fileName;
5483
}
5584

5685
function download(urlString: string, proxy?: string, strictSSL?: boolean): Promise<stream.Readable> {
@@ -79,14 +108,20 @@ function download(urlString: string, proxy?: string, strictSSL?: boolean): Promi
79108
});
80109
}
81110

82-
export function downloadOmnisharp(log: (message: string) => void, omnisharpAssetName?: string, proxy?: string, strictSSL?: boolean) {
111+
export function go(flavor: Flavor, platform: Platform, log?: (message: string) => void, proxy?: string, strictSSL?: boolean) {
83112
return new Promise<boolean>((resolve, reject) => {
84-
log(`[INFO] Installing to ${DefaultInstallLocation}`);
113+
log = log || (_ => { });
114+
115+
log(`Flavor: ${flavor}, Platform: ${platform}`);
116+
117+
const fileName = getDownloadFileName(flavor, platform);
118+
const installDirectory = getInstallDirectory(flavor);
119+
120+
log(`[INFO] Installing OmniSharp to ${installDirectory}`);
85121

86-
const assetName = omnisharpAssetName || getOmnisharpAssetName();
87-
const urlString = `${BaseDownloadUrl}/${assetName}`;
122+
const urlString = `${BaseDownloadUrl}/${fileName}`;
88123

89-
log(`[INFO] Attempting to download ${assetName}...`);
124+
log(`[INFO] Attempting to download ${fileName}...`);
90125

91126
return download(urlString, proxy, strictSSL)
92127
.then(inStream => {
@@ -108,7 +143,7 @@ export function downloadOmnisharp(log: (message: string) => void, omnisharpAsset
108143
log(`[INFO] Download complete!`);
109144
log(`[INFO] Decompressing...`);
110145

111-
return decompress(tmpPath, DefaultInstallLocation)
146+
return decompress(tmpPath, installDirectory)
112147
.then(files => {
113148
log(`[INFO] Done! ${files.length} files unpacked.`);
114149
return resolve(true);

0 commit comments

Comments
 (0)