Skip to content

Commit ea9ae78

Browse files
committed
Fix bug in ghcup-based toolchain configuration
1 parent a65d4df commit ea9ae78

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(config: GHCupConfig, logger: Logger, folder?: WorkspaceFolder): GHCup {
1515
const ghcupLoc = findGHCup(logger, config.executablePath, 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;
@@ -131,11 +137,11 @@ export async function findHaskellLanguageServer(
131137
await ghcup.upgrade();
132138

133139
// boring init
134-
let latestHLS: string | undefined;
140+
let latestHLS: string | undefined | null;
135141
let latestCabal: string | undefined | null;
136142
let latestStack: string | undefined | null;
137143
let recGHC: string | undefined | null = 'recommended';
138-
let projectHls: string | undefined;
144+
let projectHls: string | undefined | null;
139145
let projectGhc: string | undefined | null;
140146

141147
// support explicit toolchain config
@@ -253,7 +259,7 @@ export async function findHaskellLanguageServer(
253259

254260
// more download popups
255261
if (promptBeforeDownloads) {
256-
const hlsInstalled = await toolInstalled(ghcup, 'hls', projectHls);
262+
const hlsInstalled = projectHls ? await toolInstalled(ghcup, 'hls', projectHls) : undefined;
257263
const ghcInstalled = projectGhc ? await toolInstalled(ghcup, 'ghc', projectGhc) : undefined;
258264
const toInstall: InstalledTool[] = [hlsInstalled, ghcInstalled].filter(
259265
(tool) => tool && !tool.installed,
@@ -291,7 +297,7 @@ export async function findHaskellLanguageServer(
291297
const hlsBinDir = await ghcup.call(
292298
[
293299
'run',
294-
...['--hls', projectHls],
300+
...(latestHLS ? ['--hls', latestHLS] : []),
295301
...(latestCabal ? ['--cabal', latestCabal] : []),
296302
...(latestStack ? ['--stack', latestStack] : []),
297303
...(projectGhc ? ['--ghc', projectGhc] : []),
@@ -309,11 +315,19 @@ export async function findHaskellLanguageServer(
309315
true,
310316
);
311317

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

0 commit comments

Comments
 (0)