@@ -11,6 +11,7 @@ import {workspace} from 'vscode';
1111import { satisfies } from 'semver' ;
1212import { join } from 'path' ;
1313import { getOmnisharpLaunchFilePath } from './omnisharpPath' ;
14+ import { downloadOmnisharp } from './omnisharpDownload' ;
1415
1516const isWindows = process . platform === 'win32' ;
1617
@@ -19,6 +20,14 @@ export interface LaunchResult {
1920 command : string ;
2021}
2122
23+ export function installOmnisharpIfNeeded ( ) : Promise < string > {
24+ return getOmnisharpLaunchFilePath ( ) . catch ( err => {
25+ return downloadOmnisharp ( ) . then ( _ => {
26+ return getOmnisharpLaunchFilePath ( ) ;
27+ } )
28+ } ) ;
29+ }
30+
2231export default function launch ( cwd : string , args : string [ ] ) : Promise < LaunchResult > {
2332
2433 return new Promise < LaunchResult > ( ( resolve , reject ) => {
@@ -44,7 +53,7 @@ export default function launch(cwd: string, args: string[]): Promise<LaunchResul
4453}
4554
4655function launchWindows ( cwd : string , args : string [ ] ) : Promise < LaunchResult > {
47- return getOmnisharpLaunchFilePath ( ) . then ( command => {
56+ return installOmnisharpIfNeeded ( ) . then ( command => {
4857
4958 args = args . slice ( 0 ) ;
5059 args . unshift ( command ) ;
@@ -69,18 +78,8 @@ function launchWindows(cwd: string, args: string[]): Promise<LaunchResult> {
6978}
7079
7180function launchNix ( cwd : string , args : string [ ] ) : Promise < LaunchResult > {
72-
73- return new Promise ( ( resolve , reject ) => {
74- hasMono ( '>=4.0.1' ) . then ( hasIt => {
75- if ( ! hasIt ) {
76- reject ( new Error ( 'Cannot start Omnisharp because Mono version >=4.0.1 is required. See http://go.microsoft.com/fwlink/?linkID=534832#_20001' ) ) ;
77- } else {
78- resolve ( ) ;
79- }
80- } ) ;
81- } ) . then ( _ => {
82- return getOmnisharpLaunchFilePath ( ) ;
83- } ) . then ( command => {
81+
82+ return installOmnisharpIfNeeded ( ) . then ( command => {
8483 let process = spawn ( command , args , {
8584 detached : false ,
8685 // env: details.env,
@@ -91,7 +90,30 @@ function launchNix(cwd: string, args: string[]): Promise<LaunchResult>{
9190 process,
9291 command
9392 } ;
94- } ) ;
93+ } ) ;
94+
95+ // return new Promise((resolve, reject) => {
96+ // hasMono('>=4.0.1').then(hasIt => {
97+ // if (!hasIt) {
98+ // reject(new Error('Cannot start Omnisharp because Mono version >=4.0.1 is required. See http://go.microsoft.com/fwlink/?linkID=534832#_20001'));
99+ // } else {
100+ // resolve();
101+ // }
102+ // });
103+ // }).then(_ => {
104+ // return installOmnisharpIfNeeded();
105+ // }).then(command => {
106+ // let process = spawn(command, args, {
107+ // detached: false,
108+ // // env: details.env,
109+ // cwd
110+ // });
111+
112+ // return {
113+ // process,
114+ // command
115+ // };
116+ // });
95117}
96118
97119const versionRegexp = / ( \d + \. \d + \. \d + ) / ;
0 commit comments