Skip to content

Commit 8167ea0

Browse files
authored
Merge pull request #585 from fendor/fix/convert-release-metadata
Properly convert release metadata from json
2 parents c8986b2 + cd0f533 commit 8167ea0

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog for vscode-haskell
22

3+
## 2.1.3 (Pre-release)
4+
5+
- Ignore missing entries in Release Metadata
6+
([#585](https://github.com/haskell/vscode-haskell/pull/585)) by @fendor
7+
38
## 2.1.2 (Pre-release)
49

510
- Ignore missing entries in Release Metadata

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "haskell",
33
"displayName": "Haskell",
44
"description": "Haskell language support powered by the Haskell Language Server",
5-
"version": "2.1.2",
5+
"version": "2.1.3",
66
"license": "MIT",
77
"publisher": "haskell",
88
"engines": {

src/hlsBinaries.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ async function toolInstalled(
726726
*
727727
* consult [ghcup metadata repo](https://github.com/haskell/ghcup-metadata/) for details.
728728
*/
729-
export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
729+
export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
730730

731731
/**
732732
* Compute Map of supported HLS versions for this platform.
@@ -829,13 +829,29 @@ async function getReleaseMetadata(
829829

830830
const offlineCache = path.join(storagePath, 'ghcupReleases.cache.json');
831831

832+
/**
833+
* Convert a json value to ReleaseMetadata.
834+
* Assumes the json is well-formed and a valid Release-Metadata.
835+
* @param obj Release Metadata without any typing information but well-formed.
836+
* @returns Typed ReleaseMetadata.
837+
*/
838+
const objectToMetadata = (obj: any): ReleaseMetadata => {
839+
const hlsMetaEntries = Object.entries(obj).map(([hlsVersion, archMap]) => {
840+
const archMetaEntries = Object.entries(archMap as any).map(([arch, supportedGhcVersionsPerOs]) => {
841+
return [arch, new Map(Object.entries(supportedGhcVersionsPerOs as any))] as [string, Map<string, string[]>];
842+
});
843+
return [hlsVersion, new Map(archMetaEntries)] as [string, Map<string, Map<string, string[]>>];
844+
});
845+
return new Map(hlsMetaEntries);
846+
};
847+
832848
async function readCachedReleaseData(): Promise<ReleaseMetadata | null> {
833849
try {
834850
logger.info(`Reading cached release data at ${offlineCache}`);
835851
const cachedInfo = await promisify(fs.readFile)(offlineCache, { encoding: 'utf-8' });
836852
// export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
837-
const value: ReleaseMetadata = JSON.parse(cachedInfo);
838-
return value;
853+
const value: any = JSON.parse(cachedInfo);
854+
return objectToMetadata(value);
839855
} catch (err: any) {
840856
// If file doesn't exist, return null, otherwise consider it a failure
841857
if (err.code === 'ENOENT') {
@@ -852,7 +868,7 @@ async function getReleaseMetadata(
852868

853869
// Cache the latest successfully fetched release information
854870
await promisify(fs.writeFile)(offlineCache, JSON.stringify(releaseInfoParsed), { encoding: 'utf-8' });
855-
return releaseInfoParsed;
871+
return objectToMetadata(releaseInfoParsed);
856872
} catch (githubError: any) {
857873
// Attempt to read from the latest cached file
858874
try {

0 commit comments

Comments
 (0)