Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions src/zigSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,37 @@ async function updateStatus(context: vscode.ExtensionContext): Promise<void> {
});
}

async function getMirrors(context: vscode.ExtensionContext): Promise<vscode.Uri[]> {
let cached = { timestamp: 0, mirrors: "" };
const key = "mirror-cache";

const cachedStr = context.globalState.get<string>(key);
if (cachedStr !== undefined) {
cached = JSON.parse(cachedStr) as typeof cached;
}

const millisecondsInDay = 24 * 60 * 60 * 1000;
if (new Date().getTime() - cached.timestamp > millisecondsInDay) {
try {
const response = await fetch("https://ziglang.org/download/community-mirrors.txt");
if (response.status !== 200) throw Error("invalid mirrors");
const mirrorList = await response.text();
cached = {
timestamp: new Date().getTime(),
mirrors: mirrorList,
};
context.globalState.update(key, JSON.stringify(cached));
} catch {
// Cannot fetch mirrors, rely on cache.
}
}

return cached.mirrors
.trim()
.split("\n")
.map((u) => vscode.Uri.parse(u));
}

export async function setupZig(context: vscode.ExtensionContext) {
{
// This check can be removed once enough time has passed so that most users switched to the new value
Expand Down Expand Up @@ -674,19 +705,6 @@ export async function setupZig(context: vscode.ExtensionContext) {
break;
}

let mirrors: vscode.Uri[] = [];
try {
const response = await fetch("https://ziglang.org/download/community-mirrors.txt");
if (response.status !== 200) throw Error("invalid mirrors");
const mirrorList = await response.text();
mirrors = mirrorList
.trim()
.split("\n")
.map((u) => vscode.Uri.parse(u));
} catch {
// Cannot fetch mirrors, attempt downloading from canonical source.
}

versionManagerConfig = {
context: context,
title: "Zig",
Expand All @@ -695,7 +713,7 @@ export async function setupZig(context: vscode.ExtensionContext) {
/** https://ziglang.org/download */
minisignKey: minisign.parseKey("RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U"),
versionArg: "version",
mirrorUrls: mirrors,
mirrorUrls: await getMirrors(context),
canonicalUrl: {
release: vscode.Uri.parse("https://ziglang.org/download"),
nightly: vscode.Uri.parse("https://ziglang.org/builds"),
Expand Down