@@ -108,7 +108,7 @@ async function callAsync(
108
108
token . onCancellationRequested ( ( ) => {
109
109
logger . warn ( `User canceled the execution of '${ command } '` ) ;
110
110
} ) ;
111
- const newEnv = ( envAdd !== undefined ) ? Object . assign ( process . env , envAdd ) : process . env ;
111
+ const newEnv = envAdd ? Object . assign ( process . env , envAdd ) : process . env ;
112
112
// Need to set the encoding to 'utf8' in order to get back a string
113
113
// We execute the command in a shell for windows, to allow use .cmd or .bat scripts
114
114
const childProcess = child_process
@@ -117,7 +117,7 @@ async function callAsync(
117
117
args ,
118
118
{ encoding : 'utf8' , cwd : dir , shell : process . platform === 'win32' , env : newEnv } ,
119
119
( err , stdout , stderr ) => {
120
- if ( callback !== undefined ) {
120
+ if ( callback ) {
121
121
callback ( err , stdout , stderr , resolve , reject ) ;
122
122
} else {
123
123
if ( err ) {
@@ -208,7 +208,7 @@ export async function findHaskellLanguageServer(
208
208
) : Promise < string > {
209
209
logger . info ( 'Finding haskell-language-server' ) ;
210
210
211
- if ( workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string !== '' ) {
211
+ if ( workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ) {
212
212
return findServerExecutable ( context , logger , folder ) ;
213
213
}
214
214
@@ -218,7 +218,7 @@ export async function findHaskellLanguageServer(
218
218
fs . mkdirSync ( storagePath ) ;
219
219
}
220
220
221
- if ( manageHLS === null ) { // plugin needs initialization
221
+ if ( ! manageHLS ) { // plugin needs initialization
222
222
const promptMessage =
223
223
'How do you want the extension to manage/discover HLS?' ;
224
224
@@ -229,10 +229,10 @@ export async function findHaskellLanguageServer(
229
229
manageHLS = 'internal-ghcup' ;
230
230
} else if ( decision === 'PATH' ) {
231
231
manageHLS = 'PATH' ;
232
+ } else {
233
+ throw new Error ( `Internal error: unexpected decision ${ decision } ` ) ;
232
234
}
233
- if ( manageHLS !== null ) {
234
- workspace . getConfiguration ( 'haskell' ) . update ( 'manageHLS' , manageHLS , ConfigurationTarget . Global ) ;
235
- }
235
+ workspace . getConfiguration ( 'haskell' ) . update ( 'manageHLS' , manageHLS , ConfigurationTarget . Global ) ;
236
236
}
237
237
238
238
if ( manageHLS === 'PATH' || manageHLS === null ) {
@@ -244,7 +244,7 @@ export async function findHaskellLanguageServer(
244
244
// get a preliminary hls wrapper for finding project GHC version,
245
245
// later we may install a different HLS that supports the given GHC
246
246
let wrapper = await getLatestWrapperFromGHCup ( context , logger ) . then ( e =>
247
- ( e === null )
247
+ ( ! e )
248
248
? callGHCup ( context , logger ,
249
249
[ 'install' , 'hls' ] ,
250
250
'Installing latest HLS' ,
@@ -254,7 +254,7 @@ export async function findHaskellLanguageServer(
254
254
[ 'whereis' , 'hls' ] ,
255
255
undefined ,
256
256
false ,
257
- ( err , stdout , _stderr , resolve , _reject ) => { err ? resolve ( ' ') : resolve ( stdout ?. trim ( ) ) ; } )
257
+ ( err , stdout , _stderr , resolve , reject ) => { err ? reject ( 'Couldn\'t find latest HLS ') : resolve ( stdout ?. trim ( ) ) ; } )
258
258
)
259
259
: e
260
260
) ;
@@ -265,7 +265,7 @@ export async function findHaskellLanguageServer(
265
265
context ,
266
266
logger ,
267
267
workingDir ,
268
- ( wrapper === null ) ? undefined : wrapper
268
+ wrapper
269
269
) ;
270
270
271
271
// now install said version in an isolated symlink directory
@@ -309,9 +309,7 @@ async function callGHCup(
309
309
GHCUP_INSTALL_BASE_PREFIX : storagePath ,
310
310
} , callback ) ;
311
311
} else {
312
- const msg = `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ;
313
- window . showErrorMessage ( msg ) ;
314
- throw new Error ( msg ) ;
312
+ throw new Error ( `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ) ;
315
313
}
316
314
}
317
315
@@ -325,9 +323,9 @@ async function getLatestHLS(
325
323
326
324
// get project GHC version, but fallback to system ghc if necessary.
327
325
const projectGhc =
328
- wrapper === undefined
329
- ? await callAsync ( `ghc ${ exeExt } ` , [ '--numeric-version' ] , storagePath , logger , undefined , false )
330
- : await getProjectGHCVersion ( wrapper , workingDir , logger ) ;
326
+ wrapper
327
+ ? await getProjectGHCVersion ( wrapper , workingDir , logger )
328
+ : await callAsync ( `ghc ${ exeExt } ` , [ '--numeric-version' ] , storagePath , logger , undefined , false ) ;
331
329
const noMatchingHLS = `No HLS version was found for supporting GHC ${ projectGhc } .` ;
332
330
333
331
// first we get supported GHC versions from available HLS bindists (whether installed or not)
@@ -406,8 +404,8 @@ export async function getGHCup(context: ExtensionContext, logger: Logger): Promi
406
404
const localGHCup = [ 'ghcup' ] . find ( executableExists ) ;
407
405
408
406
if ( manageHLS === 'system-ghcup' ) {
409
- if ( localGHCup === undefined ) {
410
- return Promise . reject ( new MissingToolError ( 'ghcup' ) ) ;
407
+ if ( ! localGHCup ) {
408
+ throw new MissingToolError ( 'ghcup' ) ;
411
409
} else {
412
410
logger . info ( `found system ghcup at ${ localGHCup } ` ) ;
413
411
const args = [ 'upgrade' ] ;
@@ -435,8 +433,7 @@ export async function getGHCup(context: ExtensionContext, logger: Logger): Promi
435
433
. with ( 'freebsd' , ( _ ) => 'freebsd12' )
436
434
. otherwise ( ( _ ) => null ) ;
437
435
if ( plat === null ) {
438
- window . showErrorMessage ( `Couldn't find any pre-built ghcup binary for ${ process . platform } ` ) ;
439
- return undefined ;
436
+ throw new Error ( `Couldn't find any pre-built ghcup binary for ${ process . platform } ` ) ;
440
437
}
441
438
const arch = match ( process . arch )
442
439
. with ( 'arm' , ( _ ) => 'armv7' )
@@ -445,23 +442,20 @@ export async function getGHCup(context: ExtensionContext, logger: Logger): Promi
445
442
. with ( 'x64' , ( _ ) => 'x86_64' )
446
443
. otherwise ( ( _ ) => null ) ;
447
444
if ( arch === null ) {
448
- window . showErrorMessage ( `Couldn't find any pre-built ghcup binary for ${ process . arch } ` ) ;
449
- return undefined ;
445
+ throw new Error ( `Couldn't find any pre-built ghcup binary for ${ process . arch } ` ) ;
450
446
}
451
447
const dlUri = `https://downloads.haskell.org/~ghcup/${ arch } -${ plat } -ghcup${ exeExt } ` ;
452
448
const title = `Downloading ${ dlUri } ` ;
453
449
logger . info ( `Downloading ${ dlUri } ` ) ;
454
450
const downloaded = await downloadFile ( title , dlUri , ghcup ) ;
455
451
if ( ! downloaded ) {
456
- window . showErrorMessage ( `Couldn't download ${ dlUri } as ${ ghcup } ` ) ;
452
+ throw new Error ( `Couldn't download ${ dlUri } as ${ ghcup } ` ) ;
457
453
}
458
454
}
459
455
return ghcup ;
460
456
461
457
} else {
462
- const msg = `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ;
463
- window . showErrorMessage ( msg ) ;
464
- throw new Error ( msg ) ;
458
+ throw new Error ( `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ) ;
465
459
}
466
460
}
467
461
@@ -578,7 +572,7 @@ async function getHLSesFromGHCup(
578
572
579
573
580
574
const installed = hlsVersions . split ( / \r ? \n / ) . map ( e => e . split ( ' ' ) [ 1 ] ) ;
581
- if ( installed . length > 0 ) {
575
+ if ( installed ? .length ) {
582
576
const myMap = new Map < string , string [ ] > ( ) ;
583
577
installed . forEach ( hls => {
584
578
const ghcs = files . filter ( f => f . endsWith ( `~${ hls } ${ exeExt } ` ) && f . startsWith ( 'haskell-language-server-' ) )
@@ -611,8 +605,8 @@ async function getHLSesfromMetadata(
611
605
storagePath : string ,
612
606
logger : Logger
613
607
) : Promise < Map < string , string [ ] > | null > {
614
- const metadata = await getReleaseMetadata ( context , storagePath , logger ) ;
615
- if ( metadata === null ) {
608
+ const metadata = await getReleaseMetadata ( context , storagePath , logger ) . catch ( e => null ) ;
609
+ if ( ! metadata ) {
616
610
window . showErrorMessage ( 'Could not get release metadata' ) ;
617
611
return null ;
618
612
}
@@ -623,8 +617,7 @@ async function getHLSesfromMetadata(
623
617
. with ( 'freebsd' , ( _ ) => 'FreeBSD' )
624
618
. otherwise ( ( _ ) => null ) ;
625
619
if ( plat === null ) {
626
- window . showErrorMessage ( `Unknown platform ${ process . platform } ` ) ;
627
- return null ;
620
+ throw new Error ( `Unknown platform ${ process . platform } ` ) ;
628
621
}
629
622
const arch = match ( process . arch )
630
623
. with ( 'arm' , ( _ ) => 'A_ARM' )
@@ -633,8 +626,7 @@ async function getHLSesfromMetadata(
633
626
. with ( 'x64' , ( _ ) => 'A_64' )
634
627
. otherwise ( ( _ ) => null ) ;
635
628
if ( arch === null ) {
636
- window . showErrorMessage ( `Unknown architecture ${ process . arch } ` ) ;
637
- return null ;
629
+ throw new Error ( `Unknown architecture ${ process . arch } ` ) ;
638
630
}
639
631
640
632
const map : ReleaseMetadata = new Map ( Object . entries ( metadata ) ) ;
0 commit comments