{-# 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]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MarkupKind]
$creadListPrec :: ReadPrec [MarkupKind]
readPrec :: ReadPrec MarkupKind
$creadPrec :: ReadPrec MarkupKind
readList :: ReadS [MarkupKind]
$creadList :: ReadS [MarkupKind]
readsPrec :: Int -> ReadS MarkupKind
$creadsPrec :: Int -> ReadS MarkupKind
Read, Int -> MarkupKind -> ShowS
[MarkupKind] -> ShowS
MarkupKind -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MarkupKind] -> ShowS
$cshowList :: [MarkupKind] -> ShowS
show :: MarkupKind -> String
$cshow :: MarkupKind -> String
showsPrec :: Int -> MarkupKind -> ShowS
$cshowsPrec :: Int -> MarkupKind -> ShowS
Show, MarkupKind -> MarkupKind -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MarkupKind -> MarkupKind -> Bool
$c/= :: MarkupKind -> MarkupKind -> Bool
== :: MarkupKind -> MarkupKind -> Bool
$c== :: 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") = forall (f :: * -> *) a. Applicative f => a -> f a
pure MarkupKind
MkPlainText
parseJSON (String Text
"markdown") = forall (f :: * -> *) a. Applicative f => a -> f a
pure MarkupKind
MkMarkdown
parseJSON Value
_ = 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]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MarkupContent]
$creadListPrec :: ReadPrec [MarkupContent]
readPrec :: ReadPrec MarkupContent
$creadPrec :: ReadPrec MarkupContent
readList :: ReadS [MarkupContent]
$creadList :: ReadS [MarkupContent]
readsPrec :: Int -> ReadS MarkupContent
$creadsPrec :: Int -> ReadS MarkupContent
Read, Int -> MarkupContent -> ShowS
[MarkupContent] -> ShowS
MarkupContent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MarkupContent] -> ShowS
$cshowList :: [MarkupContent] -> ShowS
show :: MarkupContent -> String
$cshow :: MarkupContent -> String
showsPrec :: Int -> MarkupContent -> ShowS
$cshowsPrec :: Int -> MarkupContent -> ShowS
Show, MarkupContent -> MarkupContent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MarkupContent -> MarkupContent -> Bool
$c/= :: MarkupContent -> MarkupContent -> Bool
== :: MarkupContent -> MarkupContent -> Bool
$c== :: 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```" forall a. Semigroup a => a -> a -> a
<> Text
lang forall a. Semigroup a => a -> a -> a
<> Text
"\n" forall a. Semigroup a => a -> a -> a
<> Text
quote 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Semigroup a => a -> a -> a
<> 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 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 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 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 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MarkdownClientCapabilities] -> ShowS
$cshowList :: [MarkdownClientCapabilities] -> ShowS
show :: MarkdownClientCapabilities -> String
$cshow :: MarkdownClientCapabilities -> String
showsPrec :: Int -> MarkdownClientCapabilities -> ShowS
$cshowsPrec :: Int -> MarkdownClientCapabilities -> ShowS
Show, ReadPrec [MarkdownClientCapabilities]
ReadPrec MarkdownClientCapabilities
Int -> ReadS MarkdownClientCapabilities
ReadS [MarkdownClientCapabilities]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MarkdownClientCapabilities]
$creadListPrec :: ReadPrec [MarkdownClientCapabilities]
readPrec :: ReadPrec MarkdownClientCapabilities
$creadPrec :: ReadPrec MarkdownClientCapabilities
readList :: ReadS [MarkdownClientCapabilities]
$creadList :: ReadS [MarkdownClientCapabilities]
readsPrec :: Int -> ReadS MarkdownClientCapabilities
$creadsPrec :: Int -> ReadS MarkdownClientCapabilities
Read, MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
$c/= :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
== :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
$c== :: MarkdownClientCapabilities -> MarkdownClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''MarkdownClientCapabilities