Skip to content

Commit 9e7ba7d

Browse files
committed
address some PR feedback
1 parent 120d513 commit 9e7ba7d

8 files changed

Lines changed: 94 additions & 106 deletions

File tree

persistent/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog for persistent
22

3-
# 2.15.1.1
3+
# 2.16.0.0
44

55
* [#1584](https://github.com/yesodweb/persistent/pull/1584)
6+
* Rename `Span` to `SourceSpan`
67
* Parse entity definitions using Megaparsec.
78
* Support Haddock-style multiline pre-comments.
89

persistent/Database/Persist/EntityDef.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Database.Persist.EntityDef
1919
, getEntityKeyFields
2020
, getEntityComments
2121
, getEntityExtra
22-
, getEntitySpan
22+
, getEntitySourceSpan
2323
, isEntitySum
2424
, entityPrimary
2525
, entitiesPrimary
@@ -43,7 +43,7 @@ import Database.Persist.FieldDef
4343

4444
import Database.Persist.Names
4545
import Database.Persist.Types.Base
46-
(ForeignDef, Span, UniqueDef(..), entityKeyFields)
46+
(ForeignDef, SourceSpan, UniqueDef(..), entityKeyFields)
4747

4848
-- | Retrieve the list of 'UniqueDef' from an 'EntityDef'. This does not include
4949
-- a @Primary@ key, if one is defined. A future version of @persistent@ will
@@ -209,12 +209,12 @@ overEntityFields
209209
overEntityFields f ed =
210210
setEntityFields (f (getEntityFieldsDatabase ed)) ed
211211

212-
-- | Gets the 'Span' of the definition of the entity.
212+
-- | Gets the 'SourceSpan' of the definition of the entity.
213213
--
214214
-- Note that as of this writing the span covers the entire file or quasiquote
215215
-- where the item is defined due to parsing limitations. This may be changed in
216216
-- a future release to be more accurate.
217217
--
218-
-- @since 2.15.0.0
219-
getEntitySpan :: EntityDef -> Maybe Span
220-
getEntitySpan = entitySpan
218+
-- @since 2.16.0.0
219+
getEntitySourceSpan :: EntityDef -> Maybe SourceSpan
220+
getEntitySourceSpan = entitySourceSpan

persistent/Database/Persist/Quasi/Internal.hs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Prelude hiding (lines)
5151
import Control.Applicative (Alternative ((<|>)))
5252
import Control.Monad
5353
import Data.Char (isDigit, isLower, isSpace, isUpper, toLower)
54+
import Data.Foldable (toList)
5455
import Data.List (find, foldl')
5556
import Data.List.NonEmpty (NonEmpty (..))
5657
import 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-
629623
defaultIdName :: PersistSettings -> FieldNameDB
630624
defaultIdName = FieldNameDB . psIdName
631625

0 commit comments

Comments
 (0)