@@ -63,7 +63,7 @@ import Control.Monad.Zip (MonadZip)
63
63
import Data.Map qualified as Map
64
64
import Data.Text qualified as T
65
65
import ListT qualified (toList )
66
- import Optics (ifoldr , (^.) )
66
+ import Optics (ifoldr , over , view , (^.) )
67
67
import Primer.App (
68
68
App ,
69
69
EditAppM ,
@@ -110,6 +110,8 @@ import Primer.Core (
110
110
defType ,
111
111
moduleNamePretty ,
112
112
unLocalName ,
113
+ _typeMeta ,
114
+ _typeMetaLens ,
113
115
)
114
116
import Primer.Database (
115
117
OffsetLimit ,
@@ -668,7 +670,12 @@ viewTreeExpr e0 = case e0 of
668
670
669
671
-- | Similar to 'viewTreeExpr', but for 'Type's
670
672
viewTreeType :: Type -> Tree
671
- viewTreeType t0 = case t0 of
673
+ viewTreeType = viewTreeType' . over _typeMeta (show . view _id)
674
+
675
+ -- | Like 'viewTreeType', but with the flexibility to accept arbitrary textual node identifiers,
676
+ -- rather than using the type's numeric IDs.
677
+ viewTreeType' :: Type' Text -> Tree
678
+ viewTreeType' t0 = case t0 of
672
679
TEmptyHole _ ->
673
680
Tree
674
681
{ nodeId
@@ -682,7 +689,7 @@ viewTreeType t0 = case t0 of
682
689
{ nodeId
683
690
, flavor = FlavorTHole
684
691
, body = NoBody
685
- , childTrees = [viewTreeType t]
692
+ , childTrees = [viewTreeType' t]
686
693
, rightChild = Nothing
687
694
}
688
695
TCon _ n ->
@@ -698,7 +705,7 @@ viewTreeType t0 = case t0 of
698
705
{ nodeId
699
706
, flavor = FlavorTFun
700
707
, body = NoBody
701
- , childTrees = [viewTreeType t1, viewTreeType t2]
708
+ , childTrees = [viewTreeType' t1, viewTreeType' t2]
702
709
, rightChild = Nothing
703
710
}
704
711
TVar _ n ->
@@ -714,15 +721,15 @@ viewTreeType t0 = case t0 of
714
721
{ nodeId
715
722
, flavor = FlavorTApp
716
723
, body = NoBody
717
- , childTrees = [viewTreeType t1, viewTreeType t2]
724
+ , childTrees = [viewTreeType' t1, viewTreeType' t2]
718
725
, rightChild = Nothing
719
726
}
720
727
TForall _ n k t ->
721
728
Tree
722
729
{ nodeId
723
730
, flavor = FlavorTForall
724
731
, body = TextBody $ withKindAnn $ unName $ unLocalName n
725
- , childTrees = [viewTreeType t]
732
+ , childTrees = [viewTreeType' t]
726
733
, rightChild = Nothing
727
734
}
728
735
where
@@ -733,7 +740,7 @@ viewTreeType t0 = case t0 of
733
740
KType -> identity
734
741
_ -> (<> (" :: " <> show k))
735
742
where
736
- nodeId = show $ t0 ^. _id
743
+ nodeId = t0 ^. _typeMetaLens
737
744
738
745
showGlobal :: GlobalName k -> Text
739
746
showGlobal n = moduleNamePretty (qualifiedModule n) <> " ." <> unName (baseName n)
0 commit comments