@@ -51,6 +51,7 @@ import Prelude hiding (lines)
5151import Control.Applicative (Alternative ((<|>) ))
5252import Control.Monad
5353import Data.Char (isDigit , isLower , isSpace , isUpper , toLower )
54+ import Data.Foldable (toList )
5455import Data.List (find , foldl' )
5556import Data.List.NonEmpty (NonEmpty (.. ))
5657import qualified Data.List.NonEmpty as NEL
@@ -309,10 +310,10 @@ data UnboundEntityDef
309310 -- the field?" yet, so we defer those to the Template Haskell execution.
310311 --
311312 -- @since 2.13.0.0
312- , unboundEntityDefSpan :: Maybe Span
313+ , unboundEntityDefSourceSpan :: Maybe SourceSpan
313314 -- ^ The source code span of this entity in the models file.
314315 --
315- -- @since 2.15 .0.0
316+ -- @since 2.16 .0.0
316317 }
317318 deriving (Eq , Ord , Show , Lift )
318319
@@ -336,7 +337,7 @@ unbindEntityDef ed =
336337 ed
337338 , unboundEntityFields =
338339 map unbindFieldDef (entityFields ed)
339- , unboundEntityDefSpan = entitySpan ed
340+ , unboundEntityDefSourceSpan = entitySourceSpan ed
340341 }
341342
342343-- | Returns the @['UnboundFieldDef']@ for an 'UnboundEntityDef'. This returns
@@ -547,7 +548,7 @@ mkUnboundEntityDef ps parsedEntDef =
547548 DefaultKey (FieldNameDB $ psIdName ps)
548549 , unboundEntityFields =
549550 cols
550- , unboundEntityDefSpan = parsedEntityDefSpan parsedEntDef
551+ , unboundEntityDefSourceSpan = parsedEntityDefSourceSpan parsedEntDef
551552 , unboundEntityDef =
552553 EntityDef
553554 { entityHaskell = entNameHS
@@ -571,7 +572,7 @@ mkUnboundEntityDef ps parsedEntDef =
571572 case parsedEntityDefComments parsedEntDef of
572573 [] -> Nothing
573574 comments -> Just (T. unlines comments)
574- , entitySpan = parsedEntityDefSpan parsedEntDef
575+ , entitySourceSpan = parsedEntityDefSourceSpan parsedEntDef
575576 }
576577 }
577578 where
@@ -581,19 +582,11 @@ mkUnboundEntityDef ps parsedEntDef =
581582 attribs =
582583 parsedEntityDefFieldAttributes parsedEntDef
583584
584- fieldComments =
585- parsedEntityDefFieldComments parsedEntDef
586-
587585 cols :: [UnboundFieldDef ]
588- cols = foldMap (f . commentedField ps) (zip attribs fieldComments)
589- where
590- f = \ case
591- Just unb -> [unb]
592- _ -> []
586+ cols = foldMap (toList . commentedField ps) attribs
593587
594588 textAttribs :: [[Text ]]
595- textAttribs =
596- fmap tokenContent <$> attribs
589+ textAttribs = (fmap tokenContent . fst ) <$> attribs
597590
598591 entityConstraintDefs =
599592 foldMap
@@ -612,6 +605,13 @@ mkUnboundEntityDef ps parsedEntDef =
612605 SetOnce a -> Just a
613606 NotSet -> Nothing
614607
608+ commentedField :: 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