module TD.Data.TextRanges
(TextRanges(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.TextRange as TextRange
data
=
{ TextRanges -> Maybe [TextRange]
ranges :: Maybe [TextRange.TextRange]
}
deriving (TextRanges -> TextRanges -> Bool
(TextRanges -> TextRanges -> Bool)
-> (TextRanges -> TextRanges -> Bool) -> Eq TextRanges
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextRanges -> TextRanges -> Bool
== :: TextRanges -> TextRanges -> Bool
$c/= :: TextRanges -> TextRanges -> Bool
/= :: TextRanges -> TextRanges -> Bool
Eq, Int -> TextRanges -> ShowS
[TextRanges] -> ShowS
TextRanges -> String
(Int -> TextRanges -> ShowS)
-> (TextRanges -> String)
-> ([TextRanges] -> ShowS)
-> Show TextRanges
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextRanges -> ShowS
showsPrec :: Int -> TextRanges -> ShowS
$cshow :: TextRanges -> String
show :: TextRanges -> String
$cshowList :: [TextRanges] -> ShowS
showList :: [TextRanges] -> ShowS
Show)
instance I.ShortShow TextRanges where
shortShow :: TextRanges -> String
shortShow TextRanges
{ ranges :: TextRanges -> Maybe [TextRange]
ranges = Maybe [TextRange]
ranges_
}
= String
"TextRanges"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"ranges" String -> Maybe [TextRange] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [TextRange]
ranges_
]
instance AT.FromJSON TextRanges where
parseJSON :: Value -> Parser TextRanges
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"textRanges" -> Value -> Parser TextRanges
parseTextRanges Value
v
String
_ -> Parser TextRanges
forall a. Monoid a => a
mempty
where
parseTextRanges :: A.Value -> AT.Parser TextRanges
parseTextRanges :: Value -> Parser TextRanges
parseTextRanges = String
-> (Object -> Parser TextRanges) -> Value -> Parser TextRanges
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TextRanges" ((Object -> Parser TextRanges) -> Value -> Parser TextRanges)
-> (Object -> Parser TextRanges) -> Value -> Parser TextRanges
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [TextRange]
ranges_ <- Object
o Object -> Key -> Parser (Maybe [TextRange])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"ranges"
TextRanges -> Parser TextRanges
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TextRanges -> Parser TextRanges)
-> TextRanges -> Parser TextRanges
forall a b. (a -> b) -> a -> b
$ TextRanges
{ ranges :: Maybe [TextRange]
ranges = Maybe [TextRange]
ranges_
}
parseJSON Value
_ = Parser TextRanges
forall a. Monoid a => a
mempty