From: Javier Sagredo Date: Thu, 7 May 2026 00:19:41 +0000 (+0200) Subject: Show readable type-family flavor names in the side panel X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=dd8ef3b3313a5e281bbc74635af97bc4046b1547;p=classgraph.git Show readable type-family flavor names in the side panel Instead of the raw schema tags (OpenFam / ClosedFam / DataFam / AssocFam), the family panel now reads "Open type family", "Closed type family", "Data family", or "Associated type family (member of ParentClass (Module))". Falls back to whatever the tag string is for unknown flavours. Co-Authored-By: Claude Opus 4.7 (1M context) --- diff --git a/data/viewer.js b/data/viewer.js index 4920e0d..507a0c3 100644 --- a/data/viewer.js +++ b/data/viewer.js @@ -1777,19 +1777,43 @@ `; } + // Pretty-print a TypeFamilyFlavor as the user would expect to see + // it in source: "Open type family", "Closed type family", "Data + // family", "Associated type family (member of )". + // Falls back to whatever the raw tag string is for forwards- + // compatibility with future flavours. + function renderFlavor(flav) { + if (!flav) return ''; + const tag = typeof flav === 'string' ? flav : (flav.tag || ''); + switch (tag) { + case 'OpenFam': return 'Open type family'; + case 'ClosedFam': return 'Closed type family'; + case 'DataFam': return 'Data family'; + case 'AssocFam': { + const parent = flav.contents; + const parentName = parent && parent.qnName + ? parent.qnName + ' (' + (parent.qnModule || '') + ')' + : ''; + return parentName + ? 'Associated type family (member of ' + parentName + ')' + : 'Associated type family'; + } + default: return tag || JSON.stringify(flav); + } + } + function renderFamilyPanel(f) { const tvs = f.tfTyVars .map(v => `
  • ${escape(v.tvName)} :: ${escape(v.tvKind)}
  • `) .join(''); - const flav = (typeof f.tfFlavor === 'string') - ? f.tfFlavor : (f.tfFlavor.tag || JSON.stringify(f.tfFlavor)); + const flav = renderFlavor(f.tfFlavor); const src = renderDefinedAt(f.tfSrc, f.tfName.qnPackage); return `

    ${escape(f.tfName.qnName)}

    ${escape(f.tfName.qnPackage)} · ${escape(f.tfName.qnModule)}

    ${renderDocSection(f.tfDoc)} -
    Flavor
    ${escape(String(flav))}
    +
    Flavor
    ${escape(flav)}
    Type variables
      ${tvs}
    Result kind
    ${escape(f.tfResultKind)}
    Defined at
    ${src}