Fix issue with indentation after block-comments

ghc92
Lennart Spitzner 2023-05-12 12:02:19 +00:00
parent 47bcdb045b
commit 860c8771ae
5 changed files with 53 additions and 13 deletions

View File

@ -145,7 +145,7 @@ doop =
#expected
doop =
some long invocation == loooooooooongman + (third nested expression) - 4
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
|| ill just invoke a function with these args
|| foo
&& dooasdoiaosdoi ** oaisdoioasido
@ -165,7 +165,7 @@ doop =
-- brittany { lconfig_fixityBasedAddAlignParens: True }
doop =
( ( some long invocation == loooooooooongman + (third nested expression) - 4
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
)
|| ill just invoke a function with these args
|| ( foo

View File

@ -57,9 +57,9 @@ test = Proxy @'[{- comment -} 'True ]
#test with-comment-4
test
:: Proxy '[{- comment -}
'True ]
'True ]
test = Proxy @'[{- comment -}
'True ]
'True ]
#test with-comment-5
test
@ -69,9 +69,9 @@ test = Proxy @'[{- comment -} True]
#test with-comment-6
test
:: Proxy '[{- comment -}
True]
True]
test = Proxy @'[{- comment -}
True]
True]
#test explicit-list-type non-promoted
type Foo = '[Bool, Bool, Bool]

View File

@ -985,3 +985,11 @@ instance BMGuwigoc POtfuggj where
#test bang-type
data LabeledBool = LabeledBool !Int !Bool
#test block-comment after let
func = do
let cipInuihz = Vuozczdm.yhEfun tuhiuRasohy
let {- CAZEB mecwbd "Caa ||" -}
doeeRbaviceQzymin a b = olivhuwqbaq
iqnz biwomeJhhujy _ _ | biwomeJhhujy < volpoqAsizmHdwpl = pure 0
pure True

View File

@ -275,21 +275,53 @@ layoutBriDocM = \case
layoutBriDocM bd
BDFlushCommentsPrior loc bd -> do
comms <- takeBefore loc
startCurY <- mGet <&> _lstate_curY
printComments comms
mModify (\s -> s + CommentCounter (length comms))
mModify $ \s -> s
{ _lstate_markerForDelta = Nothing
, _lstate_plannedSpace = case _lstate_markerForDelta s of
, _lstate_plannedSpace =
case _lstate_markerForDelta s of
Nothing -> _lstate_plannedSpace s
Just m ->
let p1 = (srcLocLine m, srcLocCol m)
p2 = (srcLocLine loc, srcLocCol loc)
-- traceShow (m, ExactPrint.pos2delta p1 p2) $ pure ()
in case ExactPrint.pos2delta p1 p2 of
SameLine{} -> _lstate_plannedSpace s
in -- trace ("_lstate_plannedSpace = " ++ show (_lstate_plannedSpace s)
-- ++ ", _lstate_markerForDelta = " ++ show (_lstate_markerForDelta s)
-- ++ ", _lstate_curY = " ++ show (_lstate_curY s)
-- ++ ", p1 = " ++ show p1
-- ++ ", p2 = " ++ show p2
-- ++ ", startCurY = " ++ show startCurY
-- -- ++ ", delta = " ++ show (ExactPrint.pos2delta p1 p2)
-- ) $
case ExactPrint.pos2delta p1 p2 of
SameLine iDelta -> case _lstate_plannedSpace s of
-- There is a delta after a marker. That should only happen
-- after a block-comment. And the marker-delta is SameLine,
-- so if layout doesn't force a newline we respect the marker
-- delta (i.e. respect whitespace immediately after a block
-- comment) or we just use the plan.
PlannedNone -> PlannedSameline iDelta
PlannedSameline i -> PlannedSameline (max (iDelta - 0) i)
p@PlannedNewline{} -> p
p@PlannedDelta{} -> p
DifferentLine n _ -> case _lstate_plannedSpace s of
PlannedNone -> PlannedNone
PlannedSameline i -> PlannedDelta n (_lstate_curY s + i)
-- Marker with DifferentLine delta means that we want to
-- reproduce the newlines that were present in the input.
-- These will be emptylines in cases where it makes sense to
-- reproduce them, e.g. between statements in a do-block.
PlannedNone -> PlannedDelta n startCurY
-- ^^^^^^^^^
--
-- after a block-comment, _lstate_curY
-- matches the end of the comment.
-- But to not break layout we need to
-- restore the original.
-- E.g. consider > let {-comm-}
-- > x = 13
--
-- vvvvvvvvvvvvvvv
PlannedSameline i -> PlannedDelta n (startCurY + i)
PlannedNewline{} -> PlannedNewline n
PlannedDelta _ i -> PlannedDelta n i
}

View File

@ -152,7 +152,7 @@ layoutWriteComment absolute isBlock dp commentLines s = do -- TODO92 we don't mo
mSet state
{ _lstate_plannedSpace = if isBlock
then case _lstate_plannedSpace state of
PlannedNone -> PlannedSameline 1
p@PlannedNone -> p
p@PlannedSameline{} -> p
PlannedNewline l ->
if l <= y then PlannedSameline 1 else PlannedNewline (l - y)