@@ -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 ;
@@ -131,11 +137,11 @@ export async function findHaskellLanguageServer(
131
137
await ghcup . upgrade ( ) ;
132
138
133
139
// boring init
134
- let latestHLS : string | undefined ;
140
+ let latestHLS : string | undefined | null ;
135
141
let latestCabal : string | undefined | null ;
136
142
let latestStack : string | undefined | null ;
137
143
let recGHC : string | undefined | null = 'recommended' ;
138
- let projectHls : string | undefined ;
144
+ let projectHls : string | undefined | null ;
139
145
let projectGhc : string | undefined | null ;
140
146
141
147
// support explicit toolchain config
@@ -253,7 +259,7 @@ export async function findHaskellLanguageServer(
253
259
254
260
// more download popups
255
261
if ( promptBeforeDownloads ) {
256
- const hlsInstalled = await toolInstalled ( ghcup , 'hls' , projectHls ) ;
262
+ const hlsInstalled = projectHls ? await toolInstalled ( ghcup , 'hls' , projectHls ) : undefined ;
257
263
const ghcInstalled = projectGhc ? await toolInstalled ( ghcup , 'ghc' , projectGhc ) : undefined ;
258
264
const toInstall : InstalledTool [ ] = [ hlsInstalled , ghcInstalled ] . filter (
259
265
( tool ) => tool && ! tool . installed ,
@@ -291,7 +297,7 @@ export async function findHaskellLanguageServer(
291
297
const hlsBinDir = await ghcup . call (
292
298
[
293
299
'run' ,
294
- ...[ '--hls' , projectHls ] ,
300
+ ...( latestHLS ? [ '--hls' , latestHLS ] : [ ] ) ,
295
301
...( latestCabal ? [ '--cabal' , latestCabal ] : [ ] ) ,
296
302
...( latestStack ? [ '--stack' , latestStack ] : [ ] ) ,
297
303
...( projectGhc ? [ '--ghc' , projectGhc ] : [ ] ) ,
@@ -309,11 +315,19 @@ export async function findHaskellLanguageServer(
309
315
true ,
310
316
) ;
311
317
312
- return {
313
- binaryDirectory : hlsBinDir ,
314
- location : path . join ( hlsBinDir , `haskell-language-server-wrapper${ exeExt } ` ) ,
315
- tag : 'ghcup' ,
316
- } ;
318
+ if ( projectHls ) {
319
+ return {
320
+ binaryDirectory : hlsBinDir ,
321
+ location : path . join ( hlsBinDir , `haskell-language-server-wrapper${ exeExt } ` ) ,
322
+ tag : 'ghcup' ,
323
+ } ;
324
+ } else {
325
+ return {
326
+ binaryDirectory : hlsBinDir ,
327
+ location : findHlsInPath ( logger ) ,
328
+ tag : 'ghcup' ,
329
+ } ;
330
+ }
317
331
}
318
332
}
319
333
0 commit comments