]> Repositorios git - classgraph.git/commitdiff
Show tyvars on class node labels
authorJavier Sagredo <[email protected]>
Wed, 6 May 2026 23:15:54 +0000 (01:15 +0200)
committerJavier Sagredo <[email protected]>
Wed, 6 May 2026 23:51:06 +0000 (01:51 +0200)
Class nodes now read "BftCrypto c" / "Bar a b" instead of just the
class name, in both the classes view (Render.hs's classNodes) and
the instance-view ensureClassNode helpers. External classes — for
which we don't know the tyvars — still fall back to the bare name.

Edge labels (the positional substitution into a superclass's args)
keep using the *origin* class's tyvar names via edgeLabel, so an
arrow `Bar a b ──(b)──► Foo b` reads consistently — same letter on
edge and target node.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
data/viewer.js
src/Classgraph/Render.hs

index f86a70540a8ebea64c3dc026bdf8391b5a2836c0..4e20c6d454adcd066309c40fab4f94aa95af56a2 100644 (file)
       if (seenNodes.has(id)) return id;
       seenNodes.add(id);
       const known = classById.get(id);
+      // Include the class's tyvars in the label when we have them
+      // (i.e. the class is defined in this project). External classes
+      // fall back to bare qnName — we don't have their tyvars here.
+      const label = (known && known.ciTyVars && known.ciTyVars.length > 0)
+        ? known.ciName.qnName + ' ' + known.ciTyVars.map(tv => tv.tvName).join(' ')
+        : qn.qnName;
       els.push({ group: 'nodes', data: Object.assign({
         id,
-        label: qn.qnName,
+        label,
         kind: 'class',
         external: !known,
         package: qn.qnPackage,
       if (seenNodes.has(id)) return id;
       seenNodes.add(id);
       const known = classById.get(id);
+      const label = (known && known.ciTyVars && known.ciTyVars.length > 0)
+        ? known.ciName.qnName + ' ' + known.ciTyVars.map(tv => tv.tvName).join(' ')
+        : qn.qnName;
       els.push({ group: 'nodes', data: {
         id,
-        label: qn.qnName,
+        label,
         kind: 'class',
         external: !known,
         package: qn.qnPackage,
index b6e943680e071a55fcf811c8867f15a614eb5c56..ff149bd0ade1200f925f4812c8636820a3455bf3 100644 (file)
@@ -118,7 +118,7 @@ buildGraph pd sourceRoots = CyGraph
     classNodes =
       [ CyNode $ Aeson.object
           [ "id"      Aeson..= renderQualName (ciName c)
-          , "label"   Aeson..= qnName (ciName c)
+          , "label"   Aeson..= classNodeLabel c
           , "kind"    Aeson..= ("class" :: Text)
           , "module"  Aeson..= qnModule (ciName c)
           , "package" Aeson..= qnPackage (ciName c)
@@ -129,6 +129,17 @@ buildGraph pd sourceRoots = CyGraph
       | c <- pdClasses pd
       ]
 
+    -- A class node renders as `Foo a b c`, with the same names the
+    -- user wrote. Edge labels (positional substitution into a
+    -- superclass's args) keep using the *origin* class's tyvar names
+    -- via 'edgeLabel', so an arrow from `Bar a b` up to `Foo a` reads
+    -- as `(a)` on the edge and `Foo a` on the target node — same
+    -- letter, no aliasing.
+    classNodeLabel c = case ciTyVars c of
+      []  -> qnName (ciName c)
+      tvs -> qnName (ciName c) <> " "
+               <> T.intercalate " " (map tvName tvs)
+
     familyNodes =
       [ CyNode $ Aeson.object
           [ "id"      Aeson..= renderQualName (tfName f)