aboutsummaryrefslogtreecommitdiff
path: root/Zig.novaextension/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Zig.novaextension/Scripts')
-rw-r--r--Zig.novaextension/Scripts/main.js50
1 files changed, 41 insertions, 9 deletions
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();
}
},
};