Skip to content

Commit 7dd99e5

Browse files
committed
address some PR feedback
1 parent 120d513 commit 7dd99e5

8 files changed

Lines changed: 93 additions & 104 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: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE DeriveLift #-}
2-
{-# LANGUAGE LambdaCase #-}
32
{-# LANGUAGE PatternGuards #-}
43
{-# LANGUAGE RankNTypes #-}
54
{-# LANGUAGE RecordWildCards #-}
@@ -51,6 +50,7 @@ import Prelude hiding (lines)
5150
import Control.Applicative (Alternative ((<|>)))
5251
import Control.Monad
5352
import Data.Char (isDigit, isLower, isSpace, isUpper, toLower)
53+
import Data.Foldable (toList)
5454
import Data.List (find, foldl')
5555
import Data.List.NonEmpty (NonEmpty (..))
5656
import 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-
629623
defaultIdName :: PersistSettings -> FieldNameDB
630624
defaultIdName = FieldNameDB . psIdName
631625

0 commit comments

Comments
 (0)