{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Language.LSP.Types.MarkupContent where
import Data.Aeson
import Data.Aeson.TH
import Data.Text (Text)
import qualified Data.Text as T
import Language.LSP.Types.Utils
data MarkupKind = MkPlainText
| MkMarkdown
deriving (ReadPrec [MarkupKind]
ReadPrec MarkupKind
Int -> ReadS MarkupKind
ReadS [MarkupKind]
(Int -> ReadS MarkupKind)
-> ReadS [MarkupKind]
-> ReadPrec MarkupKind
-> ReadPrec [MarkupKind]
-> Read MarkupKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS MarkupKind
readsPrec :: Int -> ReadS MarkupKind
$creadList :: ReadS [MarkupKind]
readList :: ReadS [MarkupKind]
$creadPrec :: ReadPrec MarkupKind
readPrec :: ReadPrec MarkupKind
$creadListPrec :: ReadPrec [MarkupKind]
readListPrec :: ReadPrec [MarkupKind]
Read, Int -> MarkupKind -> ShowS
[MarkupKind] -> ShowS
MarkupKind -> String
(Int -> MarkupKind -> ShowS)
-> (MarkupKind -> String)
-> ([MarkupKind] -> ShowS)
-> Show MarkupKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MarkupKind -> ShowS
showsPrec :: Int -> MarkupKind -> ShowS
$cshow :: MarkupKind -> String
show :: MarkupKind -> String
$cshowList :: [MarkupKind] -> ShowS
showList :: [MarkupKind] -> ShowS
Show, MarkupKind -> MarkupKind -> Bool
(MarkupKind -> MarkupKind -> Bool)
-> (MarkupKind -> MarkupKind -> Bool) -> Eq MarkupKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MarkupKind -> MarkupKind -> Bool
== :: MarkupKind -> MarkupKind -> Bool
$c/= :: MarkupKind -> MarkupKind -> Bool
/= :: MarkupKind -> MarkupKind -> Bool
Eq)
instance ToJSON MarkupKind where
toJSON :: MarkupKind -> Value
toJSON MarkupKind
MkPlainText = Text -> Value
String Text
"plaintext"
toJSON MarkupKind
MkMarkdown = Text -> Value
String Text
"markdown"
instance FromJSON MarkupKind where
parseJSON :: Value -> Parser MarkupKind
parseJSON (String Text
"plaintext") = MarkupKind -> Parser MarkupKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MarkupKind
MkPlainText
parseJSON (String Text
"markdown") = MarkupKind -> Parser MarkupKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MarkupKind
MkMarkdown
parseJSON Value
_ = String -> Parser MarkupKind
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"MarkupKind"
data MarkupContent =
MarkupContent
{ MarkupContent -> MarkupKind
_kind :: MarkupKind
, MarkupContent -> Text
_value :: Text
}
deriving (ReadPrec [MarkupContent]
ReadPrec MarkupContent
Int -> ReadS MarkupContent
ReadS [MarkupContent]
(Int -> ReadS MarkupContent)
-> ReadS [MarkupContent]
-> ReadPrec MarkupContent
-> ReadPrec [MarkupContent]
-> Read MarkupContent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS MarkupContent
readsPrec :: Int -> ReadS MarkupContent
$creadList :: ReadS [MarkupContent]
readList :: ReadS [MarkupContent]
$creadPrec :: ReadPrec MarkupContent
readPrec :: ReadPrec MarkupContent
$creadListPrec :: ReadPrec [MarkupContent]
readListPrec :: ReadPrec [MarkupContent]
Read, Int -> MarkupContent -> ShowS
[MarkupContent] -> ShowS
MarkupContent -> String
(Int -> MarkupContent -> ShowS)
-> (MarkupContent -> String)
-> ([MarkupContent] -> ShowS)
-> Show MarkupContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MarkupContent -> ShowS
showsPrec :: Int -> MarkupContent -> ShowS
$cshow :: MarkupContent -> String
show :: MarkupContent -> String
$cshowList :: [MarkupContent] -> ShowS
showList :: [MarkupContent] -> ShowS
Show, MarkupContent -> MarkupContent -> Bool
(MarkupContent -> MarkupContent -> Bool)
-> (MarkupContent -> MarkupContent -> Bool) -> Eq MarkupContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MarkupContent -> MarkupContent -> Bool
== :: MarkupContent -> MarkupContent -> Bool
$c/= :: MarkupContent -> MarkupContent -> Bool
/= :: MarkupContent -> MarkupContent -> Bool
Eq)
deriveJSON lspOptions ''MarkupContent
markedUpContent :: Text -> Text -> MarkupContent
markedUpContent :: Text -> Text -> MarkupContent
markedUpContent Text
lang Text
quote
= MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkMarkdown (Text
"\n```" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lang Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
quote Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n```\n")
unmarkedUpContent :: Text -> MarkupContent
unmarkedUpContent :: Text -> MarkupContent
unmarkedUpContent Text
str = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkPlainText Text
str
sectionSeparator :: Text
sectionSeparator :: Text
sectionSeparator = Text
"* * *\n"
plainTextToMarkdown :: Text -> Text
plainTextToMarkdown :: Text -> Text
plainTextToMarkdown = [Text] -> Text
T.unlines ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" ") ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.lines
instance Semigroup MarkupContent where
MarkupContent MarkupKind
MkPlainText Text
s1 <> :: MarkupContent -> MarkupContent -> MarkupContent
<> MarkupContent MarkupKind
MkPlainText Text
s2 = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkPlainText (Text
s1 Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text
s2)
MarkupContent MarkupKind
MkMarkdown Text
s1 <> MarkupContent MarkupKind
MkMarkdown Text
s2 = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkMarkdown (Text
s1 Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text
s2)
MarkupContent MarkupKind
MkPlainText Text
s1 <> MarkupContent MarkupKind
MkMarkdown Text
s2 = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkMarkdown (Text -> Text
plainTextToMarkdown Text
s1 Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text
s2)
MarkupContent MarkupKind
MkMarkdown Text
s1 <> MarkupContent MarkupKind
MkPlainText Text
s2 = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkMarkdown (Text
s1 Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text -> Text
plainTextToMarkdown Text
s2)
instance Monoid MarkupContent where
mempty :: MarkupContent
mempty = MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkPlainText Text
""
data MarkdownClientCapabilities =
MarkdownClientCapabilities
{ MarkdownClientCapabilities -> Text
_parser :: Text
, MarkdownClientCapabilities -> Maybe Text
_version :: Maybe Text
} deriving (Int -> MarkdownClientCapabilities -> ShowS
[MarkdownClientCapabilities] -> ShowS
MarkdownClientCapabilities -> String
(Int -> MarkdownClientCapabilities -> ShowS)
-> (MarkdownClientCapabilities -> String)
-> ([MarkdownClientCapabilities] -> ShowS)
-> Show MarkdownClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MarkdownClientCapabilities -> ShowS
showsPrec :: Int -> MarkdownClientCapabilities -> ShowS
$cshow :: MarkdownClientCapabilities -> String
show :: MarkdownClientCapabilities -> String
$cshowList :: [MarkdownClientCapabilities] -> ShowS
showList :: [MarkdownClientCapabilities] -> ShowS
Show, ReadPrec [MarkdownClientCapabilities]
ReadPrec MarkdownClientCapabilities
Int -> ReadS MarkdownClientCapabilities
ReadS [MarkdownClientCapabilities]
(Int -> ReadS MarkdownClientCapabilities)
-> ReadS [MarkdownClientCapabilities]
-> ReadPrec MarkdownClientCapabilities
-> ReadPrec [MarkdownClientCapabilities]
-> Read MarkdownClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS MarkdownClientCapabilities
readsPrec :: Int -> ReadS MarkdownClientCapabilities
$creadList :: ReadS [MarkdownClientCapabilities]
readList :: ReadS [MarkdownClientCapabilities]
$creadPrec :: ReadPrec MarkdownClientCapabilities
readPrec :: ReadPrec MarkdownClientCapabilities
$creadListPrec :: ReadPrec [MarkdownClientCapabilities]
readListPrec :: ReadPrec [MarkdownClientCapabilities]
Read, MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
(MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool)
-> (MarkdownClientCapabilities
-> MarkdownClientCapabilities -> Bool)
-> Eq MarkdownClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
== :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
$c/= :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
/= :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''MarkdownClientCapabilities