From 798218a9a3ab6495313533a298e1e29e55dd1bff Mon Sep 17 00:00:00 2001 From: David Czihak Date: Tue, 12 May 2026 09:51:15 +0200 Subject: Fix: Throttle step discovery --- Zig.novaextension/Scripts/main.js | 50 ++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'Zig.novaextension/Scripts') diff --git a/Zig.novaextension/Scripts/main.js b/Zig.novaextension/Scripts/main.js index 178f376..04cfb22 100644 --- a/Zig.novaextension/Scripts/main.js +++ b/Zig.novaextension/Scripts/main.js @@ -8,6 +8,7 @@ const LANGUAGE_CLIENT_ID = `${EXTENSION_ID}.zls`; const ISSUE_MATCHER = "zig.compiler"; const USER_OPTION_REGEX = /^[A-Za-z_][A-Za-z0-9_-]*(=.+)?$/; const STEP_CACHE_TTL_MS = 5 * 60 * 1000; +const STEP_DISCOVERY_RETRY_DELAY_MS = 30 * 1000; const CONFIG_KEYS = { zigPath: `${EXTENSION_ID}.toolchain.zig-path`, @@ -553,6 +554,7 @@ const stepCache = { entries: new Map(), pending: new Map(), lastWarnedAt: new Map(), + retryTimers: new Map(), getOrFetch(cwd) { if (!cwd) return null; @@ -578,22 +580,48 @@ const stepCache = { if (fresh) return cached.steps; if (!this.pending.has(cwd)) { - const promise = this.fetch(cwd, buildZigMtimeMs, buildZonMtimeMs).finally( - () => { - this.pending.delete(cwd); - if (typeof nova.workspace.reloadTasks === "function") { - try { - nova.workspace.reloadTasks(TASK_ASSISTANT_ID); - } catch (_) {} + clearTimeout(this.retryTimers.get(cwd)); + this.retryTimers.delete(cwd); + + const promise = this.fetch(cwd, buildZigMtimeMs, buildZonMtimeMs) + .then((steps) => { + if (steps !== null) { + if (typeof nova.workspace.reloadTasks === "function") { + try { + nova.workspace.reloadTasks(TASK_ASSISTANT_ID); + } catch (_) {} + } + } else { + this._scheduleRetry(cwd); } - }, - ); + }) + .catch(() => { + this._scheduleRetry(cwd); + }) + .finally(() => { + this.pending.delete(cwd); + }); this.pending.set(cwd, promise); } return cached ? cached.steps : null; }, + _scheduleRetry(cwd) { + clearTimeout(this.retryTimers.get(cwd)); + this.retryTimers.set( + cwd, + setTimeout(() => { + this.retryTimers.delete(cwd); + if (typeof nova.workspace.reloadTasks === "function") { + try { + nova.workspace.reloadTasks(TASK_ASSISTANT_ID); + } catch (_) {} + } + }, STEP_DISCOVERY_RETRY_DELAY_MS), + ); + }, + async fetch(cwd, buildZigMtimeMs, buildZonMtimeMs) { console.log(`[${TASK_ASSISTANT_ID}] stepCache.fetch: cwd=${cwd}`); const zigPath = await resolveZigExecutable(); @@ -636,9 +664,13 @@ const stepCache = { if (cwd) { this.entries.delete(cwd); this.lastWarnedAt.delete(cwd); + clearTimeout(this.retryTimers.get(cwd)); + this.retryTimers.delete(cwd); } else { this.entries.clear(); this.lastWarnedAt.clear(); + for (const t of this.retryTimers.values()) clearTimeout(t); + this.retryTimers.clear(); } }, }; -- cgit v1.3