Skip to content

Commit

Permalink
Provide actionable steps to the user when an OmniSharp server specifi…
Browse files Browse the repository at this point in the history
…c to the current Linux distribution can't be found
  • Loading branch information
DustinCampbell committed Apr 14, 2016
1 parent 1b5c407 commit 0e2232f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/omnisharpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export abstract class OmnisharpServer {
this._fireEvent(Events.StdOut, `[INFO] Starting OmniSharp at '${solutionPath}'...\n`);
this._fireEvent(Events.BeforeServerStart, solutionPath);

return omnisharpLauncher(cwd, argv).then(value => {
return omnisharpLauncher(this._channel, cwd, argv).then(value => {
this._serverProcess = value.process;
this._requestDelays = {};
this._fireEvent(Events.StdOut, `[INFO] Started OmniSharp from '${value.command}' with process id ${value.process.pid}...\n`);
Expand Down
30 changes: 22 additions & 8 deletions src/omnisharpServerLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import {exists as fileExists} from 'fs';
import {spawn, ChildProcess} from 'child_process';
import {workspace} from 'vscode';
import {workspace, OutputChannel} from 'vscode';
import {satisfies} from 'semver';
import {join} from 'path';
import {getOmnisharpLaunchFilePath} from './omnisharpPath';
import {downloadOmnisharp} from './omnisharpDownload';
import {SupportedPlatform, getSupportedPlatform} from './utils';

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

Expand All @@ -20,20 +21,33 @@ export interface LaunchResult {
command: string;
}

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

return downloadOmnisharp().then(_ => {
return getOmnisharpLaunchFilePath();
})
});
}

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

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

try {
(isWindows ? launchWindows(cwd, args) : launchNix(cwd, args)).then(value => {
(isWindows ? launchWindows(output, cwd, args) : launchNix(output, cwd, args)).then(value => {

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

function launchWindows(cwd: string, args: string[]): Promise<LaunchResult> {
return installOmnisharpIfNeeded().then(command => {
function launchWindows(output: OutputChannel, cwd: string, args: string[]): Promise<LaunchResult> {
return installOmnisharpIfNeeded(output).then(command => {

args = args.slice(0);
args.unshift(command);
Expand All @@ -77,9 +91,9 @@ function launchWindows(cwd: string, args: string[]): Promise<LaunchResult> {
});
}

function launchNix(cwd: string, args: string[]): Promise<LaunchResult>{
function launchNix(output: OutputChannel, cwd: string, args: string[]): Promise<LaunchResult>{

return installOmnisharpIfNeeded().then(command => {
return installOmnisharpIfNeeded(output).then(command => {
let process = spawn(command, args, {
detached: false,
// env: details.env,
Expand Down

0 comments on commit 0e2232f

Please sign in to comment.