@@ -25,10 +25,16 @@ export type Context = {
25
25
logger : Logger ;
26
26
} ;
27
27
28
- // On Windows the executable needs to be stored somewhere with an .exe extension
28
+ /**
29
+ * On Windows the executable needs to be stored somewhere with an .exe extension
30
+ */
29
31
const exeExt = process . platform === 'win32' ? '.exe' : '' ;
30
32
31
- /** Gets serverExecutablePath and fails if it's not set.
33
+ /**
34
+ * Gets serverExecutablePath and fails if it's not set.
35
+ * @param logger Log progress.
36
+ * @param folder Workspace folder. Used for resolving variables in the `serverExecutablePath`.
37
+ * @returns Path to an HLS executable binary.
32
38
*/
33
39
function findServerExecutable ( logger : Logger , folder ?: WorkspaceFolder ) : string {
34
40
const rawExePath = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
@@ -130,11 +136,11 @@ export async function findHaskellLanguageServer(
130
136
await ghcup . upgrade ( ) ;
131
137
132
138
// boring init
133
- let latestHLS : string | undefined ;
139
+ let latestHLS : string | undefined | null ;
134
140
let latestCabal : string | undefined | null ;
135
141
let latestStack : string | undefined | null ;
136
142
let recGHC : string | undefined | null = 'recommended' ;
137
- let projectHls : string | undefined ;
143
+ let projectHls : string | undefined | null ;
138
144
let projectGhc : string | undefined | null ;
139
145
140
146
// support explicit toolchain config
@@ -252,7 +258,7 @@ export async function findHaskellLanguageServer(
252
258
253
259
// more download popups
254
260
if ( promptBeforeDownloads ) {
255
- const hlsInstalled = await toolInstalled ( ghcup , 'hls' , projectHls ) ;
261
+ const hlsInstalled = projectHls ? await toolInstalled ( ghcup , 'hls' , projectHls ) : undefined ;
256
262
const ghcInstalled = projectGhc ? await toolInstalled ( ghcup , 'ghc' , projectGhc ) : undefined ;
257
263
const toInstall : InstalledTool [ ] = [ hlsInstalled , ghcInstalled ] . filter (
258
264
( tool ) => tool && ! tool . installed ,
@@ -290,7 +296,7 @@ export async function findHaskellLanguageServer(
290
296
const hlsBinDir = await ghcup . call (
291
297
[
292
298
'run' ,
293
- ...[ '--hls' , projectHls ] ,
299
+ ...( latestHLS ? [ '--hls' , latestHLS ] : [ ] ) ,
294
300
...( latestCabal ? [ '--cabal' , latestCabal ] : [ ] ) ,
295
301
...( latestStack ? [ '--stack' , latestStack ] : [ ] ) ,
296
302
...( projectGhc ? [ '--ghc' , projectGhc ] : [ ] ) ,
@@ -308,11 +314,19 @@ export async function findHaskellLanguageServer(
308
314
true ,
309
315
) ;
310
316
311
- return {
312
- binaryDirectory : hlsBinDir ,
313
- location : path . join ( hlsBinDir , `haskell-language-server-wrapper${ exeExt } ` ) ,
314
- tag : 'ghcup' ,
315
- } ;
317
+ if ( projectHls ) {
318
+ return {
319
+ binaryDirectory : hlsBinDir ,
320
+ location : path . join ( hlsBinDir , `haskell-language-server-wrapper${ exeExt } ` ) ,
321
+ tag : 'ghcup' ,
322
+ } ;
323
+ } else {
324
+ return {
325
+ binaryDirectory : hlsBinDir ,
326
+ location : findHlsInPath ( logger ) ,
327
+ tag : 'ghcup' ,
328
+ } ;
329
+ }
316
330
}
317
331
}
318
332
0 commit comments