@@ -3,6 +3,7 @@ import * as fs from 'fs';
3
3
import { stat } from 'fs/promises' ;
4
4
import * as https from 'https' ;
5
5
import * as path from 'path' ;
6
+ import * as os from 'os' ;
6
7
import { match } from 'ts-pattern' ;
7
8
import { promisify } from 'util' ;
8
9
import { ConfigurationTarget , ExtensionContext , ProgressLocation , window , workspace , WorkspaceFolder } from 'vscode' ;
@@ -571,7 +572,40 @@ export async function findGHCup(_context: ExtensionContext, logger: Logger, fold
571
572
} else {
572
573
const localGHCup = [ 'ghcup' ] . find ( executableExists ) ;
573
574
if ( ! localGHCup ) {
574
- throw new MissingToolError ( 'ghcup' ) ;
575
+ logger . info ( `probing for GHCup binary` ) ;
576
+ const ghcupExe = match ( process . platform )
577
+ . with ( 'win32' , ( ) => {
578
+ const ghcupPrefix = process . env . GHCUP_INSTALL_BASE_PREFIX ;
579
+ if ( ghcupPrefix ) {
580
+ return path . join ( ghcupPrefix , 'ghcup' , 'bin' , 'ghcup.exe' ) ;
581
+ } else {
582
+ return path . join ( 'C:\\' , 'ghcup' , 'bin' , 'ghcup.exe' ) ;
583
+ }
584
+ } )
585
+ . otherwise ( ( ) => {
586
+ const useXDG = process . env . GHCUP_USE_XDG_DIRS ;
587
+ if ( useXDG ) {
588
+ const xdgBin = process . env . XDG_BIN_HOME ;
589
+ if ( xdgBin ) {
590
+ return path . join ( xdgBin , 'ghcup' ) ;
591
+ } else {
592
+ return path . join ( os . homedir ( ) , '.local' , 'bin' , 'ghcup' ) ;
593
+ }
594
+ } else {
595
+ const ghcupPrefix = process . env . GHCUP_INSTALL_BASE_PREFIX ;
596
+ if ( ghcupPrefix ) {
597
+ return path . join ( ghcupPrefix , '.ghcup' , 'bin' , 'ghcup' ) ;
598
+ } else {
599
+ return path . join ( os . homedir ( ) , '.ghcup' , 'bin' , 'ghcup' ) ;
600
+ }
601
+ }
602
+ } ) ;
603
+ if ( ghcupExe != null && executableExists ( ghcupExe ) ) {
604
+ return ghcupExe ;
605
+ } else {
606
+ logger . warn ( `ghcup at ${ ghcupExe } does not exist` ) ;
607
+ throw new MissingToolError ( 'ghcup' ) ;
608
+ }
575
609
} else {
576
610
logger . info ( `found ghcup at ${ localGHCup } ` ) ;
577
611
return localGHCup ;
0 commit comments