ligo/tools/lsp/squirrel/src/Comment.hs

39 lines
733 B
Haskell
Raw Normal View History

2020-06-01 18:17:33 +04:00
2020-06-04 17:40:38 +04:00
{- | Comments and utilities.
-}
module Comment
2020-06-01 22:02:16 +04:00
( HasComments(..)
, c
)
where
2020-06-01 18:17:33 +04:00
import qualified Data.Text as Text
2020-06-09 15:56:11 +04:00
import Data.Text (Text)
2020-06-01 18:17:33 +04:00
import Pretty
2020-06-09 15:56:11 +04:00
import Product
2020-06-01 18:17:33 +04:00
2020-06-01 22:02:16 +04:00
-- | Ability to contain comments.
2020-06-01 18:17:33 +04:00
class HasComments c where
getComments :: c -> [Text.Text]
2020-06-01 22:02:16 +04:00
-- | Wrap some @Doc@ with a comment.
2020-06-01 18:17:33 +04:00
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
2020-06-01 22:02:16 +04:00
-- | Narrator: /But there was none/.
2020-06-01 18:17:33 +04:00
instance HasComments () where
2020-06-09 15:56:11 +04:00
getComments () = []
2020-06-17 22:05:44 +04:00
instance (Contains [Text] xs) => HasComments (Product xs) where
getComments = getElem