Skip to content

Commit 3642f5a

Browse files
committed
Fix bug in ghcup-based toolchain configuration
1 parent 778df39 commit 3642f5a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/ghcup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { match } from 'ts-pattern';
99

1010
export type Tool = 'hls' | 'ghc' | 'cabal' | 'stack';
1111

12-
export type ToolConfig = Map<Tool, string>;
12+
export type ToolConfig = Map<Tool, string | null>;
1313

1414
export function initDefaultGHCup(logger: Logger, folder?: WorkspaceFolder): GHCup {
1515
const ghcupLoc = findGHCup(logger, folder);

src/hlsBinaries.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ export type Context = {
2525
logger: Logger;
2626
};
2727

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+
*/
2931
const exeExt = process.platform === 'win32' ? '.exe' : '';
3032

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.
3238
*/
3339
function findServerExecutable(logger: Logger, folder?: WorkspaceFolder): string {
3440
const rawExePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
@@ -130,11 +136,11 @@ export async function findHaskellLanguageServer(
130136
await ghcup.upgrade();
131137

132138
// boring init
133-
let latestHLS: string | undefined;
139+
let latestHLS: string | undefined | null;
134140
let latestCabal: string | undefined | null;
135141
let latestStack: string | undefined | null;
136142
let recGHC: string | undefined | null = 'recommended';
137-
let projectHls: string | undefined;
143+
let projectHls: string | undefined | null;
138144
let projectGhc: string | undefined | null;
139145

140146
// support explicit toolchain config
@@ -252,7 +258,7 @@ export async function findHaskellLanguageServer(
252258

253259
// more download popups
254260
if (promptBeforeDownloads) {
255-
const hlsInstalled = await toolInstalled(ghcup, 'hls', projectHls);
261+
const hlsInstalled = projectHls ? await toolInstalled(ghcup, 'hls', projectHls) : undefined;
256262
const ghcInstalled = projectGhc ? await toolInstalled(ghcup, 'ghc', projectGhc) : undefined;
257263
const toInstall: InstalledTool[] = [hlsInstalled, ghcInstalled].filter(
258264
(tool) => tool && !tool.installed,
@@ -290,7 +296,7 @@ export async function findHaskellLanguageServer(
290296
const hlsBinDir = await ghcup.call(
291297
[
292298
'run',
293-
...['--hls', projectHls],
299+
...(latestHLS ? ['--hls', latestHLS] : []),
294300
...(latestCabal ? ['--cabal', latestCabal] : []),
295301
...(latestStack ? ['--stack', latestStack] : []),
296302
...(projectGhc ? ['--ghc', projectGhc] : []),
@@ -308,11 +314,19 @@ export async function findHaskellLanguageServer(
308314
true,
309315
);
310316

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+
}
316330
}
317331
}
318332

0 commit comments

Comments
 (0)