Minor comment updates and cleanup

ghc92
Lennart Spitzner 2023-04-20 21:19:00 +00:00
parent 56e7d6b5b9
commit 52e4658314
4 changed files with 61 additions and 24 deletions

View File

@ -260,7 +260,7 @@ layoutPatternBind funId binderDoc lmatch@(L _ match) = do
let t' = fixPatternBindIdentifier match t
docLit t'
_ -> pure Nothing
patDoc <- docHandleComms lmatch $ case (mIdDoc, patDocs) of
patDoc <- docHandleComms lmatch $ case (mIdDoc, patDocs) of -- TODO92 we use lmatch twice here!
(Just idDoc, p1 : p2 : pr) | isInfix -> if null pr
then docCols
ColPatternsFuncInfix
@ -360,8 +360,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
, docSeparator
, docForceSingleline $ return w
]
, -- docMoveToKWDP annKeyWhere AnnWhere False -- TODO92
docEnsureIndent whereIndent
, docEnsureIndent whereIndent
$ docLines
[ wrapBinds $ wrapWhere $ docLit $ Text.pack "where"
, docEnsureIndent whereIndent
@ -372,7 +371,6 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
Just (wrapWhere, ws) ->
fmap (pure . pure)
-- $ docMoveToKWDP annKeyWhere AnnWhere False -- TODO92
$ docEnsureIndent whereIndent
$ docLines
[ wrapBinds $ wrapWhere $ docLit $ Text.pack "where"
@ -420,8 +418,12 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
[(grhsEpAnn, guards, body)] -> do
let grhsHasComms = hasAnyCommentsBelow grhsEpAnn
let guardPart = docHandleComms grhsEpAnn $ singleLineGuardsDoc guards
-- func x | null x = x + a + 2 where a = 1
-- or
-- func x | null x = x + a + b where
-- a = 1
-- b = 2
forM_ wherePart $ \wherePart' ->
-- one-line solution
addAlternativeCond (not hasComments && not grhsHasComms) $ docCols
(ColBindingLine alignmentToken)
[ docSeq (patPartInline ++ [guardPart])
@ -431,7 +433,18 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
, wherePart'
]
]
-- one-line solution + where in next line(s)
-- any below have this pattern:
-- …
-- where a = 1
-- or
-- …
-- where
-- a = 1
-- b = 1
-- func x | null x = do
-- stmt x
addAlternativeCond (not $ maybe False startsWithComments grhsEpAnn)
$ docLines
$ [ docCols
@ -450,7 +463,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
]
++ wherePartMultiLine
-- two-line solution + where in next line(s)
-- func x | null x =
-- x + a + 2
addAlternative
$ docLines
$ [ docForceSingleline
@ -460,8 +474,10 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
$ return body
]
++ wherePartMultiLine
-- pattern and exactly one clause in single line, body as par;
-- where in following lines
-- func x | null x
-- = do
-- stmt x
-- log "abc"
addAlternative
$ docLines
$ [ docCols
@ -480,7 +496,10 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
-- , docAddBaseY BrIndentRegular $ return body
-- ]
++ wherePartMultiLine
-- pattern and exactly one clause in single line, body in new line.
-- func x | null x =
-- do
-- stmt1
-- stmt2 x
addAlternative
$ docLines
$ [ docSeq (patPartInline ++ [guardPart, return binderDoc])
@ -496,8 +515,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
case mPatDoc of
Just patDoc | multipleClauses, indentPolicy == IndentPolicyFree ->
-- multiple clauses added in-paragraph, each in a single line
-- example: foo | bar = baz
-- | lll = asd
-- func x | null x = baz
-- | otherwise = asd
addAlternative
$ docLines
$ [ docSeq
@ -524,7 +543,9 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
++ wherePartMultiLine
_ -> return ()
-- multiple clauses, each in a separate, single line
-- func x y
-- | null x, null y = a + b
-- | otherwise = a - b
addAlternative
$ docLines
$ [ docAddBaseY BrIndentRegular
@ -550,8 +571,12 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
]
++ wherePartMultiLine
-- multiple clauses, each with the guard(s) in a single line, body
-- as a paragraph
-- func x y
-- | null x, null y = do
-- stmt x
-- stmt y
-- | otherwise -> do
-- abort
addAlternativeCond (not hasComments)
$ docLines
$ [ docAddBaseY BrIndentRegular
@ -572,8 +597,13 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
]
++ wherePartMultiLine
-- multiple clauses, each with the guard(s) in a single line, body
-- in a new line as a paragraph
-- func x y
-- | null x, null y
-- = do
-- stmt x
-- stmt y
-- | otherwise
-- = abort
addAlternative
$ docLines
$ [ docAddBaseY BrIndentRegular
@ -593,7 +623,14 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
]
]
++ wherePartMultiLine
-- conservative approach: everything starts on the left.
-- func x y
-- | null x
-- , null y
-- = do
-- stmt x
-- stmt y
-- | otherwise
-- = abort
addAlternative
$ docLines
$ [ docAddBaseY BrIndentRegular

View File

@ -672,8 +672,7 @@ layoutExpr lexpr@(L _ expr) = do
IndentPolicyLeft -> docLines noHangingBinds
IndentPolicyMultiple -> docLines noHangingBinds
IndentPolicyFree -> docLines
[ -- TODO92 docNodeAnnKW lexpr (Just AnnLet) $
docSeq
[ docSeq
[ appSep $ letDoc
, wrapBinds $ docSetBaseAndIndent $ docLines $ pure <$> bindDocs
]
@ -683,8 +682,7 @@ layoutExpr lexpr@(L _ expr) = do
]
]
addAlternative $ docLines
[ -- TODO92 docNodeAnnKW lexpr (Just AnnLet) $
docAddBaseY BrIndentRegular $ docPar
[ docAddBaseY BrIndentRegular $ docPar
(letDoc)
(wrapBinds $ docSetBaseAndIndent $ docLines $ pure <$> bindDocs)
, docAddBaseY BrIndentRegular

View File

@ -96,7 +96,9 @@ gatherOpTreeT hasParen hasComms commWrap locOpen locClose opExprList = \case
commWrap
locOpen
locClose
((docLit $ printRdrNameWithAnns op1, callLayouter layout_type r1) : opExprList)
( (docLit $ printRdrNameWithAnns op1, callLayouter layout_type r1)
: opExprList
)
l1
(L _ (HsParTy epAnn inner)) -> do
let AnnParen _ spanOpen spanClose = anns epAnn

View File

@ -69,7 +69,7 @@ layoutStmt lstmt@(L _ stmt) = do
in wrapBinds $ f $ return bindDoc
]
, -- let
-- bind = expr
-- bind = expr
docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "let")
(wrapBinds $ docSetBaseAndIndent $ return bindDoc)