@@ -37,7 +37,7 @@ const releaseValidator: validate.Validator<IRelease> = validate.object({
37
37
38
38
const githubReleaseApiValidator : validate . Validator < IRelease [ ] > = validate . array ( releaseValidator ) ;
39
39
40
- const cachedReleaseValidator : validate . Validator < IRelease | null > = validate . optional ( releaseValidator ) ;
40
+ const cachedReleaseValidator : validate . Validator < IRelease [ ] | null > = validate . optional ( githubReleaseApiValidator ) ;
41
41
42
42
// On Windows the executable needs to be stored somewhere with an .exe extension
43
43
const exeExt = process . platform === 'win32' ? '.exe' : '' ;
@@ -205,7 +205,7 @@ async function getProjectGhcVersion(
205
205
return callWrapper ( downloadedWrapper ) ;
206
206
}
207
207
208
- async function getLatestReleaseMetadata ( context : ExtensionContext , storagePath : string ) : Promise < IRelease | null > {
208
+ async function getLatestReleaseMetadata ( context : ExtensionContext , storagePath : string ) : Promise < IRelease [ ] | null > {
209
209
const releasesUrl = workspace . getConfiguration ( 'haskell' ) . releasesURL
210
210
? url . parse ( workspace . getConfiguration ( 'haskell' ) . releasesURL )
211
211
: undefined ;
@@ -221,7 +221,7 @@ async function getLatestReleaseMetadata(context: ExtensionContext, storagePath:
221
221
222
222
const offlineCache = path . join ( storagePath , 'latestApprovedRelease.cache.json' ) ;
223
223
224
- async function readCachedReleaseData ( ) : Promise < IRelease | null > {
224
+ async function readCachedReleaseData ( ) : Promise < IRelease [ ] | null > {
225
225
try {
226
226
const cachedInfo = await promisify ( fs . readFile ) ( offlineCache , { encoding : 'utf-8' } ) ;
227
227
return validate . parseAndValidate ( cachedInfo , cachedReleaseValidator ) ;
@@ -243,14 +243,14 @@ async function getLatestReleaseMetadata(context: ExtensionContext, storagePath:
243
243
try {
244
244
const releaseInfo = await httpsGetSilently ( opts ) ;
245
245
const latestInfoParsed =
246
- validate . parseAndValidate ( releaseInfo , githubReleaseApiValidator ) . find ( ( x ) => ! x . prerelease ) || null ;
246
+ validate . parseAndValidate ( releaseInfo , githubReleaseApiValidator ) . filter ( ( x ) => ! x . prerelease ) || null ;
247
247
248
248
if ( updateBehaviour === 'prompt' ) {
249
249
const cachedInfoParsed = await readCachedReleaseData ( ) ;
250
250
251
251
if (
252
252
latestInfoParsed !== null &&
253
- ( cachedInfoParsed === null || latestInfoParsed . tag_name !== cachedInfoParsed . tag_name )
253
+ ( cachedInfoParsed === null || latestInfoParsed [ 0 ] . tag_name !== cachedInfoParsed [ 0 ] . tag_name )
254
254
) {
255
255
const promptMessage =
256
256
cachedInfoParsed === null
@@ -316,8 +316,8 @@ export async function downloadHaskellLanguageServer(
316
316
}
317
317
318
318
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 ) {
321
321
let message = "Couldn't find any pre-built haskell-language-server binaries" ;
322
322
const updateBehaviour = workspace . getConfiguration ( 'haskell' ) . get ( 'updateBehavior' ) as UpdateBehaviour ;
323
323
if ( updateBehaviour === 'never-check' ) {
@@ -326,12 +326,12 @@ export async function downloadHaskellLanguageServer(
326
326
window . showErrorMessage ( message ) ;
327
327
return null ;
328
328
}
329
- logger . info ( `The latest release is ${ release . tag_name } ` ) ;
329
+ logger . info ( `The latest release is ${ releases [ 0 ] . tag_name } ` ) ;
330
330
logger . info ( 'Figure out the ghc version to use or advertise an installation link for missing components' ) ;
331
331
const dir : string = folder ?. uri ?. fsPath ?? path . dirname ( resource . fsPath ) ;
332
332
let ghcVersion : string ;
333
333
try {
334
- ghcVersion = await getProjectGhcVersion ( context , logger , dir , release , storagePath ) ;
334
+ ghcVersion = await getProjectGhcVersion ( context , logger , dir , releases [ 0 ] , storagePath ) ;
335
335
} catch ( error ) {
336
336
if ( error instanceof MissingToolError ) {
337
337
const link = error . installLink ( ) ;
@@ -354,20 +354,21 @@ export async function downloadHaskellLanguageServer(
354
354
// When searching for binaries, use startsWith because the compression may differ
355
355
// between .zip and .gz
356
356
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 ) ) ) ;
358
359
const asset = release ?. assets . find ( ( x ) => x . name . startsWith ( assetName ) ) ;
359
360
if ( ! asset ) {
360
361
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`
362
363
) ;
363
- window . showInformationMessage ( new NoBinariesError ( release . tag_name , ghcVersion ) . message ) ;
364
+ window . showInformationMessage ( new NoBinariesError ( releases [ 0 ] . tag_name , ghcVersion ) . message ) ;
364
365
return null ;
365
366
}
366
367
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 } ` ;
368
369
const binaryDest = path . join ( storagePath , serverName ) ;
369
370
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 } ` ;
371
372
logger . info ( title ) ;
372
373
await downloadFile ( title , asset . browser_download_url , binaryDest ) ;
373
374
if ( ghcVersion . startsWith ( '9.' ) ) {
0 commit comments