Skip to content

Commit 7c419c5

Browse files
committed
Partition haddocks
1 parent d7a2c65 commit 7c419c5

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/Hint/Comment.hs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE ImportQualifiedPost #-}
2+
{-# LANGUAGE LambdaCase #-}
23

34
{-
45
<TEST>
@@ -35,18 +36,23 @@ directives = words $
3536

3637
data Comments = Comments
3738
{ commPragma :: ![LEpaComment]
39+
, commBlockHaddocks :: ![LEpaComment]
3840
, commBlocks :: ![LEpaComment]
3941
-- TODO: Process the different types of block comments; [" |",""].
4042
-- * Haddock comments
4143
-- * Simple comments
44+
, commRunHaddocks :: ![[LEpaComment]]
4245
, commRuns :: ![[LEpaComment]]
46+
, commLineHaddocks :: ![LEpaComment]
4347
, commLines :: ![LEpaComment]
4448
}
4549

4650
classifyComments :: [LEpaComment] -> Comments
47-
classifyComments xs = Comments pragmas blocks runs lines where
48-
(partition isCommentPragma -> (pragmas, blocks), singles) = partition isCommentMultiline xs
49-
(concat -> lines, runs) = partition ((== 1) . length) $ commentRuns singles
51+
classifyComments xs = Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines where
52+
(partition isCommentPragma -> (pragmas, partition isCommentHaddock -> (blockHaddocks, blocks)), singles) = partition isCommentMultiline xs
53+
(concat -> singles', rawRuns) = partition ((== 1) . length) $ commentRuns singles
54+
(runHaddocks, runs) = partition (\case x : _ -> isCommentHaddock x; _ -> False) rawRuns
55+
(lineHaddocks, lines) = partition isCommentHaddock singles'
5056

5157
commentRuns :: [LEpaComment] -> [[LEpaComment]]
5258
commentRuns comments =
@@ -114,11 +120,14 @@ commentHint _ m =
114120
-- c) single-line comments
115121
-- TODO: Remove (True, _) runs and then run the other checks on the rest.
116122
traceShow ("pragmas", commentText <$> pragmas) $
123+
traceShow ("blockHaddocks", commentText <$> blockHaddocks) $
117124
traceShow ("blocks", commentText <$> blocks) $
118-
traceShow ("runs", fmap commentText <$> rawRuns) $
125+
traceShow ("runHaddocks", fmap commentText <$> runHaddocks) $
126+
traceShow ("runs", fmap commentText <$> runs) $
127+
traceShow ("lineHaddocks", commentText <$> lineHaddocks) $
119128
traceShow ("lines", commentText <$> lines) $
120-
if any fst runs
121-
then concatMap snd runs
129+
if any fst runReplacements
130+
then concatMap snd runReplacements
122131
else concatMap (check singleLines someLines) comments
123132
where
124133
-- Comments need to be sorted by line number for detecting runs of single
@@ -130,9 +139,12 @@ commentHint _ m =
130139
singleLines = sort $ commentLine <$> filter isSingle comments
131140
someLines = sort $ commentLine <$> filter isSingleSome comments
132141

133-
Comments pragmas blocks rawRuns lines = classifyComments comments
142+
Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines = classifyComments comments
134143

135-
runs = dropBlankLinesHint <$> rawRuns
144+
runReplacements =
145+
(dropBlankLinesHint <$> runHaddocks)
146+
++
147+
(dropBlankLinesHint <$> runs)
136148

137149
-- | Does the commment start with "--"? Can be empty. Excludes haddock single
138150
-- line comments, "-- |" and "-- ^".

0 commit comments

Comments
 (0)