@@ -3,6 +3,7 @@ import * as fs from 'fs';
33import { stat } from 'fs/promises' ;
44import * as https from 'https' ;
55import * as path from 'path' ;
6+ import * as os from 'os' ;
67import { match } from 'ts-pattern' ;
78import { promisify } from 'util' ;
89import { ConfigurationTarget , ExtensionContext , ProgressLocation , window , workspace , WorkspaceFolder } from 'vscode' ;
@@ -571,7 +572,40 @@ export async function findGHCup(_context: ExtensionContext, logger: Logger, fold
571572 } else {
572573 const localGHCup = [ 'ghcup' ] . find ( executableExists ) ;
573574 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+ }
575609 } else {
576610 logger . info ( `found ghcup at ${ localGHCup } ` ) ;
577611 return localGHCup ;
0 commit comments