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

30 lines
563 B
Haskell
Raw Normal View History

2020-06-01 18:17:33 +04:00
2020-06-01 22:02:16 +04:00
module HasComments
( HasComments(..)
, c
)
where
2020-06-01 18:17:33 +04:00
import qualified Data.Text as Text
import Pretty
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
getComments () = []