@@ -260,10 +260,10 @@ export async function findHaskellLanguageServer(
260260 latestHLS = await getLatestToolFromGHCup ( context , logger , 'hls' ) ;
261261 }
262262 if ( latestCabal === undefined ) {
263- latestCabal = await getLatestToolFromGHCup ( context , logger , 'cabal' ) ;
263+ latestCabal = await getSetOrLatestToolFromGHCup ( context , logger , 'cabal' ) ;
264264 }
265265 if ( latestStack === undefined ) {
266- latestStack = await getLatestToolFromGHCup ( context , logger , 'stack' ) ;
266+ latestStack = await getSetOrLatestToolFromGHCup ( context , logger , 'stack' ) ;
267267 }
268268 if ( recGHC === undefined ) {
269269 recGHC = ! executableExists ( 'ghc' )
@@ -630,6 +630,25 @@ export async function getStoragePath(context: ExtensionContext): Promise<string>
630630 return storagePath ;
631631}
632632
633+ // the tool might be installed or not
634+ async function getSetOrLatestToolFromGHCup ( context : ExtensionContext , logger : Logger , tool : Tool ) : Promise < string > {
635+ // these might be custom/stray/compiled, so we try first
636+ const installedVersions = await callGHCup (
637+ context ,
638+ logger ,
639+ [ 'list' , '-t' , tool , '-c' , 'set' , '-r' ] ,
640+ undefined ,
641+ false ,
642+ ) ;
643+ const latestInstalled = installedVersions . split ( / \r ? \n / ) . pop ( ) ;
644+ if ( latestInstalled ) {
645+ return latestInstalled . split ( / \s + / ) [ 1 ] ;
646+ }
647+
648+ return getLatestToolFromGHCup ( context , logger , tool ) ;
649+ }
650+
651+
633652// the tool might be installed or not
634653async function getLatestToolFromGHCup ( context : ExtensionContext , logger : Logger , tool : Tool ) : Promise < string > {
635654 // these might be custom/stray/compiled, so we try first
0 commit comments