Skip to content

Commit 37af3fa

Browse files
committed
refactor: Split a text-id-based helper out of viewTreeType
1 parent 37d6391 commit 37af3fa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

primer/src/Primer/API.hs

+14-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import Control.Monad.Zip (MonadZip)
6363
import Data.Map qualified as Map
6464
import Data.Text qualified as T
6565
import ListT qualified (toList)
66-
import Optics (ifoldr, (^.))
66+
import Optics (ifoldr, over, view, (^.))
6767
import Primer.App (
6868
App,
6969
EditAppM,
@@ -110,6 +110,8 @@ import Primer.Core (
110110
defType,
111111
moduleNamePretty,
112112
unLocalName,
113+
_typeMeta,
114+
_typeMetaLens,
113115
)
114116
import Primer.Database (
115117
OffsetLimit,
@@ -668,7 +670,12 @@ viewTreeExpr e0 = case e0 of
668670

669671
-- | Similar to 'viewTreeExpr', but for 'Type's
670672
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
672679
TEmptyHole _ ->
673680
Tree
674681
{ nodeId
@@ -682,7 +689,7 @@ viewTreeType t0 = case t0 of
682689
{ nodeId
683690
, flavor = FlavorTHole
684691
, body = NoBody
685-
, childTrees = [viewTreeType t]
692+
, childTrees = [viewTreeType' t]
686693
, rightChild = Nothing
687694
}
688695
TCon _ n ->
@@ -698,7 +705,7 @@ viewTreeType t0 = case t0 of
698705
{ nodeId
699706
, flavor = FlavorTFun
700707
, body = NoBody
701-
, childTrees = [viewTreeType t1, viewTreeType t2]
708+
, childTrees = [viewTreeType' t1, viewTreeType' t2]
702709
, rightChild = Nothing
703710
}
704711
TVar _ n ->
@@ -714,15 +721,15 @@ viewTreeType t0 = case t0 of
714721
{ nodeId
715722
, flavor = FlavorTApp
716723
, body = NoBody
717-
, childTrees = [viewTreeType t1, viewTreeType t2]
724+
, childTrees = [viewTreeType' t1, viewTreeType' t2]
718725
, rightChild = Nothing
719726
}
720727
TForall _ n k t ->
721728
Tree
722729
{ nodeId
723730
, flavor = FlavorTForall
724731
, body = TextBody $ withKindAnn $ unName $ unLocalName n
725-
, childTrees = [viewTreeType t]
732+
, childTrees = [viewTreeType' t]
726733
, rightChild = Nothing
727734
}
728735
where
@@ -733,7 +740,7 @@ viewTreeType t0 = case t0 of
733740
KType -> identity
734741
_ -> (<> (" :: " <> show k))
735742
where
736-
nodeId = show $ t0 ^. _id
743+
nodeId = t0 ^. _typeMetaLens
737744

738745
showGlobal :: GlobalName k -> Text
739746
showGlobal n = moduleNamePretty (qualifiedModule n) <> "." <> unName (baseName n)

0 commit comments

Comments
 (0)