]> Repositorios git - classgraph.git/commitdiff
Show readable type-family flavor names in the side panel
authorJavier Sagredo <[email protected]>
Thu, 7 May 2026 00:19:41 +0000 (02:19 +0200)
committerJavier Sagredo <[email protected]>
Thu, 7 May 2026 00:19:41 +0000 (02:19 +0200)
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) <[email protected]>
data/viewer.js

index 4920e0d5e56e868714b74e63e92d86d1bc6b1fb1..507a0c32f0c34c4be9633c524236975219654bee 100644 (file)
       </dl>`;
   }
 
+  // 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 <parent class>)".
+  // 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 => `<li>${escape(v.tvName)}<span style="color:#888"> :: ${escape(v.tvKind)}</span></li>`)
       .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 `
       <h2>${escape(f.tfName.qnName)}</h2>
       <p class="pkgmod">${escape(f.tfName.qnPackage)} ยท ${escape(f.tfName.qnModule)}</p>
       <dl>
         ${renderDocSection(f.tfDoc)}
-        <dt>Flavor</dt><dd>${escape(String(flav))}</dd>
+        <dt>Flavor</dt><dd>${escape(flav)}</dd>
         <dt>Type variables</dt><dd><ul>${tvs}</ul></dd>
         <dt>Result kind</dt><dd>${escape(f.tfResultKind)}</dd>
         <dt>Defined at</dt>${src}