remove dead parseJSONC code

This commit is contained in:
Troed Sångberg
2026-06-16 13:49:19 +02:00
parent e626e7259a
commit ed86d506bb
+4 -71
View File
@@ -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<TuiPlugin>[0]): Promise<string[]> {
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 []
}
}