@@ -183,7 +183,6 @@ export async function downloadHaskellLanguageServer(
183
183
wrapper = downloadedWrapper ;
184
184
}
185
185
186
- const ghcup = path . join ( storagePath , `ghcup${ exeExt } ` ) ;
187
186
const updateBehaviour = workspace . getConfiguration ( 'haskell' ) . get ( 'updateBehavior' ) as UpdateBehaviour ;
188
187
const [ installableHls , latestHlsVersion , projectGhc ] = await getLatestSuitableHLS (
189
188
context ,
@@ -208,18 +207,14 @@ export async function downloadHaskellLanguageServer(
208
207
throw new Error ( 'No version of HLS installed or found and installation was denied, giving up...' ) ;
209
208
}
210
209
}
211
- await callAsync (
212
- ghcup ,
213
- [ '--no-verbose' , 'install' , 'hls' , installableHls ] ,
214
- storagePath ,
210
+ await callGHCup (
211
+ context ,
215
212
logger ,
213
+ [ 'install' , 'hls' , installableHls ] ,
216
214
`Installing HLS ${ installableHls } ` ,
217
215
true ,
218
- { GHCUP_INSTALL_BASE_PREFIX : storagePath }
219
216
) ;
220
- await callAsync ( ghcup , [ '--no-verbose' , 'set' , 'hls' , installableHls ] , storagePath , logger , undefined , false , {
221
- GHCUP_INSTALL_BASE_PREFIX : storagePath ,
222
- } ) ;
217
+ await callGHCup ( context , logger , [ 'set' , 'hls' , installableHls ] , undefined , false ) ;
223
218
return downloadedWrapper ;
224
219
} else {
225
220
// version of active hls wrapper
@@ -273,39 +268,46 @@ export async function downloadHaskellLanguageServer(
273
268
// isolated symlinked dir with only the given HLS in place, so
274
269
// this works for installing and setting
275
270
const symHLSPath = path . join ( storagePath , 'hls' , installableHls ) ;
276
- await callAsync (
277
- ghcup ,
278
- [ '--no-verbose' , 'run' , '--hls' , installableHls , '-b' , symHLSPath , '-i' ] ,
279
- storagePath ,
280
- logger ,
271
+ await callGHCup ( context , logger ,
272
+ [ 'run' , '--hls' , installableHls , '-b' , symHLSPath , '-i' ] ,
281
273
needInstall ? `Installing HLS ${ installableHls } ` : undefined ,
282
- needInstall ,
283
- { GHCUP_INSTALL_BASE_PREFIX : storagePath }
274
+ needInstall
284
275
) ;
285
276
return path . join ( symHLSPath , `haskell-language-server-wrapper${ exeExt } ` ) ;
286
277
}
287
278
return wrapper ;
288
279
}
289
280
}
290
281
282
+ async function callGHCup (
283
+ context : ExtensionContext ,
284
+ logger : Logger ,
285
+ args : string [ ] ,
286
+ title ?: string ,
287
+ cancellable ?: boolean
288
+ ) : Promise < string > {
289
+ const storagePath : string = await getStoragePath ( context ) ;
290
+ const ghcup = path . join ( storagePath , `ghcup${ exeExt } ` ) ;
291
+ return await callAsync ( ghcup , [ '--no-verbose' ] . concat ( args ) , storagePath , logger , title , cancellable , {
292
+ GHCUP_INSTALL_BASE_PREFIX : storagePath ,
293
+ } ) ;
294
+ }
295
+
291
296
async function getLatestSuitableHLS (
292
297
context : ExtensionContext ,
293
298
logger : Logger ,
294
299
workingDir : string ,
295
300
wrapper ?: string
296
301
) : Promise < [ string , string , string | null ] > {
297
302
const storagePath : string = await getStoragePath ( context ) ;
298
- const ghcup = path . join ( storagePath , `ghcup${ exeExt } ` ) ;
299
303
300
304
// get latest hls version
301
- const hlsVersions = await callAsync (
302
- ghcup ,
303
- [ '--no-verbose' , 'list' , '-t' , 'hls' , '-c' , 'available' , '-r' ] ,
304
- storagePath ,
305
- logger ,
305
+ const hlsVersions = await callGHCup (
306
+ context ,
307
+ logger ,
308
+ [ 'list' , '-t' , 'hls' , '-c' , 'available' , '-r' ] ,
306
309
undefined ,
307
310
false ,
308
- { GHCUP_INSTALL_BASE_PREFIX : storagePath }
309
311
) ;
310
312
const latestHlsVersion = hlsVersions . split ( / \r ? \n / ) . pop ( ) ! . split ( ' ' ) [ 1 ] ;
311
313
@@ -401,8 +403,8 @@ export async function downloadGHCup(context: ExtensionContext, logger: Logger):
401
403
// ghcup exists, just upgrade
402
404
if ( fs . existsSync ( ghcup ) ) {
403
405
logger . info ( 'ghcup already installed, trying to upgrade' ) ;
404
- const args = [ '--no-verbose' , ' upgrade', '-i' ] ;
405
- await callAsync ( ghcup , args , storagePath , logger , undefined , false , { GHCUP_INSTALL_BASE_PREFIX : storagePath } ) ;
406
+ const args = [ 'upgrade' , '-i' ] ;
407
+ await callGHCup ( context , logger , args , undefined , false ) ;
406
408
} else {
407
409
// needs to download ghcup
408
410
const plat = match ( process . platform )
0 commit comments