export function getLocalTailwindSettings(this: void) { const vscodeSettingsPath = ".vscode/settings.json"; if (vim.fn.filereadable(vscodeSettingsPath) !== 1) return {}; const file = vim.fn.readfile(vscodeSettingsPath) as string[]; const vscodeSettings = safeDecode<{ tailwindCSS: Record }>( // eslint-disable-next-line unicorn/prefer-spread table.concat(file), ); if (vscodeSettings === false) { vim.print( "Failed to load '.vscode/settings.json': invalid JSON syntax.", ); return {}; } const twSettings: { [key: string]: Record | string; } = {}; for (const [key, value] of Object.entries(vscodeSettings)) { if (!key.startsWith("tailwindCSS")) continue; let current = twSettings; const sections = key.split("."); for (let index = 0; index < sections.length; index++) { const section = sections[index]; const isLast = index === sections.length - 1; current[section] = isLast ? transformValue(key, value) : current[section] || {}; if (!isLast) { // @ts-expect-error dont wanna fix rn current = current[section]; } } } return twSettings.tailwindCSS || {}; } function safeDecode(this: void, input: string) { try { return vim.json.decode(input) as T; } catch { return false; } } function transformValue( this: void, key: string, value: Record | string, transform = (input: string) => `${vim.fn.getcwd()}/${input}`, ) { if (!key.endsWith("configFile")) return value; if (typeof value === "string") return transform(value); const transformed: Record = {}; for (const [currentKey, current] of Object.entries(value)) { transformed[transform(currentKey)] = transform(current); } return transformed; }