{-# LANGUAGE DeriveGeneric #-} module Unison.Codebase.Editor.DisplayObject where import Data.Bifoldable import Data.Bitraversable import Data.Set qualified as Set import U.Codebase.Reference (TermReference, TypeReference) import Unison.DataDeclaration qualified as DD import Unison.DataDeclaration.Dependencies qualified as DD import Unison.LabeledDependency qualified as LD import Unison.Parser.Ann (Ann) import Unison.Prelude import Unison.ShortHash (ShortHash) import Unison.Symbol (Symbol) import Unison.Term (Term) import Unison.Term qualified as Term import Unison.Type (Type) import Unison.Type qualified as Type data DisplayObject b a = BuiltinObject b | MissingObject ShortHash | UserObject a deriving (DisplayObject b a -> DisplayObject b a -> Bool (DisplayObject b a -> DisplayObject b a -> Bool) -> (DisplayObject b a -> DisplayObject b a -> Bool) -> Eq (DisplayObject b a) forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a forall b a. (Eq b, Eq a) => DisplayObject b a -> DisplayObject b a -> Bool $c== :: forall b a. (Eq b, Eq a) => DisplayObject b a -> DisplayObject b a -> Bool == :: DisplayObject b a -> DisplayObject b a -> Bool $c/= :: forall b a. (Eq b, Eq a) => DisplayObject b a -> DisplayObject b a -> Bool /= :: DisplayObject b a -> DisplayObject b a -> Bool Eq, Eq (DisplayObject b a) Eq (DisplayObject b a) => (DisplayObject b a -> DisplayObject b a -> Ordering) -> (DisplayObject b a -> DisplayObject b a -> Bool) -> (DisplayObject b a -> DisplayObject b a -> Bool) -> (DisplayObject b a -> DisplayObject b a -> Bool) -> (DisplayObject b a -> DisplayObject b a -> Bool) -> (DisplayObject b a -> DisplayObject b a -> DisplayObject b a) -> (DisplayObject b a -> DisplayObject b a -> DisplayObject b a) -> Ord (DisplayObject b a) DisplayObject b a -> DisplayObject b a -> Bool DisplayObject b a -> DisplayObject b a -> Ordering DisplayObject b a -> DisplayObject b a -> DisplayObject b a forall a. Eq a => (a -> a -> Ordering) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> a) -> (a -> a -> a) -> Ord a forall b a. (Ord b, Ord a) => Eq (DisplayObject b a) forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Bool forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Ordering forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> DisplayObject b a $ccompare :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Ordering compare :: DisplayObject b a -> DisplayObject b a -> Ordering $c< :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Bool < :: DisplayObject b a -> DisplayObject b a -> Bool $c<= :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Bool <= :: DisplayObject b a -> DisplayObject b a -> Bool $c> :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Bool > :: DisplayObject b a -> DisplayObject b a -> Bool $c>= :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> Bool >= :: DisplayObject b a -> DisplayObject b a -> Bool $cmax :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> DisplayObject b a max :: DisplayObject b a -> DisplayObject b a -> DisplayObject b a $cmin :: forall b a. (Ord b, Ord a) => DisplayObject b a -> DisplayObject b a -> DisplayObject b a min :: DisplayObject b a -> DisplayObject b a -> DisplayObject b a Ord, Int -> DisplayObject b a -> ShowS [DisplayObject b a] -> ShowS DisplayObject b a -> String (Int -> DisplayObject b a -> ShowS) -> (DisplayObject b a -> String) -> ([DisplayObject b a] -> ShowS) -> Show (DisplayObject b a) forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a forall b a. (Show b, Show a) => Int -> DisplayObject b a -> ShowS forall b a. (Show b, Show a) => [DisplayObject b a] -> ShowS forall b a. (Show b, Show a) => DisplayObject b a -> String $cshowsPrec :: forall b a. (Show b, Show a) => Int -> DisplayObject b a -> ShowS showsPrec :: Int -> DisplayObject b a -> ShowS $cshow :: forall b a. (Show b, Show a) => DisplayObject b a -> String show :: DisplayObject b a -> String $cshowList :: forall b a. (Show b, Show a) => [DisplayObject b a] -> ShowS showList :: [DisplayObject b a] -> ShowS Show, (forall a b. (a -> b) -> DisplayObject b a -> DisplayObject b b) -> (forall a b. a -> DisplayObject b b -> DisplayObject b a) -> Functor (DisplayObject b) forall a b. a -> DisplayObject b b -> DisplayObject b a forall a b. (a -> b) -> DisplayObject b a -> DisplayObject b b forall b a b. a -> DisplayObject b b -> DisplayObject b a forall b a b. (a -> b) -> DisplayObject b a -> DisplayObject b b forall (f :: * -> *). (forall a b. (a -> b) -> f a -> f b) -> (forall a b. a -> f b -> f a) -> Functor f $cfmap :: forall b a b. (a -> b) -> DisplayObject b a -> DisplayObject b b fmap :: forall a b. (a -> b) -> DisplayObject b a -> DisplayObject b b $c<$ :: forall b a b. a -> DisplayObject b b -> DisplayObject b a <$ :: forall a b. a -> DisplayObject b b -> DisplayObject b a Functor, (forall x. DisplayObject b a -> Rep (DisplayObject b a) x) -> (forall x. Rep (DisplayObject b a) x -> DisplayObject b a) -> Generic (DisplayObject b a) forall x. Rep (DisplayObject b a) x -> DisplayObject b a forall x. DisplayObject b a -> Rep (DisplayObject b a) x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a forall b a x. Rep (DisplayObject b a) x -> DisplayObject b a forall b a x. DisplayObject b a -> Rep (DisplayObject b a) x $cfrom :: forall b a x. DisplayObject b a -> Rep (DisplayObject b a) x from :: forall x. DisplayObject b a -> Rep (DisplayObject b a) x $cto :: forall b a x. Rep (DisplayObject b a) x -> DisplayObject b a to :: forall x. Rep (DisplayObject b a) x -> DisplayObject b a Generic, (forall m. Monoid m => DisplayObject b m -> m) -> (forall m a. Monoid m => (a -> m) -> DisplayObject b a -> m) -> (forall m a. Monoid m => (a -> m) -> DisplayObject b a -> m) -> (forall a b. (a -> b -> b) -> b -> DisplayObject b a -> b) -> (forall a b. (a -> b -> b) -> b -> DisplayObject b a -> b) -> (forall b a. (b -> a -> b) -> b -> DisplayObject b a -> b) -> (forall b a. (b -> a -> b) -> b -> DisplayObject b a -> b) -> (forall a. (a -> a -> a) -> DisplayObject b a -> a) -> (forall a. (a -> a -> a) -> DisplayObject b a -> a) -> (forall a. DisplayObject b a -> [a]) -> (forall a. DisplayObject b a -> Bool) -> (forall a. DisplayObject b a -> Int) -> (forall a. Eq a => a -> DisplayObject b a -> Bool) -> (forall a. Ord a => DisplayObject b a -> a) -> (forall a. Ord a => DisplayObject b a -> a) -> (forall a. Num a => DisplayObject b a -> a) -> (forall a. Num a => DisplayObject b a -> a) -> Foldable (DisplayObject b) forall a. Eq a => a -> DisplayObject b a -> Bool forall a. Num a => DisplayObject b a -> a forall a. Ord a => DisplayObject b a -> a forall m. Monoid m => DisplayObject b m -> m forall a. DisplayObject b a -> Bool forall a. DisplayObject b a -> Int forall a. DisplayObject b a -> [a] forall a. (a -> a -> a) -> DisplayObject b a -> a forall b a. Eq a => a -> DisplayObject b a -> Bool forall b a. Num a => DisplayObject b a -> a forall b a. Ord a => DisplayObject b a -> a forall m a. Monoid m => (a -> m) -> DisplayObject b a -> m forall b m. Monoid m => DisplayObject b m -> m forall b a. DisplayObject b a -> Bool forall b a. DisplayObject b a -> Int forall b a. DisplayObject b a -> [a] forall b a. (b -> a -> b) -> b -> DisplayObject b a -> b forall a b. (a -> b -> b) -> b -> DisplayObject b a -> b forall b a. (a -> a -> a) -> DisplayObject b a -> a forall b m a. Monoid m => (a -> m) -> DisplayObject b a -> m forall b b a. (b -> a -> b) -> b -> DisplayObject b a -> b forall b a b. (a -> b -> b) -> b -> DisplayObject b a -> b forall (t :: * -> *). (forall m. Monoid m => t m -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. t a -> [a]) -> (forall a. t a -> Bool) -> (forall a. t a -> Int) -> (forall a. Eq a => a -> t a -> Bool) -> (forall a. Ord a => t a -> a) -> (forall a. Ord a => t a -> a) -> (forall a. Num a => t a -> a) -> (forall a. Num a => t a -> a) -> Foldable t $cfold :: forall b m. Monoid m => DisplayObject b m -> m fold :: forall m. Monoid m => DisplayObject b m -> m $cfoldMap :: forall b m a. Monoid m => (a -> m) -> DisplayObject b a -> m foldMap :: forall m a. Monoid m => (a -> m) -> DisplayObject b a -> m $cfoldMap' :: forall b m a. Monoid m => (a -> m) -> DisplayObject b a -> m foldMap' :: forall m a. Monoid m => (a -> m) -> DisplayObject b a -> m $cfoldr :: forall b a b. (a -> b -> b) -> b -> DisplayObject b a -> b foldr :: forall a b. (a -> b -> b) -> b -> DisplayObject b a -> b $cfoldr' :: forall b a b. (a -> b -> b) -> b -> DisplayObject b a -> b foldr' :: forall a b. (a -> b -> b) -> b -> DisplayObject b a -> b $cfoldl :: forall b b a. (b -> a -> b) -> b -> DisplayObject b a -> b foldl :: forall b a. (b -> a -> b) -> b -> DisplayObject b a -> b $cfoldl' :: forall b b a. (b -> a -> b) -> b -> DisplayObject b a -> b foldl' :: forall b a. (b -> a -> b) -> b -> DisplayObject b a -> b $cfoldr1 :: forall b a. (a -> a -> a) -> DisplayObject b a -> a foldr1 :: forall a. (a -> a -> a) -> DisplayObject b a -> a $cfoldl1 :: forall b a. (a -> a -> a) -> DisplayObject b a -> a foldl1 :: forall a. (a -> a -> a) -> DisplayObject b a -> a $ctoList :: forall b a. DisplayObject b a -> [a] toList :: forall a. DisplayObject b a -> [a] $cnull :: forall b a. DisplayObject b a -> Bool null :: forall a. DisplayObject b a -> Bool $clength :: forall b a. DisplayObject b a -> Int length :: forall a. DisplayObject b a -> Int $celem :: forall b a. Eq a => a -> DisplayObject b a -> Bool elem :: forall a. Eq a => a -> DisplayObject b a -> Bool $cmaximum :: forall b a. Ord a => DisplayObject b a -> a maximum :: forall a. Ord a => DisplayObject b a -> a $cminimum :: forall b a. Ord a => DisplayObject b a -> a minimum :: forall a. Ord a => DisplayObject b a -> a $csum :: forall b a. Num a => DisplayObject b a -> a sum :: forall a. Num a => DisplayObject b a -> a $cproduct :: forall b a. Num a => DisplayObject b a -> a product :: forall a. Num a => DisplayObject b a -> a Foldable, Functor (DisplayObject b) Foldable (DisplayObject b) (Functor (DisplayObject b), Foldable (DisplayObject b)) => (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> DisplayObject b a -> f (DisplayObject b b)) -> (forall (f :: * -> *) a. Applicative f => DisplayObject b (f a) -> f (DisplayObject b a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> DisplayObject b a -> m (DisplayObject b b)) -> (forall (m :: * -> *) a. Monad m => DisplayObject b (m a) -> m (DisplayObject b a)) -> Traversable (DisplayObject b) forall b. Functor (DisplayObject b) forall b. Foldable (DisplayObject b) forall b (m :: * -> *) a. Monad m => DisplayObject b (m a) -> m (DisplayObject b a) forall b (f :: * -> *) a. Applicative f => DisplayObject b (f a) -> f (DisplayObject b a) forall b (m :: * -> *) a b. Monad m => (a -> m b) -> DisplayObject b a -> m (DisplayObject b b) forall b (f :: * -> *) a b. Applicative f => (a -> f b) -> DisplayObject b a -> f (DisplayObject b b) forall (t :: * -> *). (Functor t, Foldable t) => (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> t a -> f (t b)) -> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> t a -> m (t b)) -> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a)) -> Traversable t forall (m :: * -> *) a. Monad m => DisplayObject b (m a) -> m (DisplayObject b a) forall (f :: * -> *) a. Applicative f => DisplayObject b (f a) -> f (DisplayObject b a) forall (m :: * -> *) a b. Monad m => (a -> m b) -> DisplayObject b a -> m (DisplayObject b b) forall (f :: * -> *) a b. Applicative f => (a -> f b) -> DisplayObject b a -> f (DisplayObject b b) $ctraverse :: forall b (f :: * -> *) a b. Applicative f => (a -> f b) -> DisplayObject b a -> f (DisplayObject b b) traverse :: forall (f :: * -> *) a b. Applicative f => (a -> f b) -> DisplayObject b a -> f (DisplayObject b b) $csequenceA :: forall b (f :: * -> *) a. Applicative f => DisplayObject b (f a) -> f (DisplayObject b a) sequenceA :: forall (f :: * -> *) a. Applicative f => DisplayObject b (f a) -> f (DisplayObject b a) $cmapM :: forall b (m :: * -> *) a b. Monad m => (a -> m b) -> DisplayObject b a -> m (DisplayObject b b) mapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> DisplayObject b a -> m (DisplayObject b b) $csequence :: forall b (m :: * -> *) a. Monad m => DisplayObject b (m a) -> m (DisplayObject b a) sequence :: forall (m :: * -> *) a. Monad m => DisplayObject b (m a) -> m (DisplayObject b a) Traversable) instance Bifunctor DisplayObject where bimap :: forall a b c d. (a -> b) -> (c -> d) -> DisplayObject a c -> DisplayObject b d bimap a -> b _ c -> d _ (MissingObject ShortHash sh) = ShortHash -> DisplayObject b d forall b a. ShortHash -> DisplayObject b a MissingObject ShortHash sh bimap a -> b f c -> d _ (BuiltinObject a b) = b -> DisplayObject b d forall b a. b -> DisplayObject b a BuiltinObject (a -> b f a b) bimap a -> b _ c -> d f (UserObject c a) = d -> DisplayObject b d forall b a. a -> DisplayObject b a UserObject (c -> d f c a) instance Bitraversable DisplayObject where bitraverse :: forall (f :: * -> *) a c b d. Applicative f => (a -> f c) -> (b -> f d) -> DisplayObject a b -> f (DisplayObject c d) bitraverse a -> f c f b -> f d _ (BuiltinObject a b) = c -> DisplayObject c d forall b a. b -> DisplayObject b a BuiltinObject (c -> DisplayObject c d) -> f c -> f (DisplayObject c d) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> a -> f c f a b bitraverse a -> f c _ b -> f d _ (MissingObject ShortHash sh) = DisplayObject c d -> f (DisplayObject c d) forall a. a -> f a forall (f :: * -> *) a. Applicative f => a -> f a pure (ShortHash -> DisplayObject c d forall b a. ShortHash -> DisplayObject b a MissingObject ShortHash sh) bitraverse a -> f c _ b -> f d g (UserObject b a) = d -> DisplayObject c d forall b a. a -> DisplayObject b a UserObject (d -> DisplayObject c d) -> f d -> f (DisplayObject c d) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> b -> f d g b a instance Bifoldable DisplayObject where bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> DisplayObject a b -> m bifoldMap = (a -> m) -> (b -> m) -> DisplayObject a b -> m forall (t :: * -> * -> *) m a b. (Bitraversable t, Monoid m) => (a -> m) -> (b -> m) -> t a b -> m bifoldMapDefault toMaybe :: DisplayObject b a -> Maybe a toMaybe :: forall b a. DisplayObject b a -> Maybe a toMaybe = \case UserObject a a -> a -> Maybe a forall a. a -> Maybe a Just a a DisplayObject b a _ -> Maybe a forall a. Maybe a Nothing termDisplayObjectLabeledDependencies :: TermReference -> DisplayObject (Type Symbol Ann) (Term Symbol Ann) -> (Set LD.LabeledDependency) termDisplayObjectLabeledDependencies :: TermReference -> DisplayObject (Type Symbol Ann) (Term Symbol Ann) -> Set LabeledDependency termDisplayObjectLabeledDependencies TermReference termRef DisplayObject (Type Symbol Ann) (Term Symbol Ann) displayObject = do DisplayObject (Type Symbol Ann) (Term Symbol Ann) displayObject DisplayObject (Type Symbol Ann) (Term Symbol Ann) -> (DisplayObject (Type Symbol Ann) (Term Symbol Ann) -> Set LabeledDependency) -> Set LabeledDependency forall a b. a -> (a -> b) -> b & (Type Symbol Ann -> Set LabeledDependency) -> (Term Symbol Ann -> Set LabeledDependency) -> DisplayObject (Type Symbol Ann) (Term Symbol Ann) -> Set LabeledDependency forall m a b. Monoid m => (a -> m) -> (b -> m) -> DisplayObject a b -> m forall (p :: * -> * -> *) m a b. (Bifoldable p, Monoid m) => (a -> m) -> (b -> m) -> p a b -> m bifoldMap (Type Symbol Ann -> Set LabeledDependency forall v a. Ord v => Type v a -> Set LabeledDependency Type.labeledDependencies) (Term Symbol Ann -> Set LabeledDependency forall v vt at ap a. (Ord v, Ord vt) => Term2 vt at ap v a -> Set LabeledDependency Term.labeledDependencies) Set LabeledDependency -> (Set LabeledDependency -> Set LabeledDependency) -> Set LabeledDependency forall a b. a -> (a -> b) -> b & LabeledDependency -> Set LabeledDependency -> Set LabeledDependency forall a. Ord a => a -> Set a -> Set a Set.insert (TermReference -> LabeledDependency LD.TermReference TermReference termRef) typeDisplayObjectLabeledDependencies :: TypeReference -> DisplayObject () (DD.Decl Symbol Ann) -> Set LD.LabeledDependency typeDisplayObjectLabeledDependencies :: TermReference -> DisplayObject () (Decl Symbol Ann) -> Set LabeledDependency typeDisplayObjectLabeledDependencies TermReference typeRef DisplayObject () (Decl Symbol Ann) displayObject = do DisplayObject () (Decl Symbol Ann) displayObject DisplayObject () (Decl Symbol Ann) -> (DisplayObject () (Decl Symbol Ann) -> Set LabeledDependency) -> Set LabeledDependency forall a b. a -> (a -> b) -> b & (Decl Symbol Ann -> Set LabeledDependency) -> DisplayObject () (Decl Symbol Ann) -> Set LabeledDependency forall m a. Monoid m => (a -> m) -> DisplayObject () a -> m forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap (TermReference -> Decl Symbol Ann -> Set LabeledDependency forall v a. Var v => TermReference -> Decl v a -> Set LabeledDependency DD.labeledDeclDependenciesIncludingSelfAndFieldAccessors TermReference typeRef)