@@ -139,22 +139,22 @@ export async function callAsync(
139
139
140
140
/** Gets serverExecutablePath and fails if it's not set.
141
141
*/
142
- async function findServerExecutable ( logger : Logger , folder ?: WorkspaceFolder ) : Promise < string > {
143
- let exePath = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
144
- logger . info ( `Trying to find the server executable in: ${ exePath } ` ) ;
145
- exePath = resolvePathPlaceHolders ( exePath , folder ) ;
146
- logger . log ( `Location after path variables substitution: ${ exePath } ` ) ;
147
- if ( executableExists ( exePath ) ) {
148
- return exePath ;
142
+ function findServerExecutable ( logger : Logger , folder ?: WorkspaceFolder ) : string {
143
+ const rawExePath = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
144
+ logger . info ( `Trying to find the server executable in: ${ rawExePath } ` ) ;
145
+ const resolvedExePath = resolvePathPlaceHolders ( rawExePath , folder ) ;
146
+ logger . log ( `Location after path variables substitution: ${ resolvedExePath } ` ) ;
147
+ if ( executableExists ( resolvedExePath ) ) {
148
+ return resolvedExePath ;
149
149
} else {
150
- const msg = `Could not find a HLS binary at ${ exePath } ! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.` ;
151
- throw new Error ( msg ) ;
150
+ const msg = `Could not find a HLS binary at ${ resolvedExePath } ! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.` ;
151
+ throw new HlsError ( msg ) ;
152
152
}
153
153
}
154
154
155
155
/** Searches the PATH. Fails if nothing is found.
156
156
*/
157
- async function findHLSinPATH ( _context : ExtensionContext , logger : Logger ) : Promise < string > {
157
+ function findHlsInPath ( _context : ExtensionContext , logger : Logger ) : string {
158
158
// try PATH
159
159
const exes : string [ ] = [ 'haskell-language-server-wrapper' , 'haskell-language-server' ] ;
160
160
logger . info ( `Searching for server executables ${ exes . join ( ',' ) } in $PATH` ) ;
@@ -210,16 +210,16 @@ export async function findHaskellLanguageServer(
210
210
) : Promise < HlsExecutable > {
211
211
logger . info ( 'Finding haskell-language-server' ) ;
212
212
213
- if ( workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ) {
214
- const exe = await findServerExecutable ( logger , folder ) ;
213
+ const hasConfigForExecutable = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
214
+ if ( hasConfigForExecutable ) {
215
+ const exe = findServerExecutable ( logger , folder ) ;
215
216
return {
216
217
location : exe ,
217
218
tag : 'config' ,
218
219
} ;
219
220
}
220
221
221
- const storagePath : string = await getStoragePath ( context ) ;
222
-
222
+ const storagePath : string = getStoragePath ( context ) ;
223
223
if ( ! fs . existsSync ( storagePath ) ) {
224
224
fs . mkdirSync ( storagePath ) ;
225
225
}
@@ -228,7 +228,7 @@ export async function findHaskellLanguageServer(
228
228
manageHLS = await promptUserForManagingHls ( context , manageHLS ) ;
229
229
230
230
if ( manageHLS === 'PATH' ) {
231
- const exe = await findHLSinPATH ( context , logger ) ;
231
+ const exe = findHlsInPath ( context , logger ) ;
232
232
return {
233
233
location : exe ,
234
234
tag : 'path' ,
@@ -512,7 +512,7 @@ async function getLatestProjectHLS(
512
512
: await callAsync ( `ghc${ exeExt } ` , [ '--numeric-version' ] , logger , undefined , undefined , false ) ;
513
513
514
514
// first we get supported GHC versions from available HLS bindists (whether installed or not)
515
- const metadataMap = ( await getHLSesfromMetadata ( context , logger ) ) || new Map < string , string [ ] > ( ) ;
515
+ const metadataMap = ( await getHlsMetadata ( context , logger ) ) || new Map < string , string [ ] > ( ) ;
516
516
// then we get supported GHC versions from currently installed HLS versions
517
517
const ghcupMap = ( await getHLSesFromGHCup ( context , logger ) ) || new Map < string , string [ ] > ( ) ;
518
518
// since installed HLS versions may support a different set of GHC versions than the bindists
@@ -657,8 +657,8 @@ export async function findGHCup(_context: ExtensionContext, logger: Logger, fold
657
657
}
658
658
}
659
659
660
- export async function getStoragePath ( context : ExtensionContext ) : Promise < string > {
661
- let storagePath : string | undefined = await workspace . getConfiguration ( 'haskell' ) . get ( 'releasesDownloadStoragePath' ) ;
660
+ export function getStoragePath ( context : ExtensionContext ) : string {
661
+ let storagePath : string | undefined = workspace . getConfiguration ( 'haskell' ) . get ( 'releasesDownloadStoragePath' ) ;
662
662
663
663
if ( ! storagePath ) {
664
664
storagePath = context . globalStorageUri . fsPath ;
@@ -838,8 +838,8 @@ export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
838
838
* @param logger Logger for feedback
839
839
* @returns Map of supported HLS versions or null if metadata could not be fetched.
840
840
*/
841
- async function getHLSesfromMetadata ( context : ExtensionContext , logger : Logger ) : Promise < Map < string , string [ ] > | null > {
842
- const storagePath : string = await getStoragePath ( context ) ;
841
+ async function getHlsMetadata ( context : ExtensionContext , logger : Logger ) : Promise < Map < string , string [ ] > | null > {
842
+ const storagePath : string = getStoragePath ( context ) ;
843
843
const metadata = await getReleaseMetadata ( context , storagePath , logger ) . catch ( ( ) => null ) ;
844
844
if ( ! metadata ) {
845
845
window . showErrorMessage ( 'Could not get release metadata' ) ;
0 commit comments