@@ -277,36 +277,35 @@ export async function findHaskellLanguageServer(
277
277
if ( promptBeforeDownloads ) {
278
278
const hlsInstalled = latestHLS
279
279
? await toolInstalled ( context , logger , 'hls' , latestHLS )
280
- : new InstalledTool ( 'hls' ) ;
280
+ : undefined ;
281
281
const cabalInstalled = latestCabal
282
282
? await toolInstalled ( context , logger , 'cabal' , latestCabal )
283
- : new InstalledTool ( 'cabal' ) ;
283
+ : undefined ;
284
284
const stackInstalled = latestStack
285
285
? await toolInstalled ( context , logger , 'stack' , latestStack )
286
- : new InstalledTool ( 'stack' ) ;
287
- const ghcInstalled = ( await executableExists ( 'ghc' ) )
288
- ? new InstalledTool ( 'ghc' )
289
- // if recGHC is null, that means user disabled automatic handling,
290
- // so we pretend it's installed in order to ignore it
291
- : ( recGHC !== null ? await toolInstalled ( context , logger , 'ghc' , recGHC ) : new InstalledTool ( 'ghc' ) ) ;
292
- const toInstall = [ hlsInstalled , cabalInstalled , stackInstalled , ghcInstalled ]
293
- . filter ( ( tool ) => ! tool . installed )
294
- . map ( ( tool ) => tool . nameWithVersion ) ;
286
+ : undefined ;
287
+ const ghcInstalled = executableExists ( 'ghc' )
288
+ ? new InstalledTool ( 'ghc' , await callAsync ( `ghc${ exeExt } ` , [ '--numeric-version' ] , logger , undefined , undefined , false ) )
289
+ // if recGHC is null, that means user disabled automatic handling,
290
+ // so we pretend it's installed in order to ignore it
291
+ : ( recGHC !== null ? await toolInstalled ( context , logger , 'ghc' , recGHC ) : undefined ) ;
292
+ const toInstall : InstalledTool [ ] = [ hlsInstalled , cabalInstalled , stackInstalled , ghcInstalled ]
293
+ . filter ( ( tool ) => tool && ! tool . installed ) as InstalledTool [ ] ;
295
294
if ( toInstall . length > 0 ) {
296
295
const decision = await window . showInformationMessage (
297
- `Need to download ${ toInstall . join ( ', ' ) } , continue?` ,
296
+ `Need to download ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } , continue?` ,
298
297
'Yes' ,
299
298
'No' ,
300
299
"Yes, don't ask again"
301
300
) ;
302
301
if ( decision === 'Yes' ) {
303
- logger . info ( `User accepted download for ${ toInstall . join ( ', ' ) } .` ) ;
302
+ logger . info ( `User accepted download for ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } .` ) ;
304
303
} else if ( decision === "Yes, don't ask again" ) {
305
- logger . info ( `User accepted download for ${ toInstall . join ( ', ' ) } and won't be asked again.` ) ;
304
+ logger . info ( `User accepted download for ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ) ;
306
305
workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
307
306
} else {
308
- [ hlsInstalled , cabalInstalled , stackInstalled , ghcInstalled ] . forEach ( ( tool ) => {
309
- if ( ! tool . installed ) {
307
+ toInstall . forEach ( ( tool ) => {
308
+ if ( tool !== undefined && ! tool . installed ) {
310
309
if ( tool . name === 'hls' ) {
311
310
throw new MissingToolError ( 'hls' ) ;
312
311
} else if ( tool . name === 'cabal' ) {
@@ -357,28 +356,27 @@ export async function findHaskellLanguageServer(
357
356
if ( promptBeforeDownloads ) {
358
357
const hlsInstalled = projectHls
359
358
? await toolInstalled ( context , logger , 'hls' , projectHls )
360
- : new InstalledTool ( 'hls' ) ;
359
+ : undefined ;
361
360
const ghcInstalled = projectGhc
362
361
? await toolInstalled ( context , logger , 'ghc' , projectGhc )
363
- : new InstalledTool ( 'ghc' ) ;
364
- const toInstall = [ hlsInstalled , ghcInstalled ]
365
- . filter ( ( tool ) => ! tool . installed )
366
- . map ( ( tool ) => tool . nameWithVersion ) ;
362
+ : undefined ;
363
+ const toInstall : InstalledTool [ ] = [ hlsInstalled , ghcInstalled ]
364
+ . filter ( ( tool ) => tool && ! tool . installed ) as InstalledTool [ ] ;
367
365
if ( toInstall . length > 0 ) {
368
366
const decision = await window . showInformationMessage (
369
- `Need to download ${ toInstall . join ( ', ' ) } , continue?` ,
367
+ `Need to download ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } , continue?` ,
370
368
{ modal : true } ,
371
369
'Yes' ,
372
370
'No' ,
373
371
"Yes, don't ask again"
374
372
) ;
375
373
if ( decision === 'Yes' ) {
376
- logger . info ( `User accepted download for ${ toInstall . join ( ', ' ) } .` ) ;
374
+ logger . info ( `User accepted download for ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } .` ) ;
377
375
} else if ( decision === "Yes, don't ask again" ) {
378
- logger . info ( `User accepted download for ${ toInstall . join ( ', ' ) } and won't be asked again.` ) ;
376
+ logger . info ( `User accepted download for ${ toInstall . map ( t => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ) ;
379
377
workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
380
378
} else {
381
- [ hlsInstalled , ghcInstalled ] . forEach ( ( tool ) => {
379
+ toInstall . forEach ( ( tool ) => {
382
380
if ( ! tool . installed ) {
383
381
if ( tool . name === 'hls' ) {
384
382
throw new MissingToolError ( 'hls' ) ;
@@ -403,7 +401,7 @@ export async function findHaskellLanguageServer(
403
401
...( projectGhc ? [ '--ghc' , projectGhc ] : [ ] ) ,
404
402
'--install' ,
405
403
] ,
406
- `Installing project specific toolchain: HLS- ${ projectHls } , GHC- ${ projectGhc } , cabal- ${ latestCabal } , stack-${ latestStack } ` ,
404
+ `Installing project specific toolchain: ${ [ [ 'hls' , projectHls ] , [ ' GHC' , projectGhc ] , [ ' cabal' , latestCabal ] , [ ' stack' , latestStack ] ] . filter ( t => t [ 1 ] ) . map ( t => ` ${ t [ 0 ] } -${ t [ 1 ] } ` ) . join ( ', ' ) } ` ,
407
405
true
408
406
) ;
409
407
0 commit comments