From ed86d506bba4b78a6552ad535900f437183b54c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troed=20S=C3=A5ngberg?= Date: Tue, 16 Jun 2026 13:49:19 +0200 Subject: [PATCH] remove dead parseJSONC code --- tui.tsx | 75 +++------------------------------------------------------ 1 file changed, 4 insertions(+), 71 deletions(-) diff --git a/tui.tsx b/tui.tsx index 0490893..4cf9060 100644 --- a/tui.tsx +++ b/tui.tsx @@ -49,70 +49,6 @@ function estimateStreamTokens(delta: string) { return Math.max(1, Math.ceil(Buffer.byteLength(delta, "utf8") / 5)) } -function parseJSONC(text: string): unknown { - let result = "" - let inString = false - let escape = false - let i = 0 - - while (i < text.length) { - const ch = text[i] - - if (escape) { - result += ch - escape = false - i++ - continue - } - - if (ch === "\\") { - result += ch - escape = true - i++ - continue - } - - if (ch === '"') { - result += ch - inString = !inString - i++ - continue - } - - if (inString) { - result += ch - i++ - continue - } - - if (ch === "/" && text[i + 1] === "/") { - while (i < text.length && text[i] !== "\n") i++ - continue - } - - if (ch === "/" && text[i + 1] === "*") { - i += 2 - while (i < text.length - 1 && !(text[i] === "*" && text[i + 1] === "/")) i++ - i += 2 - result += " " - continue - } - - if (ch === ",") { - const next = text.indexOf(/[\s}\]]/, i + 1) - if (next !== -1 && /[\s}\]]/.test(text[next])) { - i++ - continue - } - } - - result += ch - i++ - } - - return JSON.parse(result) -} - function stripBaseUrlPath(baseURL: string): string { try { const url = new URL(baseURL) @@ -154,13 +90,10 @@ function extractProviderUrls(config: unknown): string[] { async function loadConfigUrls(api: Parameters[0]): Promise { try { - const configPath = api.state.path.config - const resp = await fetch(`file://${configPath}`) - if (!resp.ok) return [] - const text = await resp.text() - const config = parseJSONC(text) - return extractProviderUrls(config) - } catch { + debug(`loadConfigUrls: tuiConfig.provider=${JSON.stringify(Object.keys(api.tuiConfig.provider || {}))}`) + return extractProviderUrls(api.tuiConfig as unknown) + } catch (e) { + debug(`loadConfigUrls error: ${e}`) return [] } }