11{-# LANGUAGE DeriveLift #-}
2- {-# LANGUAGE LambdaCase #-}
32{-# LANGUAGE PatternGuards #-}
43{-# LANGUAGE RankNTypes #-}
54{-# LANGUAGE RecordWildCards #-}
@@ -51,6 +50,7 @@ import Prelude hiding (lines)
5150import Control.Applicative (Alternative ((<|>) ))
5251import Control.Monad
5352import Data.Char (isDigit , isLower , isSpace , isUpper , toLower )
53+ import Data.Foldable (toList )
5454import Data.List (find , foldl' )
5555import Data.List.NonEmpty (NonEmpty (.. ))
5656import qualified Data.List.NonEmpty as NEL
@@ -309,10 +309,10 @@ data UnboundEntityDef
309309 -- the field?" yet, so we defer those to the Template Haskell execution.
310310 --
311311 -- @since 2.13.0.0
312- , unboundEntityDefSpan :: Maybe Span
312+ , unboundEntityDefSourceSpan :: Maybe SourceSpan
313313 -- ^ The source code span of this entity in the models file.
314314 --
315- -- @since 2.15 .0.0
315+ -- @since 2.16 .0.0
316316 }
317317 deriving (Eq , Ord , Show , Lift )
318318
@@ -336,7 +336,7 @@ unbindEntityDef ed =
336336 ed
337337 , unboundEntityFields =
338338 map unbindFieldDef (entityFields ed)
339- , unboundEntityDefSpan = entitySpan ed
339+ , unboundEntityDefSourceSpan = entitySourceSpan ed
340340 }
341341
342342-- | Returns the @['UnboundFieldDef']@ for an 'UnboundEntityDef'. This returns
@@ -547,7 +547,7 @@ mkUnboundEntityDef ps parsedEntDef =
547547 DefaultKey (FieldNameDB $ psIdName ps)
548548 , unboundEntityFields =
549549 cols
550- , unboundEntityDefSpan = parsedEntityDefSpan parsedEntDef
550+ , unboundEntityDefSourceSpan = parsedEntityDefSourceSpan parsedEntDef
551551 , unboundEntityDef =
552552 EntityDef
553553 { entityHaskell = entNameHS
@@ -571,7 +571,7 @@ mkUnboundEntityDef ps parsedEntDef =
571571 case parsedEntityDefComments parsedEntDef of
572572 [] -> Nothing
573573 comments -> Just (T. unlines comments)
574- , entitySpan = parsedEntityDefSpan parsedEntDef
574+ , entitySourceSpan = parsedEntityDefSourceSpan parsedEntDef
575575 }
576576 }
577577 where
@@ -581,19 +581,11 @@ mkUnboundEntityDef ps parsedEntDef =
581581 attribs =
582582 parsedEntityDefFieldAttributes parsedEntDef
583583
584- fieldComments =
585- parsedEntityDefFieldComments parsedEntDef
586-
587584 cols :: [UnboundFieldDef ]
588- cols = foldMap (f . commentedField ps) (zip attribs fieldComments)
589- where
590- f = \ case
591- Just unb -> [unb]
592- _ -> []
585+ cols = foldMap (toList . commentedField ps) attribs
593586
594587 textAttribs :: [[Text ]]
595- textAttribs =
596- fmap tokenContent <$> attribs
588+ textAttribs = fmap tokenContent . fst <$> attribs
597589
598590 entityConstraintDefs =
599591 foldMap
@@ -612,6 +604,14 @@ mkUnboundEntityDef ps parsedEntDef =
612604 SetOnce a -> Just a
613605 NotSet -> Nothing
614606
607+ commentedField
608+ :: PersistSettings
609+ -> ([Token ], Maybe Text )
610+ -> Maybe UnboundFieldDef
611+ commentedField ps (tokens, mCommentText) = do
612+ unb <- takeColsEx ps (tokenContent <$> tokens)
613+ pure $ unb{unboundFieldComments = mCommentText}
614+
615615 autoIdField :: FieldDef
616616 autoIdField =
617617 mkAutoIdField ps entNameHS idSqlType
@@ -620,12 +620,6 @@ mkUnboundEntityDef ps parsedEntDef =
620620 idSqlType =
621621 maybe SqlInt64 (const $ SqlOther " Primary Key" ) primaryComposite
622622
623- commentedField
624- :: PersistSettings -> ([Token ], Maybe Text ) -> Maybe UnboundFieldDef
625- commentedField ps (tokens, mCommentText) = do
626- unb <- takeColsEx ps (tokenContent <$> tokens)
627- pure $ unb{unboundFieldComments = mCommentText}
628-
629623defaultIdName :: PersistSettings -> FieldNameDB
630624defaultIdName = FieldNameDB . psIdName
631625
0 commit comments