Skip to content

Commit 9c5b6e6

Browse files
committed
support old hls versions compatible with the requested ghc version
1 parent 627b1da commit 9c5b6e6

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/hlsBinaries.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const releaseValidator: validate.Validator<IRelease> = validate.object({
3737

3838
const githubReleaseApiValidator: validate.Validator<IRelease[]> = validate.array(releaseValidator);
3939

40-
const cachedReleaseValidator: validate.Validator<IRelease | null> = validate.optional(releaseValidator);
40+
const cachedReleaseValidator: validate.Validator<IRelease[] | null> = validate.optional(githubReleaseApiValidator);
4141

4242
// On Windows the executable needs to be stored somewhere with an .exe extension
4343
const exeExt = process.platform === 'win32' ? '.exe' : '';
@@ -205,7 +205,7 @@ async function getProjectGhcVersion(
205205
return callWrapper(downloadedWrapper);
206206
}
207207

208-
async function getLatestReleaseMetadata(context: ExtensionContext, storagePath: string): Promise<IRelease | null> {
208+
async function getLatestReleaseMetadata(context: ExtensionContext, storagePath: string): Promise<IRelease[] | null> {
209209
const releasesUrl = workspace.getConfiguration('haskell').releasesURL
210210
? url.parse(workspace.getConfiguration('haskell').releasesURL)
211211
: undefined;
@@ -221,7 +221,7 @@ async function getLatestReleaseMetadata(context: ExtensionContext, storagePath:
221221

222222
const offlineCache = path.join(storagePath, 'latestApprovedRelease.cache.json');
223223

224-
async function readCachedReleaseData(): Promise<IRelease | null> {
224+
async function readCachedReleaseData(): Promise<IRelease[] | null> {
225225
try {
226226
const cachedInfo = await promisify(fs.readFile)(offlineCache, { encoding: 'utf-8' });
227227
return validate.parseAndValidate(cachedInfo, cachedReleaseValidator);
@@ -243,14 +243,14 @@ async function getLatestReleaseMetadata(context: ExtensionContext, storagePath:
243243
try {
244244
const releaseInfo = await httpsGetSilently(opts);
245245
const latestInfoParsed =
246-
validate.parseAndValidate(releaseInfo, githubReleaseApiValidator).find((x) => !x.prerelease) || null;
246+
validate.parseAndValidate(releaseInfo, githubReleaseApiValidator).filter((x) => !x.prerelease) || null;
247247

248248
if (updateBehaviour === 'prompt') {
249249
const cachedInfoParsed = await readCachedReleaseData();
250250

251251
if (
252252
latestInfoParsed !== null &&
253-
(cachedInfoParsed === null || latestInfoParsed.tag_name !== cachedInfoParsed.tag_name)
253+
(cachedInfoParsed === null || latestInfoParsed[0].tag_name !== cachedInfoParsed[0].tag_name)
254254
) {
255255
const promptMessage =
256256
cachedInfoParsed === null
@@ -316,8 +316,8 @@ export async function downloadHaskellLanguageServer(
316316
}
317317

318318
logger.info('Fetching the latest release from GitHub or from cache');
319-
const release = await getLatestReleaseMetadata(context, storagePath);
320-
if (!release) {
319+
const releases = await getLatestReleaseMetadata(context, storagePath);
320+
if (!releases) {
321321
let message = "Couldn't find any pre-built haskell-language-server binaries";
322322
const updateBehaviour = workspace.getConfiguration('haskell').get('updateBehavior') as UpdateBehaviour;
323323
if (updateBehaviour === 'never-check') {
@@ -326,12 +326,12 @@ export async function downloadHaskellLanguageServer(
326326
window.showErrorMessage(message);
327327
return null;
328328
}
329-
logger.info(`The latest release is ${release.tag_name}`);
329+
logger.info(`The latest release is ${releases[0].tag_name}`);
330330
logger.info('Figure out the ghc version to use or advertise an installation link for missing components');
331331
const dir: string = folder?.uri?.fsPath ?? path.dirname(resource.fsPath);
332332
let ghcVersion: string;
333333
try {
334-
ghcVersion = await getProjectGhcVersion(context, logger, dir, release, storagePath);
334+
ghcVersion = await getProjectGhcVersion(context, logger, dir, releases[0], storagePath);
335335
} catch (error) {
336336
if (error instanceof MissingToolError) {
337337
const link = error.installLink();
@@ -354,20 +354,21 @@ export async function downloadHaskellLanguageServer(
354354
// When searching for binaries, use startsWith because the compression may differ
355355
// between .zip and .gz
356356
const assetName = `haskell-language-server-${githubOS}-${ghcVersion}${exeExt}`;
357-
logger.info(`Search for binary ${assetName} in release assests`);
357+
logger.info(`Search for binary ${assetName} in release assets`);
358+
const release = releases?.find(r => r.assets.find((x) => x.name.startsWith(assetName)));
358359
const asset = release?.assets.find((x) => x.name.startsWith(assetName));
359360
if (!asset) {
360361
logger.error(
361-
`No binary ${assetName} found in the release assets: ${release?.assets.map((value) => value.name).join(',')}`
362+
`No binary ${assetName} found in the release assets`
362363
);
363-
window.showInformationMessage(new NoBinariesError(release.tag_name, ghcVersion).message);
364+
window.showInformationMessage(new NoBinariesError(releases[0].tag_name, ghcVersion).message);
364365
return null;
365366
}
366367

367-
const serverName = `haskell-language-server-${release.tag_name}-${process.platform}-${ghcVersion}${exeExt}`;
368+
const serverName = `haskell-language-server-${release?.tag_name}-${process.platform}-${ghcVersion}${exeExt}`;
368369
const binaryDest = path.join(storagePath, serverName);
369370

370-
const title = `Downloading haskell-language-server ${release.tag_name} for GHC ${ghcVersion}`;
371+
const title = `Downloading haskell-language-server ${release?.tag_name} for GHC ${ghcVersion}`;
371372
logger.info(title);
372373
await downloadFile(title, asset.browser_download_url, binaryDest);
373374
if (ghcVersion.startsWith('9.')) {

0 commit comments

Comments
 (0)