Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 9a9166c

Browse files
committed
fix incorrect values being cached in the global state
Previously the code stored a `semver.Semver` as a JS Object in the global state instead of storing a string as was intended.
1 parent 87cd528 commit 9a9166c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/zigSetup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function findClosestSatisfyingZigVersion(
8585
// We can't just return `version` because `0.12.0` should return `0.12.1`.
8686
const availableVersions = (await getVersions()).map((item) => item.version);
8787
const selectedVersion = semver.maxSatisfying(availableVersions, `^${version.toString()}`);
88-
await context.globalState.update(cacheKey, selectedVersion ?? undefined);
88+
await context.globalState.update(cacheKey, selectedVersion ? selectedVersion.raw : undefined);
8989
return selectedVersion ?? version;
9090
} catch {
9191
const selectedVersion = context.globalState.get<string | null>(cacheKey, null);
@@ -597,6 +597,16 @@ export async function setupZig(context: vscode.ExtensionContext) {
597597
await workspaceConfigUpdateNoThrow(zigConfig, "initialSetupDone", undefined, true);
598598

599599
await context.workspaceState.update("zig-version", undefined);
600+
601+
// Remove incorrect values in the global state that have been added by
602+
// an older version of the extension.
603+
for (const key of context.globalState.keys()) {
604+
if (!key.startsWith("zig-satisfying-version-")) continue;
605+
const value = context.globalState.get(key);
606+
if (value !== undefined && typeof value !== "string") {
607+
await context.globalState.update(key, undefined);
608+
}
609+
}
600610
}
601611

602612
/// Workaround https://github.com/ziglang/zig/issues/21905

0 commit comments

Comments
 (0)