Skip to content

Commit ca628e2

Browse files
committed
Properly validate hls executables wrt ghc version
1 parent 8fd75e1 commit ca628e2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { CommandNames } from './commands/constants';
2323
import { ImportIdentifier } from './commands/importIdentifier';
2424
import { DocsBrowser } from './docsBrowser';
25-
import { IEnvVars, addPathToProcessPath, downloadHaskellLanguageServer, downloadGHCup, getProjectGHCVersion } from './hlsBinaries';
25+
import { IEnvVars, addPathToProcessPath, downloadHaskellLanguageServer, downloadGHCup, validateHLSToolchain } from './hlsBinaries';
2626
import { directoryExists, executableExists, expandHomeDir, ExtensionLogger, resolvePathPlaceHolders } from './utils';
2727

2828

@@ -190,7 +190,7 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
190190
// If not, then try to download haskell-language-server binaries if it's selected
191191
await downloadGHCup(context, logger);
192192
serverExecutable = await downloadHaskellLanguageServer(context, logger);
193-
await getProjectGHCVersion(serverExecutable, currentWorkingDir, logger)
193+
await validateHLSToolchain(serverExecutable, currentWorkingDir, logger)
194194
addInternalServerPath = path.dirname(serverExecutable);
195195
if (!serverExecutable) {
196196
return;

src/hlsBinaries.ts

+17
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ export async function downloadHaskellLanguageServer(context: ExtensionContext, l
238238
}
239239
}
240240

241+
// also serves as sanity check
242+
export async function validateHLSToolchain(
243+
wrapper: string,
244+
workingDir: string,
245+
logger: Logger
246+
): Promise<void> {
247+
const ghc = await getProjectGHCVersion(wrapper, workingDir, logger);
248+
const wrapperDir = path.dirname(wrapper);
249+
const hlsExe = path.join(wrapperDir, `haskell-language-server-${ghc}${exeExt}`)
250+
const hlsVer = await callAsync(wrapper, ["--numeric-version"], workingDir, logger);
251+
if (!executableExists(hlsExe)) {
252+
const msg = `Couldn't find ${hlsExe}. Your project ghc version ${ghc} may not be supported! Consider building HLS from source, e.g.: ghcup compile hls --jobs 8 --ghc ${ghc} ${hlsVer}`;
253+
window.showErrorMessage(msg);
254+
throw new Error(msg);
255+
}
256+
}
257+
241258
// also serves as sanity check
242259
export async function getProjectGHCVersion(
243260
wrapper: string,

0 commit comments

Comments
 (0)