ligo/tools/lsp/squirrel/src/Comment.hs
2020-08-11 12:32:05 +04:00

39 lines
733 B
Haskell

{- | Comments and utilities.
-}
module Comment
( HasComments(..)
, c
)
where
import qualified Data.Text as Text
import Data.Text (Text)
import Pretty
import Product
-- | Ability to contain comments.
class HasComments c where
getComments :: c -> [Text.Text]
-- | Wrap some @Doc@ with a comment.
c :: HasComments i => i -> Doc -> Doc
c i d =
case getComments i of
[] -> d
cc -> block (map removeSlashN cc) $$ d
where
removeSlashN txt =
if "\n" `Text.isSuffixOf` txt
then Text.init txt
else txt
-- | Narrator: /But there was none/.
instance HasComments () where
getComments () = []
instance (Contains [Text] xs) => HasComments (Product xs) where
getComments = getElem